AnsweredAssumed Answered

MakeIndependent save to variable location

Question asked by Tim Vriens on Oct 4, 2019

Hello,

 

We've got an library assembly which we use for every new project. I want to make 4 parts independent and save them with a custom value + their default name to a custom location.

 

After this has been done a copy of the current assembly has to be saved to the same custom location.

 

So far i've made this with the help of examples:

 

 

------------

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swAssembly As SldWorks.AssemblyDoc
Dim fileName As String
Dim status As Boolean
Dim errors As Long
Dim warnings As Long

 

Sub main()
Set swApp = Application.SldWorks
fileName = "C:\MG-Products\SolidWorks\Design Library\MG-products\Wisseldelen\MG01 Wisseldeel.sldasm"
Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
Set swModelDocExt = swModel.Extension
Set swAssembly = swModel

'Select first part to make independent
status = swModelDocExt.SelectByID2("MG01 Wisseldeel Basisplaat-1@MG01 Wisseldeel", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

'Save on location with certain name
status = swAssembly.MakeIndependent("C:\" + [Variable location; selected in popup menu] + "\" + [Variable name; selected in popup menu] + ".sldprt")

'Repeat for 4 different parts, then save a copy of the assembly on the same location with the same custom property + document name


End Sub

 

-------------

 

Please note that in the current state it doesn't work as i've added comments to explain what i'm looking for to achieve. 

 

in fileName it locates one of the library items i wish to use. Then in the first status it locates the first out of 4 parts i wish to make independent. In the second status it saves the part to another name as well as updating the reference in the assembly.

 

Now the part which i'm stuck on is making a custom file name based on a value in a popup menu. I cannot get to the point where i can break up the part in brackets after MakeIndependent and add any kind of variable to it. 

 

Idealy i would get a popup asking where the files should be saved and what the added custom part of the filename should be.

 

Could someone help me to where i can make use of a variable name in the part after MakeIndependent? The popup part is something i can try to work out myself after that, or if someone feels generous and could provide the popup code to me aswell that'd be greatly appriciated!

 

Thank you in advance,

 

Tim

Outcomes