7 Replies Latest reply on Dec 17, 2013 10:18 AM by Eric Fox

    Add Property to Cut-List

    jacob may

      I have a part with several sheet metal bodies and i am wanting to add different properties to each of the cut list items. My part currently has Cut-List-Item1 through Cut-List-Item10.

      I have searched solidworks api help, the forums, and google, and i know how to add custom properties to the part itself, but have no idea on how to add properties specific to cut-list items. If anyone has any insight on this it would be greatly appreciated. Also Cut-List-Item2, & Cut-List-Item3 are the only two showing up in a folder in the cut-list area of my design tree. Does anyone know why this is, and does it even matter?

       

      Thanks in advance!

        • Re: Add Property to Cut-List
          Artem Taturevych

          Use the same ICustomPropertyManager interface retrieved via IFeature::CustomPropertyManager.

           

          Here is the example:

           

          http://help.solidworks.com/2012/English/api/sldworksapi/Get_Custom_Properties_for_Cut-list_Item_Example_VB.htm

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: Add Property to Cut-List
              jacob may

              I am not really too for sure if i added these two together right to do what i am wanting to do. I used IFeature::CustomPropertyManager to get the custom properties then AddCustomInfo3 to add a new custom property. When i run this code it still adds my new property to the part custom properties, it does not add the new property to the properties specific to the Cut-List-Item i have selected.

               

               

              Sub main()

               

              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swSelMgr As SldWorks.SelectionMgr
              Dim swCutlistItem As SldWorks.Feature
              Dim swCustPropMgr As SldWorks.CustomPropertyManager
              Dim names As Variant
              Dim name As Variant
              Dim textexp As String
              Dim evalval As String

               

              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swSelMgr = swModel.SelectionManager
              Set swCutlistItem = swSelMgr.GetSelectedObject6(1, 0)
              Set swCustPropMgr = swCutlistItem.CustomPropertyManager

               

              Debug.Print "Custom Properties for Selected Weldment Cut-list Item"
              Debug.Print "Number of custom properties = " + CStr(swCustPropMgr.Count)
              Debug.Print "Name", "Text Expression", "Value", "Type"

               

              names = swCustPropMgr.GetNames

               

              For Each name In names
                  swCustPropMgr.Get2 name, textexp, evalval
                  Debug.Print name, textexp, evalval, swCustPropMgr.GetType(name)
              Next name

               

              Dim swDraw As SldWorks.DrawingDoc
              Dim retval As String
              Set swModel = swApp.ActiveDoc


              retval = swModel.AddCustomInfo3("", "Input1", swCustomInfoNumber, "2345")

              End Sub

                • Re: Add Property to Cut-List
                  Artem Taturevych

                  You should use the CustomPropertyManager::Add2, CustomPropertyManager::Set from your custom property manager pointer:

                   

                  swCustPropMgr.Add2 "Inout1", swCustomInfoNumber, "1234"

                  swCustPropMgr.Set "Input1", "1234"

                  ______________________

                  Regards,

                  Artem Taturevych

                  Application Engineer at Intercad

                  http://intercad.com.au/

                  Tel: +61 2 9454 4444

                    • Re: Add Property to Cut-List
                      jacob may

                      I actually found a chunk of code on the internet and re-built it to suit my needs. Instead of having to click on a Cut-List-Item I have set it up to loop through all of the Cut-List-Items and set up new custom properties based on existing custom properties. I am still tweaking it and little, but i will post the code once i have it finished incase anyone else needs something like it.

                        • Re: Add Property to Cut-List
                          Artem Taturevych

                          This was just a sample of how can you get the cut-list properties but not the complete macro for you. Sure you have to modify this for your needs depending of what you like to see and what you have as an input.

                          ______________________

                          Regards,

                          Artem Taturevych

                          Application Engineer at Intercad

                          http://intercad.com.au/

                          Tel: +61 2 9454 4444

                          • Re: Add Property to Cut-List
                            Eric Fox

                            Jacob,

                             

                            I know it's been nearly a year since you made this reply, but have you finished up the code you're talking about? I have a similar application I am trying to get to work.

                             

                            So, I have a macro that we run at the top-level assembly that totals the number of times a component is used in the assembly, then writes back a custom property to each part file named "ExtQTY". The extended quantity is then displayed in the top-level BOM, and exported out for quoting/purchasing. The issue I am having is that I can get the extended quantity to write back to the weldment part file, but not to individual cut list items. It sounds like your code may do this for me.

                             

                            To give an example, we may use the same weldment bodies 3 times in the top-level, so the extended quantity would be 3x each of the components in the weldment. When we send the weldment print to our vendor, we want them to see how many pieces of each cut list item they need to make for the individual weldment (standard quantity), and how many pieces for the top-level assembly (extended quantity). The goal is to make this an automated process instead of having to manually total all of the components and then add the value to the BOM. Make sense?

                    • Re: Add Property to Cut-List
                      Seth Ruhan

                      Jacob,

                       

                      This is the code I use to acces cut lists.

                       

                       

                      public class aNameHere

                      Public ModDoc As IModelDoc2

                          Public swModelDocExt As ModelDocExtension

                          Public Sub New(ByVal NewFile As IModelDoc2)

                              ModDoc = NewFile

                              swModelDocExt = ModDoc.Extension

                          End Sub

                      #Region "CutLits"

                          Private Function GetCutListFeatures() As List(Of Feature)

                              Dim aFeature As IFeature = ModDoc.FirstFeature()

                              Dim CutListFeatures As New List(Of Feature)

                              Do While aFeature IsNot Nothing

                                  If aFeature.GetTypeName2 = "CutListFolder" Then

                                      Dim CutFolder As BodyFolder = aFeature.GetSpecificFeature2

                                      If CutFolder.GetBodyCount > 0 Then

                                          CutListFeatures.Add(aFeature)

                                      End If

                                  End If

                                  aFeature = aFeature.GetNextFeature()

                              Loop

                              If CutListFeatures.Count = 0 Then

                                  Return Nothing

                              Else

                                  Return CutListFeatures

                              End If

                          End Function

                          Public Function GetCutListProperties() As ConfigsWithProps()

                              Dim swCustPropMgr As CustomPropertyManager

                              Dim liCutList As List(Of Feature) = GetCutListFeatures()

                              Dim Names As Object = Nothing

                              Dim types As Object = Nothing

                              Dim value As Object = Nothing

                              Dim bool As Boolean = False

                       

                       

                              Dim ConfigsWithProp(liCutList.Count - 1) As ConfigsWithProps

                              Dim Count As Integer = 0

                       

                       

                              If liCutList IsNot Nothing Then

                                  For Each CutList As Feature In liCutList

                                      swCustPropMgr = CutList.CustomPropertyManager()

                                      bool = swCustPropMgr.GetAll(Names, types, value)

                                      If bool Then

                                          Dim Props(swCustPropMgr.Count - 1) As CustomProperty

                                          For index As Integer = 0 To swCustPropMgr.Count - 1

                                              Props(index) = New CustomProperty(Names(index), types(index), value(index).ToString)

                                          Next

                                          Dim CustomProps As New ConfigsWithProps(CutList.Name, Props)

                                          ConfigsWithProp(Count) = CustomProps

                                          Count += 1

                                      End If

                                  Next

                                  Return ConfigsWithProp

                              End If

                              Return Nothing

                          End Function

                          Public Function DeleteallCutListProperties() As Boolean

                              Dim swCustPropMgr As CustomPropertyManager

                              Dim liCutList As List(Of Feature) = GetCutListFeatures()

                              If liCutList IsNot Nothing Then

                                  Try

                                      For Each CutList As Feature In liCutList

                                          swCustPropMgr = CutList.CustomPropertyManager()

                                          For Each PropName As String In swCustPropMgr.GetNames

                                              swCustPropMgr.Delete(PropName)

                                          Next

                                      Next

                                      Return True

                                  Catch

                                      Return False

                                  End Try

                              End If

                          End Function

                          Public Function AddCutListProp(ByVal Prop As ConfigsWithProps) As Boolean

                              Dim swCustPropMgr As CustomPropertyManager

                              Dim liCutList As List(Of Feature) = GetCutListFeatures()

                              Dim myError As Boolean = True

                       

                       

                              If liCutList IsNot Nothing Then

                                  For Each CutList As Feature In liCutList

                                      If CutList.Name = Prop.ConfigName Then

                                          swCustPropMgr = CutList.CustomPropertyManager()

                                          For Each Props As CustomProperty In Prop.CustomProps

                                              Try

                                                  DeleteCutlistProp(Prop)

                                                  If Not swCustPropMgr.Add(Props.Name, Props.type, Props.Value) Then

                                                      myError = False

                                                  End If

                                              Catch

                                                  myError = False

                                              End Try

                                          Next

                                      End If

                                  Next

                              End If

                              Return myError

                          End Function

                          Public Function DeleteCutlistProp(ByVal Prop As ConfigsWithProps) As Boolean

                              Dim swCustPropMgr As CustomPropertyManager

                              Dim liCutList As List(Of Feature) = GetCutListFeatures()

                              Dim myError As Boolean = True

                       

                       

                              If liCutList IsNot Nothing Then

                                  For Each CutList As Feature In liCutList

                                      If CutList.Name = Prop.ConfigName Then

                                          swCustPropMgr = CutList.CustomPropertyManager()

                                          For Each Props As CustomProperty In Prop.CustomProps

                                              Try

                                                  DeleteCutlistProp(Prop)

                                                  If Not swCustPropMgr.Delete(Props.Name) Then

                                                      myError = False

                                                  End If

                                              Catch

                                                  myError = False

                                              End Try

                                          Next

                                      End If

                                  Next

                              End If

                              Return myError

                          End Function

                          Public Function DeleteCutlistProp(ByVal Name As String) As Boolean

                              Dim swCustPropMgr As CustomPropertyManager

                              Dim liCutList As List(Of Feature) = GetCutListFeatures()

                              Dim myError As Boolean = True

                       

                       

                              If liCutList IsNot Nothing Then

                                  For Each CutList As Feature In liCutList

                                      swCustPropMgr = CutList.CustomPropertyManager()

                                      For Each PropName As String In swCustPropMgr.GetNames

                                          If Name = PropName Then

                                              Try

                                                  If Not swCustPropMgr.Delete(PropName) Then

                                                      myError = False

                                                  End If

                                              Catch

                                                  myError = False

                                              End Try

                                          End If

                                      Next

                                  Next

                              End If

                              Return myError

                          End Function

                      #End Region

                       

                       

                      End Class

                       

                       

                      Public Structure CustomProperty

                          ReadOnly Name As String

                          ReadOnly type As Integer

                          ReadOnly Value As String

                          Public Sub New(ByVal dName As String, ByVal dType As Integer, ByVal dValue As String)

                              Name = dName

                              type = dType

                              Value = dValue

                          End Sub

                      End Structure

                      Public Structure ConfigsWithProps

                          ReadOnly ConfigName As String

                          Private _CustomProps() As CustomProperty

                          Public Sub New(ByVal dName As String, ByVal CustomProp As CustomProperty)

                              ConfigName = dName

                              ReDim _CustomProps(0)

                              _CustomProps(0) = CustomProp

                          End Sub

                          Public Sub New(ByVal dName As String, ByVal CustomProps() As CustomProperty)

                              ConfigName = dName

                              _CustomProps = CustomProps

                          End Sub

                          Public Sub AddProp(ByVal value As CustomProperty)

                              ReDim Preserve _CustomProps(_CustomProps.Length)

                              _CustomProps(_CustomProps.Length - 1) = value

                          End Sub

                          ReadOnly Property CustomProps() As CustomProperty()

                              Get

                                  Return _CustomProps

                              End Get

                          End Property

                      End Structure