2 Replies Latest reply on Sep 19, 2018 3:38 PM by Nick Sinno

    Cannot set custom property in drawing file

    Nick Sinno

      Been working on a custom renaming/copying/moving macro, and want to add the date modified. We store our dates in the actual drawing files custom properties, and I take just a text input for the date (user entered). Im running into an issue where I cannot add a custom property to my drawing file, no matter the name. I also cannot use the "Set2" property to change the value of an existing property. I can read any of the values just fine, and the textbox input is coming through fine. Ive no idea whats going on here.

       

      See below my current test code;

       

      Private Sub renameDWG(replaceRef As Boolean)

          Dim sDWG As DrawingDoc

          Set dwgDoc = sApp.OpenDoc6(compDWG, 3, 1, "", lErrors, lWarnings)

          dwgDoc.SaveAs4 pathNameBox.Text & partNameBox.Text & ".SLDDRW", 0, 1, lErrors, lWarnings

              Set custProp = dwgDoc.Extension.CustomPropertyManager("")

              custProp.Add3 "DrawnDate", 30, dateBox.Text, 1

              derp2 = custProp.Get("Revision")

              custProp.Set2 "Revision", "Revised"

              derp3 = dateBox.Text

      '    doProperties (1)

          sApp.QuitDoc pathNameBox.Text & partNameBox.Text & ".SLDDRW"

         

          boolStatus = sApp.ReplaceReferencedDocument(pathNameBox.Text & partNameBox.Text & ".SLDDRW", compMod.GetPathName, pathNameBox.Text & partNameBox.Text & compExt)

      End Sub

        • Re: Cannot set custom property in drawing file
          Fifi Riri

          Hello,

          Isn't it because you're saving the file before making the changes?

          Try this as a test:

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim dwgDoc As SldWorks.DrawingDoc

          Dim boolstatus As Boolean

          Dim longstatus As Long, longwarnings As Long

          Dim myInputFile As String

          Dim myOutputFile As String

          Sub main()

              myInputfile = "C:\mydoc\myinputfile.SLDDRW"

              myOutputFile = "C:\mydoc\myoutputfile.SLDDRW"

              Set swApp = Application.SldWorks

              Set dwgDoc = swApp.OpenDoc6(myInputFile, 3, 1, "", longstatus, longwarnings)

              Dim CustProp As SldWorks.CustomPropertyManager

              Set CustProp = dwgDoc.Extension.CustomPropertyManager("")

              boolstatus = CustProp.Add3("DrawnDate", swCustomInfoType_e.swCustomInfoDate, "17-Apr-2005", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)

              boolstatus = dwgDoc.SaveAs4(myOutputFile, 0, 1, longstatus, longwarnings)

              swApp.QuitDoc myOutputFile

          End Sub