7 Replies Latest reply on Jan 30, 2014 4:58 PM by Seth Ruhan

    Retrieving Weldment Custom Properties

    Chris Day

      I'm trying to get the code linked below to work on a multi-body part with structural members and plates. When I select the Structural Member feature in the FeatureManager Tree and run the code swSelMgr.GetSelectedObject6(1, 0) returns null. The code therefore fails at For Each name In names as names is empty.

       

      Get Custom Properties for Weldment Cut-list Item Example (VBA)

       

      Although I'm running 2013 SP5 the GetSelectedObject6 method does exist, so I'm not sure what else could be at fault.

        • Re: Retrieving Weldment Custom Properties
          Artem Taturevych

          The expected feature is not a weldment feature but the cut-list feature under the cut-list folders.

           

          GetSelectedObject6 method is available from SolidWorks 2006. I assume it just doesn't list in your intellisense (happens to me sometimes in SolidWorks 2013 and 2014 with new VB7 engine).

          • Re: Retrieving Weldment Custom Properties
            Seth Ruhan

            All though you have your solution, Here's some thing from the libary

             

            1 - Update Cut lists (inc Sheet metal bouding box's)

              2 - Get Cut List Items as OO

            3 - Cut List Class, Inc Custom Properties & Type of item

             

             

            Update Cutlist (inc Sheet metal bounding box) wrote:

             

            Public Function RebuildCutListFeature(ByVal ModDoc As ModelDoc2) As Boolean

                    Try

             

             

                        If ModDoc.GetType <> swDocumentTypes_e.swDocPART Then Return False

             

             

                        Dim swPart As PartDoc = ModDoc

             

             

                        Dim BodyFolder As IBodyFolder = Nothing

             

             

                        If Not swPart.IsWeldment Then

                            Return False

                        End If

             

             

                        'Update Bouding Box

                        Dim swFeat As Feature = swPart.FirstFeature

                        Do While Not swFeat Is Nothing

                            If "FlatPattern" = swFeat.GetTypeName2 Then

                                swPart.ClearSelection2(True)

                                swFeat.Select2(False, -1)

                                If swPart.EditUnsuppress2 Then

                                    swPart.ForceRebuild3(True)

                                    swFeat.Select2(False, -1)

                                    swPart.EditSuppress()

                                End If

                            End If

                            swFeat = swFeat.GetNextFeature

                        Loop

                        'Update Cut list items

                        swFeat = swPart.FirstFeature

                        Do While Not swFeat Is Nothing

                            If "SolidBodyFolder" = swFeat.GetTypeName2 Then

                                BodyFolder = swFeat.GetSpecificFeature2

                                If BodyFolder.GetAutomaticCutList Then

                                    BodyFolder.UpdateCutList()

                                End If

                            End If

                            swFeat = swFeat.GetNextFeature

                        Loop

                        Return True

                    Catch

                        Return False

                    End Try

                End Function

             

             

            Get Cut list properties (OO) & Cut list class:

             

            Public Function GetCutListItems() As List(Of CutListItem)

                    If _AllCutListFeats Is Nothing Then

                          Dim aFeature As IFeature = ModDocExt.ModDoc.FirstFeature()

                        Dim CutListFeatures As New List(Of CutListItem)

                        Do While aFeature IsNot Nothing

                            If aFeature.GetTypeName2 = "CutListFolder" Then

                                Dim CutFolder As BodyFolder = aFeature.GetSpecificFeature2

                                If CutFolder.GetBodyCount > 0 Then

                                    CutListFeatures.Add(New CutListItem(aFeature))

                                End If

                            End If

                            aFeature = aFeature.GetNextFeature()

                        Loop

                        If CutListFeatures.Count = 0 Then

                            Return Nothing

                        Else

                            _AllCutListFeats = CutListFeatures

                        End If

                    End If

                    Return _AllCutListFeats

                End Function

             

             

            Public Class CutListItem

                Public Feature As IFeature

                Dim CustPropMgr As CustomPropertyManager

                Public Sub New(ByVal Item As IFeature)

                    If Item.GetTypeName2 = "CutListFolder" Then

                        Feature = Item

                        CustPropMgr = Feature.CustomPropertyManager

                    End If

                End Sub

                Public Function CustomProperties() As List(Of CutlistProperty)

                    Dim swCustPropMgr As CustomPropertyManager = Feature.CustomPropertyManager()

             

             

                    If swCustPropMgr.Count > 0 Then

                        Dim Props As New List(Of CutlistProperty)

                        For Each name As String In swCustPropMgr.GetNames

                            Props.Add(New CutlistProperty(Me, name))

                        Next

                        Return Props

                    End If

                    Return Nothing

                End Function

                Function DeleteProperty(ByVal Value As String) As Boolean

                    Return CustPropMgr.Delete(Value)

                End Function

                Function DeleteAllProperties() As Boolean

                    For Each name As String In CustPropMgr.GetNames

                        CustPropMgr.Delete(name)

                    Next

                    Return True

                End Function

                Public Property CustomProperty(ByVal Name As String) As String

                    Get

                        Try

                            Dim ValueOut As String = ""

                            Dim ResovedValue As String = ""

                            CustPropMgr.Get2(Name, ValueOut, ResovedValue)

                            Return ValueOut

                        Catch

                            Return Nothing

                        End Try

                    End Get

                    Set(ByVal value As String)

                        If CustomProperty(Name) <> "" Then

                            CustPropMgr.Set(Name, value)

                        Else

                            CustPropMgr.Add2(Name, swCustomInfoType_e.swCustomInfoText, value)

                        End If

                    End Set

                End Property

                Public ReadOnly Property ResovedValueCustomProperty(ByVal Name As String) As String

                    Get

                        Try

                            Dim ValueOut As String = ""

                            Dim ResovedValue As String = ""

                            CustPropMgr.Get2(Name, ValueOut, ResovedValue)

                            Return ResovedValue

                        Catch

                            Return Nothing

                        End Try

                    End Get

                End Property

             

             

             

                Public ReadOnly Property Type() As CutListType_e

                    Get

                        Try

                            Dim CutFolder As BodyFolder = Feature.GetSpecificFeature2

                            Dim ABody As Body2 = CutFolder.GetBodies(0)

             

             

             

             

             

             

                            For Each Feat As Feature In ABody.GetFeatures()

             

             

                                Dim FeatType As String = Feat.GetTypeName2

             

             

                                If FeatType = "SMBaseFlange" Or _

                                   FeatType = "SheetMetal" Or _

                                   FeatType = "SM3dBend" Or _

                                   FeatType = "SMMiteredFlange" Or _

                                   FeatType = "ProcessBends" Or _

                                   FeatType = "FlattenBends" Or _

                                   FeatType = "EdgeFlange" Or _

                                   FeatType = "FlatPattern" Or _

                                   FeatType = "Hem" Or _

                                   FeatType = "Jog" Or _

                                   FeatType = "Rip" Or _

                                   FeatType = "CornerFeat" Or _

                                   FeatType = "LoftedBend" _

                                    Then

                                    Return CutListType_e.SheetMetal

                                ElseIf FeatType = "WeldMemberFeat" Then

                                    Return CutListType_e.StructuralMember

                                End If

                            Next

                        Catch ex As Exception

                            Return CutListType_e.Unknown

                        End Try

             

             

                        Return CutListType_e.Unknown

                    End Get

                End Property

             

             

                Enum CutListType_e

                    Unknown

                    StructuralMember

                    SheetMetal

                End Enum

             

             

            End Class