I test below code snippets in vscode with enviroment of python 3.8, pywin32
build 228, solidworks 2017 API sets and created .py files by makepy, I get some
strange errors.
first snippet
# -*- coding: utf-8 -*-
from win32com.client import *
from pythoncom import *
swx = Dispatch("SldWorks.Application")
swModel = swx.ActiveDoc
mathUilty = swx.GetMathUtility
compName = []
Trans = [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
CoordName = []
compName.append(r'C:\Users\admin\Desktop\abc.SLDASM')
CoordName.append('')
vtName = VARIANT(VT_VARIANT, compName)
vtTrans = VARIANT(VT_VARIANT, Trans)
vtCoordName = VARIANT(VT_VARIANT, CoordName)
swModel.AddComponents3(vtName,vtTrans,vtCoordName)
Running this code and vscode says:
line 15, in <module>
swModel.AddComponents3(vtName,vtTrans,vtCoordName)
TypeError: 'NoneType' object is not callable
If I code it like this 'swModel.AddComponents3' then it's ok. the function
definition is:
System.object AddComponents3(
System.object Names,
System.object Transforms,
System.object CoordinateSystemNames
)
second snippet
# -*- coding: utf-8 -*-
from win32com.client import *
from pythoncom import *
swx = Dispatch("SldWorks.Application")
swModel = swx.ActiveDoc
mathUilty = swx.GetMathUtility
vtPoint = VARIANT(VT_VARIANT, [100.0,0.0,0.0])
vtVec = VARIANT(VT_VARIANT, [0.0,0.0,1.0])
point = mathUilty.CreatePoint(vtPoint)
axis = mathUilty.CreateVector(vtVec)
trans = mathUilty.CreateTransformRotateAxis(point,axis,3.14*30.0/180.0)
print(trans)
Running this code and vscode says:
line 9, in __call__
return
self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
the function 'CreatePoint' and 'CreateVector' is not the member of mathuilty,
the functions definition are:
System.object CreatePoint(
System.object ArrayDataIn
)
System.object CreateVector(
System.object ArrayDataIn
)
Could somebody can kindly find out what happened for these issues? thanks very
much!
And you can find the redist of solidworks inhttp://u.163.com/nnnnnnFnC. access
code: fomwl84g
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32