6 Replies Latest reply on Apr 4, 2018 5:59 AM by Dave Bear


    Stanislao Bazoli


      I need a macro to rename the default plans. How can I recognize the default plans as some of them have already been renamed in some parts?

      Thank you

          Dave Bear



          • Re: MACRO RENAME PLANE
            Solid Air

            Normally a macro of this type will be set up to traverse the feature manager tree.  The default planes with be the first three planes the macro finds.

            • Re: MACRO RENAME PLANE
              Rob Edwards

              Hi Stanislao


              Heres a vba class that handles default planes independent of name

              I quickly created a short example of using it... you will have to set any batch processing up yourself.

              Each time you process a new part or assembly just set the model property of the class to the active doc (see line 12)

              Works for parts and assemblies, macro attached


              Option Explicit
              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim dp As DefaultPlanes
              Dim swFeature As SldWorks.Feature
              Sub main()
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
                  Set dp = New DefaultPlanes
                  Set dp.Model = swModel
                  dp.Front.Name = "MyNewFrontPlane"
                  dp.Top.Name = "MyNewTopPlane"
                  dp.Right.Name = "MyNewRightPlane"
              End Sub



              'DefaultPlanes Class
              Option Explicit
              Private swDatum As SldWorks.Feature
              Private swModel As SldWorks.ModelDoc2
              Public Property Set Model(m As SldWorks.ModelDoc2)
                  Select Case True
                  Case m Is Nothing: Call Terminate
                  Case m.GetType = swDocumentTypes_e.swDocPART _
                    , m.GetType = swDocumentTypes_e.swDocASSEMBLY
                        Set swModel = m
                      Call Initialize
                  Case Else
                      Call Terminate
                  End Select
              End Property
              Private Sub Class_Initialize(): Debug.Print "Lazy init": End Sub
              Private Function Initialize()
                  Set swDatum = swModel.FirstFeature
                      Do While swDatum.GetTypeName2 <> "RefPlane"
                          Debug.Print swDatum.GetTypeName2
                            Set swDatum = swDatum.GetNextFeature
              End Function
              Public Property Get Front() As SldWorks.Feature
                  Set Front = IIf(swDatum Is Nothing, Nothing, swDatum)
              End Property
              Public Property Get Top() As SldWorks.Feature
                  Set Top = IIf(swDatum Is Nothing, Nothing, swDatum.GetNextFeature)
              End Property
              Public Property Get Right() As SldWorks.Feature
                  Set Right = IIf(swDatum Is Nothing, Nothing, swDatum.GetNextFeature.GetNextFeature)
              End Property
              Private Sub Class_Terminate(): Call Terminate: End Sub
              Private Function Terminate(): Set swModel = Nothing: Set swDatum = Nothing: End Function
                • Re: MACRO RENAME PLANE
                  Stanislao Bazoli

                  thank you sooooooooooooooooooooooooo much Rob

                  my manager is proud of me


                  I have another question for you...   but more difficult...


                  is it possible to check the opening of a file of the names of the floors, and if they do not correspond to those I wanted, does it change automatically?


                  ps: sorry my english...