3 Replies Latest reply on Sep 15, 2014 5:17 AM by Deepak Gupta

    Modify macro to work in SolidWorks drawing

    Feroz Mahomed

      How can I modify the code below to work in a SolidWorks drawing instead of a part?

       

       

      Sub Main()

      Set swApp = CreateObject("SldWorks.Application")
      Set CurrentDoc = swApp.ActiveDoc
      Set Part = swApp.ActiveDoc

      ' No document loaded error handler
        If Part Is Nothing Then
            MsgBox "No document loaded!", vbCritical
            End
        Else
        End If

      Part.ClearSelection2 True

      ' Assign custom properties
        PropName(0) = "Die Number"
        PropName(1) = "Plant"
        PropName(2) = "File Name"
        PropName(3) = "Press"
        PropName(4) = "Drawn Date"
        PropName(5) = "Del Date"
        PropName(6) = "Bolster"
        PropName(7) = "Cavities"

      ' Add custom properties (won't overwrite if they already exist)
        Prop = CurrentDoc.AddCustomInfo3("", PropName(0), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(1), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(2), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(3), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(4), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(5), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(6), swCustomInfoText, " ")
        Prop = CurrentDoc.AddCustomInfo3("", PropName(7), swCustomInfoText, " ")

      Call CheckProps

      End Sub

        • Re: Modify macro to work in SolidWorks drawing
          Deepak Gupta

          Here are the updated codes

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim Part As ModelDoc2

          Dim PropName(8) As String

          Dim Prop As Boolean

          Sub Main()

           

          Set swApp = CreateObject("SldWorks.Application")

          'Set CurrentDoc = swApp.ActiveDoc 'Not sure why you have this line when next line does the same thing

          Set Part = swApp.ActiveDoc

           

          ' No document loaded error handler

            If Part Is Nothing Then

                MsgBox "No document loaded!", vbCritical

                End

            Else

            End If

          Part.ClearSelection2 True

           

          ' Assign custom properties

            PropName(0) = "Die Number"

            PropName(1) = "Plant"

            PropName(2) = "File Name"

            PropName(3) = "Press"

            PropName(4) = "Drawn Date"

            PropName(5) = "Del Date"

            PropName(6) = "Bolster"

            PropName(7) = "Cavities"

           

          ' Add custom properties (won't overwrite if they already exist)

            Prop = Part.AddCustomInfo2(PropName(0), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(1), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(2), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(3), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(4), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(5), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(6), swCustomInfoText, " ")

            Prop = Part.AddCustomInfo2(PropName(7), swCustomInfoText, " ")

           

          Call CheckProps

          End Sub