10 Replies Latest reply on Nov 9, 2018 12:33 PM by Mike Flanders

    Changing Reference Planes

    Mike Flanders

      I would like to make a macro that goes down through my part and switches a reference plane from what its currently to the front plane. I have the coolant holes right now based off one X-Hole 1 Rotation plane and the other 8 sets are set to the same. More and more customers are basing them off 0° and giving each plane its own degrees° value.

       

       

      switching xhole plane.JPG

        • Re: Changing Reference Planes
          Fifi Riri

          Hello, try this

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim Part As SldWorks.PartDoc

          Dim Feature As SldWorks.Feature

          Dim swRefPlaneData As IRefPlaneFeatureData

          Dim boolstatus As Boolean

          Sub main()

          Set swApp = Application.SldWorks

          Set Part = swApp.ActiveDoc

          'boolstatus = Part.Extension.SelectByID2("X-Hole 1 Rotation", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

          If Part.SelectionManager.GetSelectedObjectCount2(-1) <> 1 Then

              MsgBox ("Select a plane to modify")

              Exit Sub

          End If

          Set Feature = Part.SelectionManager.GetSelectedObject6(1, -1)

          Set swRefPlaneData = Feature.GetDefinition

          boolstatus = swRefPlaneData.AccessSelections(Part, Nothing)

          boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

          swRefPlaneData.Reference(0) = Part.SelectionManager.GetSelectedObject6(1, -1)

          boolstatus = Feature.ModifyDefinition(swRefPlaneData, Part, Nothing)

          End Sub

            • Re: Changing Reference Planes
              Mike Flanders

              This works for the first one. The planes are always called out the same thing. Could this be written to walk down and change all 10 of these planes without the interaction of selecting each of them first?? I see I missed the first one you did (X-Hole 1 Rotation)

               

              10 rotational planes.JPG

                • Re: Changing Reference Planes
                  Fifi Riri

                  Option Explicit

                  Sub main()

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Dim swFeat As SldWorks.Feature

                  Dim swRefPlaneData As IRefPlaneFeatureData

                  Dim FeatName As String

                  Dim boolstatus As Boolean

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Set swFeat = swModel.FirstFeature

                  Do While Not swFeat Is Nothing

                      If swFeat.GetTypeName2 = "RefPlane" Then

                          FeatName = UCase(swFeat.Name)

                          If (InStr(FeatName, "X-HOLE") > 0 Or InStr(FeatName, "XHOLE") > 0) And InStr(FeatName, "UNEQUAL") > 0 Then

                              Debug.Print FeatName

                              Set swRefPlaneData = swFeat.GetDefinition

                              boolstatus = swRefPlaneData.AccessSelections(swModel, Nothing)

                              boolstatus = swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

                              swRefPlaneData.Reference(0) = swModel.SelectionManager.GetSelectedObject6(1, -1)

                              boolstatus = swFeat.ModifyDefinition(swRefPlaneData, swModel, Nothing)

                          End If

                      End If

                      Set swFeat = swFeat.GetNextFeature

                  Loop

                  End Sub

                    • Re: Changing Reference Planes
                      Mike Flanders

                      This Macro does indeed do exactly what I'm trying to achieve with one exception. For some reason it renames the rotation value name to a default "D1" variable name. This breaks the link into my configuration table so this variable isn't controlled without re selecting them in the table. I went in and double checked this feature change and it doesn't change the variable name and all remains in my table.

                      The two pictures illustrates a before and after the macro is hit.

                       

                      unequal dissappearing.JPG

                      after macro.JPG

                        • Re: Changing Reference Planes
                          Fifi Riri

                          Add this at the end of the macro, to change the names:

                           

                          Dim myDimension As SldWorks.Dimension

                          Set myDimension = swModel.Parameter("D1@X-Hole 2 Unequal")

                          myDimension.Name = "2nd XHole Unequally Spaced"

                          Set myDimension = swModel.Parameter("D1@X-Hole 3 Unequal ")

                          myDimension.Name = "XHole 3 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@X-Hole 4 Unequal")

                          myDimension.Name = "XHole 4 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@X-Hole 5 Unequal")

                          myDimension.Name = "XHole 5 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@X-Hole 6 Unequal")

                          myDimension.Name = "XHole 7 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@XHole 7 Unequal")

                          myDimension.Name = "XHole 7 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@XHole 8 Unequal")

                          myDimension.Name = "XHole 8 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@XHole 9 Unequal")

                          myDimension.Name = "XHole 9 Unequal (<)"

                          Set myDimension = swModel.Parameter("D1@Xhole 10 Unequal")

                          myDimension.Name = "XHole 10 Unequal"

                  • Re: Changing Reference Planes
                    Solid Air

                    Could you simply rename your hole features with the angle they are put in at instead of creating a bunch of unnecessary planes?

                      • Re: Changing Reference Planes
                        Mike Flanders

                        This part template is a worse case scenario part. I has every imaginable feature built into it. Those planes are not the angle they are put in at. They are the rotation from the flute face and so many customers these days are using whats called MQL "minumum quantity lubricant" and it is very crucial the rotational placement of these coolant holes. I use these macros to delete unnecessary features, planes and reference geometry to "dumb" the model down to only what parameters/features it  needs. I have developed to be very quick. I can design customer cutting tools in almost any configuration in just a few minutes once "dumbed" down and using the configuration table as a drive table. The table before any of my macro sequences has four times the variable lines lines in it. one I run the macros to break down the options I want it automatically cleans up my configuration tables like the bottom photo with only parameters I am dealing with.

                         

                        CONFIG TABLE SIZED CENTERED.JPG

                        Capture.JPG