4 Replies Latest reply on Jul 25, 2018 6:24 PM by Josh Hixon

    Help with Changing component configuration within assembly with a macro?

    Josh Hixon

      My code for this macro seems like it should be right, but I can not for the life of me figure why I keep getting this error.

      The code is intended to change a few different parts and subassembly configurations based on top level custom properties. I feel like it is not setting swcomp to anything even though it doesn't error. My first component name is the same as my top level assembly and changes per order.

      Here is my code:

       

      Dim swapp As SldWorks.SldWorks

      Dim Swmodel As SldWorks.ModelDoc2

      Dim swcomp As SldWorks.Component2

      Dim swassy As SldWorks.AssemblyDoc

      Dim RorX As String

      Dim Color As String

      Dim Stepsd As String

      Dim stepsz As String

      Dim frame As String

      Dim Name As String

      Dim sel As SldWorks.SelectionMgr

      Dim status As Boolean

       

      Sub main()

       

       

      Set swapp = Application.SldWorks

      Set Swmodel = swapp.ActiveDoc

      If Swmodel Is Nothing Or (Swmodel.GetType <> swDocASSEMBLY) Then

          swapp.SendMsgToUser ("Open a Starting Block assembly and try again")

          Exit Sub

          End If

      Set swassy = Swmodel

      ' define the custom property vaiables_____________________________________________________________________

      RorX = Swmodel.CustomInfo("Block Type")

      Color = Swmodel.CustomInfo("SB Color - Steel")

      Stepsd = Swmodel.CustomInfo("SB Step Location")

      stepsz = Swmodel.CustomInfo("SB Step Size")

      frame = Swmodel.CustomInfo("SB Setback")

      ' File name for Frame________________________________________________________________________________________________________

      Name = Mid(Swmodel.GetPathName, InStrRev(Swmodel.GetPathName, "\") + 1)

      Name = Left(Name, InStrRev(Name, ".") - 1)

      'Frame Handling_________________________________________________________________

      Set swcomp = swassy.GetComponentByName(Name)

      If CInt(frame) >= 24 Then

      swcomp.ReferencedConfiguration = "SHORT"

      Else

      swcomp.ReferencedConfiguration = "LONG"

      End If

       

       

      End Sub

       

       

      On a tangent, I see some people add awesome little-numbered lines when they post code on the forums... how do you do this?