ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MLMikko Laine05/03/2020

Hello,

we have few models that need separate drawings for all the different model configurations. For just few of them it's not a problem but few models have over 150 different configurations and generating them all by hand is waste of resources...

I found this macro   that will go trough the given drawing and save a new drawing with the given configuration active. This works quite nicely. Problem is the output filename, if the part and first drawing names are "1234-001 - Test piece.sldprt" and "1234-001 - Test piece.slddrw" it will output the new drawing as "1234-001 - Test piece - Sheet1 - Configuration name.slddrw".

I've tried to modify that macro as follows to get the drawing numbers. This works nice if the DwgNo property is already in the drawing properties but how to get it read the DwgNo from the Configuration Specific properties of the part? The drawing template calls DwgNo as $PRPSHEET from the part and it updates correctly.

'------------------------------------------------------------------------------------
'Created by Artem Taturevych (Intercad, Australia)
'http://intercad.com.au/
'------------------------------------------------------------------------------------
'Disclaimer: The API examples are provided as is and should be used as reference only.
'You may redistribute it and/or modify it on the condition that this header is retained.
'In no event shall Intercad be liable for any types of damages whatsoever
'(including without limitation, damages from the loss of use, data, profits, or business)
'arising out of the uses of this information, applications, or services.
'------------------------------------------------------------------------------------

Const OUTPUT_FOLDER = "C:\Out\"

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim Piirustusnumero As String
Dim swDraw As SldWorks.DrawingDoc

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swDraw = swModel

Dim i As Integer

Dim vConfs As Variant

Dim swView As SldWorks.View

Set swView = swDraw.GetFirstView().GetNextView
Dim swRefModel As SldWorks.ModelDoc2
Set swRefModel = swView.ReferencedDocument

vConfs = swRefModel.GetConfigurationNames

For i = 0 To UBound(vConfs)

Dim confName As String
confName = vConfs(i)
GetDwgNo confName
Set swModel = swApp.ActiveDoc
ProcessViews confName
swModel.ForceRebuild3 False
swModel.Extension.SaveAs OUTPUT_FOLDER + DwgNo + " - " + confName + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Copy, Nothing, 0, 0

Next

MsgBox "Completed"

End Sub

Sub ProcessViews(confName As String)

Dim i As Integer

Dim vSheets As Variant
vSheets = swDraw.GetViews

For i = 0 To UBound(vSheets)

Dim j As Integer
Dim vViews As Variant

vViews = vSheets(i)

For j = 0 To UBound(vViews)
Dim swView As SldWorks.View
Set swView = vViews(j)
swView.ReferencedConfiguration = confName
Next

Next

End Sub

Sub GetDwgNo(confName As String)

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")

Dim valOut As String
Dim evalValOut As String
swCustPropMgr.Get3 "DwgNo", False, valOut, evalValOut
DwgNo = evalValOut

End Sub