Re: [python-win32] Run solidworks macro from python.
On Feb 10, 2022, at 9:39 AM, Sanaa Mouzahir wrote: > > Or maybe After importing the packages I can just use the same command as the > VBA? I know that for excel the function Application.run(macroname) works, but > not for solidworks.. Right, because every application defines their own object model. There’s no “general rule” that applies to all COM servers. You HAVE to go through the documentation for THAT product, or at least look at some examples. — Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Run solidworks macro from python.
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 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Run solidworks macro from python.
Sanaa Mouzahir wrote: Hello. I have started a project in which I have to link both solidworks and python. I want to use Pywin32 to run a macro from python. here is my code: app=win32com.client.Dispatch("SldWorks.Application") app.OpenDoc("C:/Users/sm5126/Downloads/Python/Python/Part1.SLDPRT", 1) app.Run("C:/Users/sm5126/Downloads/Python/Python/Part1.SLDPRT!ForceRebuild.swp") I basically want to use the same run function as for excel. But it does not work. Is there a way to run a macro from python using Pywin32? What do you mean by "it does not work"? Do you get an error? Does it crash? Have you read the documentation for the SolidWorks API? As I read the documentation, the API for running a script is called RunScript, not Run. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. smime.p7s Description: S/MIME Cryptographic Signature ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32