AnsweredAssumed Answered


Question asked by S. Harvey on Feb 21, 2019
Latest reply on Feb 23, 2019 by Deepak Gupta

I would like a macro to choose which drawing to reference and build a new drawing from based on a Custom Property.

I can see the finite number of drawings required to:

     -make every possible drawing without dangling dimensions

     -create more or less views

     -create special annotations

     -change the scale so views fit


My workflow is:

     1) Input Parameters into DriveWorks Xpress

     2) Produce the Model from DriveWorks Xpress (Generates the Custom Property "Drawing Code" from rules in DriveWorks)

     3) User Runs the Macro with the New Part open

               a) Code looks at the Custom Property "Drawing Code"

               b) Through If then Statements finds the correct Drawing associated with the code "Drawing Code"

               c) Copies that Drawing, changes references and saves to the current folder of the New Part


I don't have Solo or Pro and I understand there is more functionality but for now I'm locked into Xpress.



This is the Property lookup and currently works for step 3a.  I borrowed and tweaked this.  There is a condition to create a new custom property which I named Drawing #.  I would override this with the code to create the new drawing.


Option Explicit

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swCustProp As CustomPropertyManager

Dim ValOut As String

Dim ResolvedValOut As String

Dim wasResolved As Boolean

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

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

swCustProp.Get5 "DRAWING CODE", False, ValOut, ResolvedValOut, wasResolved

If ResolvedValOut = "T11R1" Then

    swCustProp.Add3 "DRAWING #", swCustomInfoText, "GET T11R1 DRAWING", 1

End If

If ResolvedValOut = "T11R0" Then

    swCustProp.Add3 "DRAWING #", swCustomInfoText, "GET T11R0 DRAWING", 1

End If

End Sub


I am currently hitting a snag with the SolidWorks help file " Replace Referenced Document Example".

I copied and pasted the code exactly.  I replace the file locations accordingly and make sure the assembly is not open as noted in preconditions.

It's producing an error at "Debug.Assert bRet" by highlighting it, no msg box

I know it's probably something dumb but I am trying.  I started with the exact code first then I'll switch it to a drawing instead of an assembly later


I'll then have to figure out the coding to make a copy and move but its a working progress


Thank You for any help.


Option Explicit

Const sReferencingDoc       As String = "C:\Users\Desktop\TESTASSEBMLY.sldasm"

Const sOldDoc               As String = "C:\Users\Desktop\TEST.sldprt"

Const sNewDoc               As String = "C:\Users\Desktop\TESTWITHHOLE.sldprt"

Sub main()

    Dim swApp               As SldWorks.SldWorks

    Dim bRet                As Boolean

      Set swApp = CreateObject("SldWorks.Application")

      bRet = swApp.ReplaceReferencedDocument(sReferencingDoc, sOldDoc, sNewDoc)

    Debug.Assert bRet

End Sub