tag:blogger.com,1999:blog-3338128750432104713.post7740664839251327618..comments2023-10-13T01:02:22.552-07:00Comments on Joshua Redstone's Blog: Solidworks Macros via PythonJoshuahttp://www.blogger.com/profile/05824098668540667172noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-3338128750432104713.post-69511084107840338622022-08-10T21:42:19.650-07:002022-08-10T21:42:19.650-07:00Hi Joshua
Can you share few python programs which ...Hi Joshua<br />Can you share few python programs which you have worked on Solidworks. I've started learning and your programs would help me learn faster.<br />I'll be thankful to you. Afthabhttps://www.blogger.com/profile/09246434204331459402noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-34150641382055238232022-06-13T16:02:12.865-07:002022-06-13T16:02:12.865-07:00I have spent wayyy to much time solving this. Here...I have spent wayyy to much time solving this. Here is what I finaly got to work. <br /><br />import win32com.client<br />from win32com.client import VARIANT<br />from pythoncom import *<br /><br />swApp = win32com.client.Dispatch("SLDWORKS.Application")<br /><br />activedoc = swApp.ActiveDoc<br />configname = activedoc.GetActiveConfiguration.name # '' is default<br />PropNames = VARIANT(VT_BYREF | VT_VARIANT, '');<br />PropTypes = VARIANT(VT_BYREF | VT_VARIANT, '');<br />PropValues = VARIANT(VT_BYREF | VT_VARIANT, '');<br /><br /># note this modifies the above variables, not return them like you would expect.<br />bool_out = = activedoc.Extension.CustomPropertyManager(configname).GetAll(PropNames,PropTypes,PropValues);<br /><br />names = PropNames.value # python tuple<br />types = PropTypes.value<br />values = PropValues.value<br /><br /># also, here is how you get mass properties<br />mp = swApp.GetMassProperties2(str(paths[0]), "Default", int(3))<br />volume = mp[3] # m^3<br />surface_area = mp[4] # m^2<br />mass = mp[5] # kg<br /><br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-72506997768585392572022-02-14T15:11:59.568-08:002022-02-14T15:11:59.568-08:00Good question. I don't know offhand. One sugge...Good question. I don't know offhand. One suggestion is to run python from the command line and try invoking the RunMacro varoius ways manually and see if you can get it to work.Joshuahttps://www.blogger.com/profile/05824098668540667172noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-75882961580618616602022-02-14T12:31:32.382-08:002022-02-14T12:31:32.382-08:00Thank you for this awsome blog! I was wondering if...Thank you for this awsome blog! I was wondering if you could help clarify one more thing: Let's say we write a Macro directly on Solidworks, (In my case, a Macro that rebuilds the shape after I change coordinates of control points), do you know of a way to run the macro from Python? I got an answer about 'sw.bindings.RunMacro' though I do not find any documentations regarding that. Thank you already!Anonymoushttps://www.blogger.com/profile/12834856979269251670noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-19357891383887920752021-09-24T06:15:47.653-07:002021-09-24T06:15:47.653-07:00Just wanted to let you know that his has been a Go...Just wanted to let you know that his has been a Godsend in my first try in writing python scripts to automate SolidWorks.<br /><br />Thanks!Anonymoushttps://www.blogger.com/profile/17161045479207953942noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-79307202998563248182021-02-08T23:13:37.379-08:002021-02-08T23:13:37.379-08:00Is there a way to extract number of mates used in ...Is there a way to extract number of mates used in an assembly?Help My Experiment (Akbar)https://www.blogger.com/profile/14313854278986936498noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-40314345109623615182020-09-25T02:21:03.779-07:002020-09-25T02:21:03.779-07:00Are there any video tutorials out there on this? W...Are there any video tutorials out there on this? Would help us noobs learn a bit faster lol<br />Anonymoushttps://www.blogger.com/profile/12897357005800134725noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-50631510377207373202020-04-17T13:48:42.806-07:002020-04-17T13:48:42.806-07:00With Solidworks 2019 API, I am trying to use the c...With Solidworks 2019 API, I am trying to use the cusPropMgr.GetAll3 from the ICustomPropertyManager class. Here is the code I run:<br /><br />PropNames = VARIANT(16396,"")<br />PropTypes = VARIANT(16396,"")<br />PropValues = VARIANT(16396, "")<br />PropLink = VARIANT(16396, "")<br />Resolved = VARIANT(16396, "")<br />Prop = cusPropMgr.GetAll3(PropNames,PropTypes,PropValues,Resolved,PropLink)<br /><br />Analyzing the Data the function send me, the "PropNames" are the "PropLink" and the "PropTypes" are the "Resolved" and vice versa. Is this a Solidworks bug? Have you seen that before? Any fix?Anonymoushttps://www.blogger.com/profile/16015465066605894368noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-34078438448673963522019-12-16T10:05:52.497-08:002019-12-16T10:05:52.497-08:00Nope, I just worked around it.Nope, I just worked around it.Joshuahttps://www.blogger.com/profile/05824098668540667172noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-56579317417897184762019-12-15T02:49:18.510-08:002019-12-15T02:49:18.510-08:00Hi Joshua,
I just stumbled across your nice artic...Hi Joshua, <br />I just stumbled across your nice article above. I have similar issues with MathUtils.<br /><br />Did you get in any way closer to a solution ?<br />Cheers FrankAnonymoushttps://www.blogger.com/profile/17911680935844637211noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-78157499235481025702015-10-06T21:10:40.689-07:002015-10-06T21:10:40.689-07:00Hi Josh,
My Name is Arvind, I have a small clarif...Hi Josh,<br /><br />My Name is Arvind, I have a small clarification. I wrote a code in vba for dissolving component pattern but it is not getting executed at all and I could not figure out why.<br /><br />here is my code:<br /><br /> <br /> <br />Sub main()<br />Dim swApp As SldWorks.SldWorks<br />Dim swModel As SldWorks.ModelDoc2<br />Dim swfeat As SldWorks.Feature<br />Dim swComp As SldWorks.Component2<br />Dim swRootComp As SldWorks.Component2<br />Dim swConfMgr As SldWorks.ConfigurationManager<br />Dim swConf As SldWorks.Configuration<br />Dim partname As SldWorks.Component2<br />Dim swAssy As SldWorks.AssemblyDoc<br />Dim swModelDoc As SldWorks.ModelDoc2<br /> <br /> <br /> Set swApp = Application.SldWorks<br /> Set swModel = swApp.ActiveDoc<br /> Set swAssy = swModel<br /> Set swfeat = swModel.FirstFeature<br /> Set swConfMgr = swModel.ConfigurationManager<br /> Set swConf = swConfMgr.ActiveConfiguration<br /> Set swRootComp = swConf.GetRootComponent3(True)<br /> While Not swfeat Is Nothing<br /> If swfeat.GetTypeName2 = "Reference" Then<br /> Set swComp = swfeat.GetSpecificFeature2<br /> If UCase(Right(swComp.GetPathName, 3)) = "ASM" Then<br /> MsgBox "Assembly:" & swComp.Name2<br /> ElseIf UCase(Right(swComp.GetPathName, 3)) = "PRT" Then<br /> MsgBox "Part :" & swComp.Name2<br /> End If<br /> End If<br /> If swfeat.GetTypeName2 = "ReferencePattern" Then<br /> swfeat.Select (False)<br /> swModel.DissolveComponentPattern <br /> End If<br /> Set swfeat = swfeat.GetNextFeature<br /> <br /> Wend<br />End Sub<br /> <br />Kindly help me out.Anonymoushttps://www.blogger.com/profile/04647592949296369686noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-41560812181671376492015-08-02T07:14:44.147-07:002015-08-02T07:14:44.147-07:00woww... great job and nice idea.woww... great job and nice idea.Solidworkshttp://www.applicadindonesia.com/noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-64966090499131731612015-05-11T11:19:16.973-07:002015-05-11T11:19:16.973-07:00I'm not sure what would cause it. Are you usi...I'm not sure what would cause it. Are you using the same kind/version of python as listed in the post? Do you get the same error when trying the other variant arg examples?Joshuahttps://www.blogger.com/profile/05824098668540667172noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-9928212716124751542015-05-09T19:36:59.743-07:002015-05-09T19:36:59.743-07:00I'm trying to follow along to your post, and a...I'm trying to follow along to your post, and after this line:<br /><br />modelExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, arg1, 0), <br /><br />I get the following error:<br /><br />TypeError: Objects of type 'VARIANT' can not be converted to a COM VARIANT (but obtaining the buffer() of this object could) <br /><br />Any idea?<br /><br />Great post btw!<br /><br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-14378218976984536202015-04-19T06:21:48.236-07:002015-04-19T06:21:48.236-07:00Woops, I mean 0x2000 + 0x5 = 0x2005 = 8197Woops, I mean 0x2000 + 0x5 = 0x2005 = 8197Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-47876872308948001652015-04-19T06:10:24.177-07:002015-04-19T06:10:24.177-07:00In the 2012 version of Solidworks helpfile, Create...In the 2012 version of Solidworks helpfile, CreatePoint appears to require a variant array of coordinates. I assume this is a SafeArray of 3 doubles, 8197.<br />I have yet to get this to work by directly editing the proxy stub file.<br />I'm working on a Solidworks API problem at present (swModeler.CreateBodyFromBox()) and have used similar techniques to transfer SafeArrays of Dispatch pointers and doubles, swModel.RayIntersections().<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-75690668708990074242015-04-18T11:00:19.927-07:002015-04-18T11:00:19.927-07:00Adding parenthesis only makes it fail earlier:
---...Adding parenthesis only makes it fail earlier:<br />-------------------<br />Traceback (most recent call last):<br /> File "solidworksApp.py", line 91, in <br /> mathUtil = sw.GetMathUtility()<br /> File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 192, in __call__<br /> return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)<br />pywintypes.com_error: (-2147352573, 'Member not found.', None, None)<br />Joshuahttps://www.blogger.com/profile/05824098668540667172noreply@blogger.comtag:blogger.com,1999:blog-3338128750432104713.post-2580540393499089162015-04-17T11:37:57.941-07:002015-04-17T11:37:57.941-07:00mathUtil = sw.GetMathUtility()mathUtil = sw.GetMathUtility()Anonymousnoreply@blogger.com