[python-win32] Run solidworks macro from python.

Moritz Mühlbauer moritz_muehlbauer at web.de
Thu Feb 10 04:50:59 EST 2022


Hello Sanaa,

I used makepy.py to generate swcommands.py, swbindings.py, swconst.py
and cosworks.py and placed them in the same directory as the python file
I ran (at least I think it worked that way).

Then,

import swbindings, swcommands, swconst, cosworks
import win32com.client
import pythoncom
sw=swbindings.SldWorks()
arg1 = win32com.client.VARIANT(pythoncom.VT_DISPATCH, None)
mdsl=sw.NewDocument(r'C:\ProgramData\SolidWorks\SOLIDWORKS
2018\templates\MBD\part 0251mm to 1000mm.prtdot',6,1,1)
model = sw.ActiveDoc
modelExt = model.Extension
selMgr = model.SelectionManager
featureMgr = model.FeatureManager
sketchMgr = model.SketchManager
sketchMgr.InsertSketch(True)

etc. worked fine. It should work similarly with your code.

Inspecting swbindings.py, I found a RunMacro function, which might be
what you need.

Are there any error messages?

An other way would be to run the macro from excel using xlwings, if it
is a excel macro.

Best regards

Moritz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20220210/a2202d92/attachment-0001.html>


More information about the python-win32 mailing list