Macro to output a separate drawing for all part configurations

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.

'------------------------------------------------------------------------------------<br>'Created by Artem Taturevych (Intercad, Australia)<br>'http://intercad.com.au/<br>'------------------------------------------------------------------------------------<br>'Disclaimer: The API examples are provided as is and should be used as reference only.<br>'You may redistribute it and/or modify it on the condition that this header is retained.<br>'In no event shall Intercad be liable for any types of damages whatsoever<br>'(including without limitation, damages from the loss of use, data, profits, or business)<br>'arising out of the uses of this information, applications, or services.<br>'------------------------------------------------------------------------------------<br><br>Const OUTPUT_FOLDER = "C:\\Out\\"<br><br>Dim swApp As SldWorks.SldWorks<br>Dim swModel As SldWorks.ModelDoc2<br>Dim swCustPropMgr As SldWorks.CustomPropertyManager<br>Dim Piirustusnumero As String<br>Dim swDraw As SldWorks.DrawingDoc<br><br>Sub main()<br><br> Set swApp = Application.SldWorks<br><br> Set swModel = swApp.ActiveDoc<br><br> Set swDraw = swModel<br><br> Dim i As Integer<br><br> Dim vConfs As Variant<br><br> Dim swView As SldWorks.View<br><br> Set swView = swDraw.GetFirstView().GetNextView<br> Dim swRefModel As SldWorks.ModelDoc2<br> Set swRefModel = swView.ReferencedDocument<br><br> vConfs = swRefModel.GetConfigurationNames<br><br> For i = 0 To UBound(vConfs)<br><br> Dim confName As String<br> confName = vConfs(i)<br> GetDwgNo confName<br> Set swModel = swApp.ActiveDoc<br> ProcessViews confName<br> swModel.ForceRebuild3 False<br> swModel.Extension.SaveAs OUTPUT_FOLDER + DwgNo + " - " + confName + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Copy, Nothing, 0, 0<br><br> Next<br><br> MsgBox "Completed"<br><br>End Sub<br><br>Sub ProcessViews(confName As String)<br><br> Dim i As Integer<br><br> Dim vSheets As Variant<br> vSheets = swDraw.GetViews<br><br> For i = 0 To UBound(vSheets)<br><br> Dim j As Integer<br> Dim vViews As Variant<br><br> vViews = vSheets(i)<br><br> For j = 0 To UBound(vViews)<br> Dim swView As SldWorks.View<br> Set swView = vViews(j)<br> swView.ReferencedConfiguration = confName<br> Next<br><br> Next<br><br>End Sub<br><br>Sub GetDwgNo(confName As String)<br><br>Set swApp = Application.SldWorks<br>Set swModel = swApp.ActiveDoc<br><br>Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")<br><br>Dim valOut As String<br>Dim evalValOut As String<br>swCustPropMgr.Get3 "DwgNo", False, valOut, evalValOut<br>DwgNo = evalValOut<br><br>End Sub<br><br>
SolidworksApi/macros