AnsweredAssumed Answered

Macro Won't update properties from current configuration for saving .pdf. How do I get the file name to match the correct properties?

Question asked by Ben Bilbrough on Dec 17, 2018
Latest reply on Dec 17, 2018 by Deepak Gupta

I have a macro to save an .x_t and a STEP file and it works with a part with multiple configurations. I have a similar macro to save a .pdf, but it doesn't always work with configurations. It works initially, but if I change the configuration of the drawing views, the custom properties that are pulled are not always for the current configuration.

 

This is my current macro for the .pdf It has a little debugging

 

' ******************************************************************************

' C:\Users\bilbroughb.TRESKE\AppData\Local\Temp\swx12456\Macro1.swb - macro recorded on 09/19/18 by bilbroughb

' ******************************************************************************

Option Explicit

 

 

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

 

 

 

 

Dim sRevision As String

Dim sPartNo As String

 

 

 

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim swView As SldWorks.View

Dim swCustProp As CustomPropertyManager

Dim swSelMgr As SldWorks.SelectionMgr

Dim Config As SldWorks.Configuration

Dim cfg As String

 

 

 

 

 

 

Sub main()

 

 

Set swApp = Application.SldWorks

Set swDraw = swApp.ActiveDoc

'Set swSelMgr = swModel.SelectionManager

 

 

Set swView = swDraw.GetFirstView

Set swView = swView.GetNextView

Set swModel = swView.ReferencedDocument

Set swCustProp = swModel.Extension.CustomPropertyManager(swView.ReferencedConfiguration)

Set Config = swModel.GetActiveConfiguration

cfg = swModel.GetActiveConfiguration.Name

 

 

 

 

Dim testdefault As String

Dim testcfg As String

 

 

Set swDraw = swApp.ActiveDoc

 

 

 

 

If cfg = "default" Then

sRevision = swModel.CustomInfo("Revision")

sPartNo = swModel.CustomInfo("Partno")

testdefault = 1

End If

 

 

 

 

If cfg <> "default" Then

sRevision = swModel.GetCustomInfoValue(cfg, "Revision")

sPartNo = swModel.GetCustomInfoValue(cfg, "PartNo")

testcfg = 1

End If

 

 

'Set swDraw = swApp.ActiveDoc

 

 

Set Part = swApp.ActiveDoc

 

 

Debug.Print "cfg" + ":" + " " + cfg

Debug.Print "sPartNo" + ":" + " " + sPartNo

Debug.Print "sRevision" + ":" + " " + sRevision

Debug.Print "testdefault" + ":" + " " + testdefault

Debug.Print "testcfg" + ":" + " " + testcfg

 

 

 

 

 

 

' Save As

longstatus = Part.SaveAs3("C:\Users\bilbroughb.TRESKE\Desktop\A working Folder\" + sPartNo + "_" + sRevision + ".PDF", 0, 0)

 

 

 

 

End Sub

 

 

Here is the macro that works for the .x_t and Parasolid

 

' ******************************************************************************

' C:\Users\bilbroughb.TRESKE\AppData\Local\Temp\swx12456\Macro1.swb - macro recorded on 09/19/18 by bilbroughb

' ******************************************************************************

Option Explicit

Sub main()

 

 

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swCompModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swComp As SldWorks.Component2

Dim value As String

Dim sRevision As String

Dim sPartNo As String

Dim Config As SldWorks.Configuration

Dim cfg As String

Dim swCustProp As CustomPropertyManager

Dim Test As String

 

 

 

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

 

 

 

 

Set Config = swModel.GetActiveConfiguration

cfg = swModel.GetActiveConfiguration.Name

 

 

If cfg <> "Default" Then

sRevision = swModel.GetCustomInfoValue(cfg, "Revision")

sPartNo = swModel.GetCustomInfoValue(cfg, "PartNo")

End If

 

 

 

 

If cfg = "Default" Then

sRevision = swModel.CustomInfo("Revision")

sPartNo = swModel.CustomInfo("Partno")

End If

 

 

 

 

 

 

Debug.Print "sPartNo" + ":" + " " + sPartNo

Debug.Print "sRevision" + ":" + " " + sRevision

Debug.Print "cfg" + ":" + " " + cfg

Debug.Print "Test" + ":" + " " + Test

 

 

 

 

 

 

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

 

 

' Save As

longstatus = Part.SaveAs3("N:\CAD_Transfer\" + sPartNo + "_" + sRevision + ".x_t", 0, 0)

longstatus = Part.SaveAs3("N:\CAD_Transfer\" + sPartNo + "_" + sRevision + ".step", 0, 0)

End Sub

Outcomes