Hello
I have a macro that replaces all the components of a model assembly with all the assemblies selected by the user via an Excel file, this allows us to build a machine composed of standard elements very quickly.
For one of these elements (a part), only one dimension will change depending on a few options selected by the user.
I could have made a solidworks part specific to each possibility but since this part will be specific to each machine, I preferred to make a generic model of this part then:
- Import it into my machine model assembly
- Open this generic part
- Edit this rating
- Save the part and its drawing under a new name (generic drawing already done)
- and close this part to return to the assembly in construction.
Of all the steps mentioned above, I can only import my generic part (name of the part TEST. SLDPRT), select it, open it and then select the dimension in question which bears the name "DIAM", for the rest of the steps I thought I would use the macro recording to change the value of the selected dimension, save the part under a new name (as well as its drawing by opening it before saving the part file), Unfortunately the recording does not record anything for these actions...
I copy/paste the code I have to select my part, open it and select the dimension whose value I want to change:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("TEST-1@ASSY TEST", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.OpenCompFile
' Open the part TEST.SLDPRT
Set Part = swApp.OpenDoc6("PATCH\TEST.SLDPRT", 1, 0, "", longstatus, longwarnings)
Set Part = swApp.ActiveDoc
' Select dimension "DIAM"
boolstatus = Part.Extension.SelectByID2("DIAM@Sketch1@TEST.SLDPRT", "DIMENSION", 0, 0, 0, True, 0, Nothing, 0)
End Sub
So my question is rather obvious, does anyone have an idea for:
- Change the value of a selected dimension
- Open the drawing of a selected part
- Save a part under a new name
- Save the drawing under a new name
- Close it all to go back to the assembly
I have already tried to search, to manipulate the selections but I must admit that I get very easily lost in the solidworks VBA compared to the Excel VBA and I therefore have difficulties to manipulate the selections etc...
Thank you in advance for your help
P.S: sorry for the lack of accents, I use an English keyboard ...
Yves