4 Replies Latest reply on Jul 26, 2013 6:51 PM by Mike Morgan

    Macro to change custom properties of a drawing's referenced part

    Mike Morgan

      I'm trying to create a macro that will do two things: 1) Add a revision to the revision table with a formatted date as the revision number (I have this section working so I have not included it here so it's easier to see my problem section) and 2) change the custom property, "Revision", of the part referenced by the drawing to have that same revision number as its value. I keep getting a run-time error 91 - object not set on the swDrawModel.CustomInfo2 line. How do I make this work? Any help would be much appreciated.



      Sub main()


      Dim revnum As String

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swSelMgr As SldWorks.SelectionMgr   

      Dim swView As SldWorks.View

      Dim swDrawModel As SldWorks.PartDoc

      Dim sModelName As String


      revnum = Format(Date, "YYMMDD")


          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swSelMgr = swModel.SelectionManager

          Set swView = swSelMgr.GetSelectedObject5(1)

         Set swDrawModel = swView.ReferencedDocument


          swDrawModel.CustomInfo2("", "Revision") = revnum





      End Sub