在SW中新建一个零件文档,建立一个立方体,长度和宽度自定义,高度100mm,下面通过python实现读取该立方体的高度:
import win32com.client as win32
import pythoncom
swApp = win32.Dispatch('sldworks.application')
swApp.Visible = True
Nothing = win32.VARIANT(pythoncom.VT_DISPATCH, None)
swModel = swApp.ActiveDoc
swDim = swModel.Parameter("D1@凸台-拉伸1")
print(swModel.GetPathName)
print(swDim.FullName)
print(swDim.Name)
vConfigNames = swModel.GetConfigurationNames
vValue = swDim.GetSystemValue3(1, (vConfigNames))
print(vValue(0) * 1000)
代码报错,如下:
Traceback (most recent call last):
File "D:\pycharm pjt\main.py", line 14, in <module>
print(vValue(0) * 1000)
TypeError: 'tuple' object is not callable
修正后如下所示:
import win32com.client as win32
import pythoncom
swApp = win32.Dispatch('sldworks.application')
swApp.Visible = True
Nothing = win32.VARIANT(pythoncom.VT_DISPATCH, None)
swModel = swApp.ActiveDoc
swDim = swModel.Parameter("D1@凸台-拉伸1")
print(swModel.GetPathName)
print(swDim.FullName)
print(swDim.Name)
vConfigNames = swModel.GetConfigurationNames
vValue = swDim.GetSystemValue3(1, (vConfigNames))
print(f"{vValue[0] * 1000} mm")
D1@凸台-拉伸1@零件1.Part
D1
100.0 mm