1 Reply Latest reply on May 18, 2014 4:37 AM by Deepak Gupta

    How do I remove hardcoded values from macros?

    Neville Bonwit

      I recorded a macro, but it has all sorts of hardcoded propterties in it instead of variables.

       

      After clicking on a part in an assembly, the user will start the macro.  The macro should:

      1) Open the selected part

      2) Go to Configurations->Properties

      3) Change the Bill of Materials Part Number to "Document Name"

      4) Go back to the Design Tree

      5) Save and close the file

       

      Please let me know what variables I should use to replace the 7 items in bold below.

       

      Thank you!

       

      ---------------------------

      ' Autogenerated Macro code

      Dim swApp As Object

       

       

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

       

      Sub main()

       

       

      Set swApp = _

      Application.SldWorks

       

      Set Part = swApp.ActiveDoc

      'boolstatus = Part.Extension.SelectByID2("McM 91841A011 Nut-1@Segment Cutter Roller", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

      Part.OpenCompFile

      'Set Part = swApp.OpenDoc6("C:\Users\...\_CAD\COTS\McM 91841A011 Nut.SLDPRT", 1, 0, "", longstatus, longwarnings)

      Set Part = swApp.ActiveDoc

      Dim myModelView As Object

      Set myModelView = Part.ActiveView

      myModelView.FrameLeft = 0

      myModelView.FrameTop = 0

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      swApp.ActivateDoc2 "McM 91841A011 Nut.SLDPRT", False, longstatus

      Set Part = swApp.ActiveDoc

      Part.ClearSelection2 True

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      boolstatus = Part.Extension.SelectByID2("91841A011", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)

      boolstatus = Part.EditConfiguration3("91841A011", "91841A011", "10-24", "", 32)

      Part.ClearSelection2 True

      Set Part = Nothing

      swApp.CloseDoc "McM 91841A011 Nut.SLDPRT"

      Set Part = swApp.ActiveDoc

      Set myModelView = Part.ActiveView

      myModelView.FrameLeft = 0

      myModelView.FrameTop = 0

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      swApp.ActivateDoc2 "Segment Cutter Roller.SLDASM", False, longstatus

      Set Part = swApp.ActiveDoc

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      End Sub