2 Replies Latest reply on May 22, 2014 12:02 AM by Vincent Li

    Renamed the component name , and found wrong name under pattern feature in assembly design tree?

    Vincent Li

      Dear Master Shi Fu,

       

      when I Renamed the component name , and found wrong name under pattern feature in assembly design tree, using the macro sample in the API help.

       

      But the result showed that the component names under the pattern feature are wrong , we hope it they are the same.

       

      you may check the attached picture. How to handle it ? pls help to advise.

       

      *****************************************************************

       

      Dim swapp                   As SldWorks.SldWorks

          Dim swmodel                 As SldWorks.ModelDoc2

          Dim swConfigMgr             As SldWorks.ConfigurationManager

          Dim swConfig                As SldWorks.Configuration

          Dim swRootComp              As SldWorks.Component2

          Dim Children                As Variant

          Dim swChild                 As SldWorks.Component2

          Dim ChildCount              As Integer

          Dim OldName                 As String

          Dim NewName                 As String

          Dim bOldSetting             As Boolean

          Dim bRet                    As Boolean

          Dim i                       As Long

         

          Set swapp = Application.SldWorks

          Set swmodel = swapp.ActiveDoc

          Set swConfigMgr = swmodel.ConfigurationManager

          Set swConfig = swConfigMgr.ActiveConfiguration

          Set swRootComp = swConfig.GetRootComponent

         

          bOldSetting = swapp.GetUserPreferenceToggle(swExtRefUpdateCompNames)

          swapp.SetUserPreferenceToggle swExtRefUpdateCompNames, False

         

          Children = swRootComp.GetChildren

          ChildCount = UBound(Children)

         

          For i = 0 To ChildCount

              Set swChild = Children(i)

             

              ' Changing component name requires component to be selected

              bRet = swChild.Select2(False, 0)

             

              OldName = swChild.Name2

              NewName = OldName & "_" & UserForm1.TextBox1.Text

              Debug.Print "OldName = " + OldName

              Debug.Print "NewName = " + NewName

              Debug.Print ""

             

              swChild.Name2 = NewName

          Next i
         
          swapp.SetUserPreferenceToggle swExtRefUpdateCompNames, bOldSetting
         
        
      2014-05-21_16-12-00.jpg