2 Replies Latest reply on Jul 21, 2017 7:58 AM by Matt Martens

    How to set the properties in Cut List using macro?

    Marco Wu

      I am writing a macro to set  a few properties of the cut list items.

      Pre conditions : a few cut list items are selected.

      Post conditions:

      1. Boundary boxes are created. 

      2. Bounding Box Width and length are found

      3. Description is set




      Option Explicit
      Dim swApp As Object
      Dim swModel As SldWorks.ModelDoc2
      Dim swSelMgr As SldWorks.SelectionMgr
      Dim swCustPropMgr As SldWorks.CustomPropertyManager
      Dim swFeat As SldWorks.Feature
      Dim selComp As Component2
      Dim Part As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long
      Dim i As Integer
      Dim iCount As Integer
      Dim bool As Boolean
      Dim valout As String
      Dim strValue(7)         As String
      Dim Counter As Integer
      Sub main()
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swSelMgr = swModel.SelectionManager
          iCount = swSelMgr.GetSelectedObjectCount2(-1)
          For i = 0 To iCount - 1
              Set selComp = swSelMgr.GetSelectedObjectsComponent4(i + 1, -1)
              MsgBox (selComp.Name2)
              bool = swModel.Extension.SelectByID2(selComp.Name2, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
                  Counter = Counter + 1
                  Set swCustPropMgr = swFeat.CustomPropertyManager
                  swCustPropMgr.Get4 "Bounding Box Width", False, strValue(0), strValue(1)
                  swCustPropMgr.Get4 "Bounding Box Length", False, strValue(2), strValue(3)
                  swCustPropMgr.Set2 "Description", "Bar" & Counter
                  If strValue(0) <= 3.18 And strValue(0) >= 3.13 Then
                      MsgBox (strValue(0))
                  End If
          Next i
      End Sub