0 Replies Latest reply on Dec 22, 2017 8:08 AM by Steve Anderson

    I would like to know how to read and edit feature properties

    Steve Anderson

      Hello:

       

      I have written/modified this code, and basically it traverses through the features.  I have been able to programmatically isolate the feature I wish to edit.  It is at the bottom of TraverseNode2 where I need help.

       

      1.  In the selected feature, under "Standard:" I need to reload the static value "_WMI Profiles_"

      2.  In the selected feature, under "Type: Configured Profile" (determined as node.Text), I need to add the value from my array and append the static value " - Configured" to it.

      3.  In the selected feature, under "Size:" I need to first read (this can be done earlier on), and then repopulate the same information.

      4.  Finally I need to check ok.

       

      In the manual world, this is the only way I have found to add two properties to the cutlist properties.  The information already exists, but is just not there until this is done.

       

      The goal will be to automate this in all parts, to eliminate the pain of doing it manually for thousands of parts.  For questions 1-3 above, I just do not see any API calls to accomplish these things.

       

      See attachment...

       

      FeatureOptionsDialog.jpg

       

       

      Thanks!

       

       

              If (displayNodeInfo) Then
                  ' Compare Contents of node item where TraverseLevel = 1 and contains the array information
                  Debug.WriteLine(TRAVERSELEVEL & ": " & node.Text)
                  For c As Integer = 0 To AL_WELDMENTPROFILEFILES.Count - 1
                      Debug.WriteLine(AL_WELDMENTPROFILEFILES(c))
                      ' Check if weldment profile is contained in feature name
                      If TRAVERSELEVEL = 1 Then
                          If InStr(node.Text.ToLower, AL_WELDMENTPROFILEFILES(c).tolower) <> 0 Then
                              Debug.WriteLine("Feature Match: " & node.Text & ", " & AL_WELDMENTPROFILEFILES(c))
                              Dim cx As Integer = c

                              ' Edit Feature
                              ' 1. Reload --> '_WMI Profiles_'
                              Dim StandardProfile As String = "_WMI Profiles_"

                              ' 2. Select Type --> AL_WELDMENTPROFILEFILES(c) & " - Configured'
                              ' Get full path object
                              Dim ConfiguredProfile_FullPath As String = AL_WELDMENTPROFILEFILES_FULLPATH.Item(cx)
                              Debug.WriteLine(ConfiguredProfile_FullPath)

                              ' 3. Select Sized --> Must be read in prior to being specified again.Helo:

       

       

                          End If

                      End If

                  Next

              End If

       

       

      ---------

          Private Sub cmdTraverse_Click(sender As Object, e As EventArgs) Handles cmdTraverse.Click
              Dim swPart As ModelDoc2 = swApp.ActiveDoc

              ' Properties Variables
              Dim swCpm As CustomPropertyManager = swModel.Extension.CustomPropertyManager("")
              Dim GetNames() As String = swCpm.GetNames
              Dim theval As String = ""
              Dim thevalres As String = ""

              ' Create arraylist of SLDLFP files located in 'C:\Sackett-Waconia\Master Documents\SOLIDWORKS TEMPLATES\weldment profiles\_WMI Profiles_'
              ' ENHANCEMENT: Obtain progran folder programatically
              BuildArrayList(AL_WELDMENTPROFILEFILES, "C:\Master Documents\SOLIDWORKS TEMPLATES\weldment profiles\_WMI Profiles_")
              BuildArrayList_FullPath(AL_WELDMENTPROFILEFILES_FULLPATH, "C:\Master Documents\SOLIDWORKS TEMPLATES\weldment profiles\_WMI Profiles_")

              For c As Integer = 0 To AL_WELDMENTPROFILEFILES.Count - 1
                  Debug.WriteLine(c & " of " & AL_WELDMENTPROFILEFILES.Count & ": " & AL_WELDMENTPROFILEFILES(c))

              Next

              ' Profile Variables
              Dim swSelectionManager As SelectionMgr = swPart.SelectionManager
              Dim featureManager As FeatureManager = swPart.FeatureManager
              Dim rootNode As TreeControlItem = featureManager.GetFeatureTreeRootItem()

              If Not rootNode Is Nothing Then
                  MessageBox.Show(rootNode.ToString)
                  TraverseNode2(rootNode)

              End If

              MessageBox.Show("Done.")

          End Sub

          Private Sub BuildArrayList(ByVal al As ArrayList, ByVal Folder As String)
              Dim Files As String() = Directory.GetFiles(Folder)
              Dim FileName As String
              For Each FileName In Files
                  ' Return FileName without path
                  al.Add(Path.GetFileNameWithoutExtension(FileName)) ' GetFileNameWithoutExtension also removes the path!

              Next

          End Sub

          Private Sub BuildArrayList_FullPath(ByVal al As ArrayList, ByVal Folder As String)
              Dim Files As String() = Directory.GetFiles(Folder)
              Dim FileName As String
              For Each FileName In Files
                  ' Return FileName without path
                  al.Add(FileName)

              Next

          End Sub

       

       

          Private Sub TraverseNode2(node As TreeControlItem)
              Dim childNode As TreeControlItem
              Dim featureNode As Feature
              Dim componentNode As Component2
              Dim nodeObjectType As Long
              Dim nodeObject As Object
              Dim restOfString As String
              Dim indent As String
              Dim i As Integer
              Dim displayNodeInfo As Boolean
              Dim compName As String
              Dim suppr As Long, supprString As String
              Dim vis As Long, visString As String
              Dim fixed As Boolean, fixedString As String
              Dim componentDoc As Object, docString As String
              Dim refConfigName As String
              displayNodeInfo = False
              nodeObjectType = node.ObjectType
              nodeObject = node.Object

              Select Case nodeObjectType
                  Case swTreeControlItemType_e.swFeatureManagerItem_Feature
                      displayNodeInfo = True
                      If Not nodeObject Is Nothing Then
                          featureNode = nodeObject
                          restOfString = "[FEATURE: " & featureNode.Name & "]"
                      Else
                          restOfString = "[FEATURE: object Null?!]"

                      End If

                  Case swTreeControlItemType_e.swFeatureManagerItem_Component
                      displayNodeInfo = True
                      If Not nodeObject Is Nothing Then
                          componentNode = nodeObject
                          compName = componentNode.Name2
                          If (compName = "") Then
                              compName = "???"

                          End If

                          suppr = componentNode.GetSuppression()
                          Select Case (suppr)
                              Case swComponentSuppressionState_e.swComponentFullyResolved
                                  supprString = "Resolved"

                              Case swComponentSuppressionState_e.swComponentLightweight
                                  supprString = "Lightweight"

                              Case swComponentSuppressionState_e.swComponentSuppressed
                                  supprString = "Suppressed"

                          End Select

                          vis = componentNode.Visible

                          Select Case (vis)
                              Case swComponentVisibilityState_e.swComponentHidden
                                  visString = "Hidden"

                              Case swComponentVisibilityState_e.swComponentVisible
                                  visString = "Visible"

                          End Select

                          fixed = componentNode.IsFixed

                          If fixed = 0 Then
                              fixedString = "Floating"

                          Else
                              fixedString = "Fixed"

                          End If

                          componentDoc = componentNode.GetModelDoc
                          If componentDoc Is Nothing Then
                              docString = "NotLoaded"

                          Else
                              docString = "Loaded"

                          End If

                          refConfigName = componentNode.ReferencedConfiguration

                          If (refConfigName = "") Then
                              refConfigName = "???"

                          End If

                          restOfString = "[COMPONENT: " & compName & " " & docString & " " & supprString & " " & visString & " " & refConfigName & "]"

                      Else
                          restOfString = "[COMPONENT: object Null?!]"

                      End If

                  Case Else
                      displayNodeInfo = True

                      If Not nodeObject Is Nothing Then
                          restOfString = "[object type not handled]"

                      Else
                          restOfString = "[object Null?!]"

                      End If

              End Select

              For i = 1 To TraverseLevel
                  indent = indent & "  "

              Next I

              If (displayNodeInfo) Then
                  ' Compare Contents of node item where TraverseLevel = 1 and contains the array information
                  Debug.WriteLine(TRAVERSELEVEL & ": " & node.Text)
                  For c As Integer = 0 To AL_WELDMENTPROFILEFILES.Count - 1
                      Debug.WriteLine(AL_WELDMENTPROFILEFILES(c))
                      ' Check if weldment profile is contained in feature name
                      If TRAVERSELEVEL = 1 Then
                          If InStr(node.Text.ToLower, AL_WELDMENTPROFILEFILES(c).tolower) <> 0 Then
                              Debug.WriteLine("Feature Match: " & node.Text & ", " & AL_WELDMENTPROFILEFILES(c))
                              Dim cx As Integer = c

                              ' Edit Feature
                              ' 1. Reload --> '_WMI Profiles_'
                              Dim StandardProfile As String = "_WMI Profiles_"

                              ' 2. Select Type --> AL_WELDMENTPROFILEFILES(c) & " - Configured'
                              ' Get full path object
                              Dim ConfiguredProfile_FullPath As String = AL_WELDMENTPROFILEFILES_FULLPATH.Item(cx)
                              Debug.WriteLine(ConfiguredProfile_FullPath)

                              ' 3. Select Sized --> Must be read in prior to being specified again.Helo:

       

       

                          End If

                      End If

                  Next

              End If

              TRAVERSELEVEL = TraverseLevel + 1

              childNode = node.GetFirstChild()

              While Not childNode Is Nothing
                  TraverseNode2(childNode)
                  childNode = childNode.GetNext

              End While

              TRAVERSELEVEL = TRAVERSELEVEL - 1

          End Sub