3 Replies Latest reply on Apr 2, 2014 12:53 AM by Seth Ruhan

    Renaming Features

    Seth Ruhan

      Hello

       

      I'm trying to rename some features, However I'm finding that when doing it via API it does not update the name in the cutlist.

       

      If rename StructuralMember1 to Beam , The cutlist properties still refer to StructuralMember1 not Beam, Which then causes the custom property not resolve.

      Equations & custom properties seem to be working correctly.

       

      Code i'm using is :

       

      Dim Feat As IFeature = swModel.FirstFeature

      Feat.Name = PartName & Counter.ToString

       

       

      Is there a better way to achive the same results with out having to loop through every cut list property?

        • Re: Renaming Features
          Marquis Leblanc

          Hi,

           

          for your information,  cutlist bodies, as well as other solid bodies and surface bodies, are 'named' at the time of creation, which means ,at the time of creation of the feature that created it...

           

          so yes you can rename the bodies anytime after, but you have to do a forcerebuild after.

           

          as for the custom properties already made and/or equations, it's another set of problem...

           

          ...i suggest getting the data, such as values or properties names or equations variables, via your macro BEFORE renaming your bodies, then deal the respective changes of names, then delete/create/update them with the new names...

           

          I hope its been somewhat helpful ...

            • Re: Renaming Features
              Seth Ruhan

              Thank you for the clarification.

               

              I ended up doing as you suggested, get the name of the feature before rename, the search and replace the name.

               

              Currently I only wrote a find and replace for Cutlist properties. However I will need to do it for Custom Properties & equations and hopefully that covers all bases.

               

               

              Attached is the short hand code for reference. (A bit rough compared to implemented code as I used more Classes)

               

                 

              Public Shared Sub RenameCutlistProperties(ByRef ModDOc As PartDoc, ByVal OldName As String, ByVal NewName As String)

                      Dim aFeature As IFeature = ModDoc.FirstFeature()

               

               

                      Dim CustPropMgr As ICustomPropertyManager

               

               

                      Do While aFeature IsNot Nothing

                          If aFeature.GetTypeName2 = "CutListFolder" Then

                              Dim CutFolder As BodyFolder = aFeature.GetSpecificFeature2

                              If CutFolder.GetBodyCount > 0 Then

                                  CustPropMgr = aFeature.CustomPropertyManager

                                  Dim ValueOut As String = ""

                                  Dim ResovedValue As String = ""

                                  CustPropMgr.Get2("Description", ValueOut, ResovedValue) 'Do this for all properties.

                                  If ResovedValue IsNot "" AndAlso Not ResovedValue.Contains(OldName) Then

                                      CustPropMgr.set2("Description", ResovedValue.Replace(OldName, NewName))

                                  End If

                              End If

                          End If

                          aFeature = aFeature.GetNextFeature()

                      Loop

                  End Sub

            • Re: Renaming Features
              Mati Link

              If you really are trying to rename first feature then this might be Favourites folder. Anyway, I just had created such macro which renames cutlist folders and bodies and cut list properties are automatically resolved to new names.

               

              This is actually "because I can" project because this feature should come in 2015 beta in summer.

               

              It is even greater joy to be able to modify SolidWorks yourself without needing to wait for new versions.