|
各位大大好
小弟我最近在研究如何利用EXCEL或是TXT檔案,事先輸入座標與矩形的長寬, 導入solidworks畫成2D草圖
礙於小弟的程式能力不太好, 只能求助OpenAi與各位大大
以下是AI提供的Python語言
===============================================================
import win32com.client as win32
# 設置SolidWorks程序的啟動參數
swApp = win32.Dispatch('SldWorks.Application')
swApp.Visible = True
swApp.UserControl = True
# 創建新文件
swModel = swApp.NewDocument('Part', 0, 0, 0)
# 創建草圖
swModel.Extension.SelectByID2('', 'PLANEXY', 0, 0, 0, False, 0, None, 0)
swModel.SketchManager.InsertSketch(True)
# 讀取TXT文件中的數據
with open('data.txt', 'r') as f:
data = f.readlines()
# 創建矩形
for line in data:
x, y, w, h = line.strip().split(',')
swModel.SketchManager.CreateCenterRectangle(float(x), float(y), 0, float(w) / 2, float(h) / 2, 0)
# 完成草圖
swModel.ClearSelection2(True)
swModel.SketchManager.InsertSketch(True)
# 保存文件為SWP檔案
swModel.SaveAs3('drawing.swp', 0, True, True)
================================================================
另外AI有提醒請確保已經安裝了SolidWorks和Python環境,以及SolidWorks API的Python庫
我想請問SolidWorks API的Python庫是要另外購買的嗎?
有沒有其他方法可以完成匯入矩形草圖,爬文只有找到輸入XYZ點的三維座標,但SWP檔似乎也有Bug
先謝過各位大大
|
|