AnsweredAssumed Answered

Rename part with Configuration Specific Tab where configuration is not allways default

Question asked by Jernej Globočnik on Jan 29, 2017
Latest reply on Jan 30, 2017 by Jernej Globočnik

Hello all.

I´m a new on this forum and 1 year user of SW2016.

 

I have, I think, quite easy problem, for you here and that is:

I would like a macro that will rename a part into a new name where new name consist a value of  Properties in the CUSTOM tab and a value from Configuration Specific Tab where configuration is not allways default, so I need to read a name of active configuration and use it, but I don´t know how.

 

I was able to get so far but it dosn´t work and I don´t know whay:

 

 

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swConfig As SldWorks.Configuration

Dim swComp As SldWorks.Component2

Dim swCompConfig As String

Dim configName As String

Dim partnumber As String

Dim imekosa As String

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

 

Set swConfig = swModel.GetActiveConfiguration

 

'Get configuration name

Set swCompConfig = swModel.ReferencedConfiguration

 

'Use this....To Get the value from the Properties in the CUSTOM tab

partnumber = swModel.GetCustomInfoValue(swCompConfig, "NumberNomenc")

imekosa = swModel.CustomInfo("FileNoProj")

'Or this....To Get the value from the Configuration Specific Tab

'partnumber = SWmoddoc.GetCustomInfoValue("Default", "Number")

PathName = swModel.GetPathName     'this gets the full path of the current open document (including filename)

FilePath = Left(PathName, InStrRev(PathName, "\"))  'uses to full pathname to get the folder path, to be added to the save as file name

If (swModel.GetType = swDocASSEMBLY) Then

    swModel.SaveAs (FilePath + partnumber + ".sldasm")

  

ElseIf (swModel.GetType = swDocPART) Then

     swModel.SaveAs (FilePath + partnumber + "_" + imekosa + ".sldprt")

End If

End Sub

 

 

 

I started from this macro wich I allready modified and it works, but only if active configuration is default.

 

Sub main()

Dim swApp As SldWorks.SldWorks

Dim SWmoddoc As SldWorks.ModelDoc2

Dim partnumber As String

Dim imekosa As String

Set swApp = Application.SldWorks

Set SWmoddoc = swApp.ActiveDoc

'Use this....To Get the value from the Properties in the CUSTOM tab

partnumber = SWmoddoc.GetCustomInfoValue("Default", "NumberNomenc")

imekosa = SWmoddoc.CustomInfo("FileNoProj")

'Or this....To Get the value from the Configuration Specific Tab

'partnumber = SWmoddoc.GetCustomInfoValue("Default", "Number")

PathName = SWmoddoc.GetPathName     'this gets the full path of the current open document (including filename)

FilePath = Left(PathName, InStrRev(PathName, "\"))  'uses to full pathname to get the folder path, to be added to the save as file name

If (SWmoddoc.GetType = swDocASSEMBLY) Then

    SWmoddoc.SaveAs (FilePath + partnumber + ".sldasm")

  

ElseIf (SWmoddoc.GetType = swDocPART) Then

     SWmoddoc.SaveAs (FilePath + partnumber + "_" + imekosa + ".sldprt")

End If

End Sub

 

Please help,

Jernej

Outcomes