5 Replies Latest reply on Aug 27, 2015 2:54 PM by Dave Branco

    Is there a way to get temp axis of cylindrical face?

    Tore Magne Bjornodegard

      As the title states, is there a way to get temp axis of cylindrical face? I cant find enything about temp axis in API help, and it seems that the axis does not have any names...

      This is in assembly.

       

      Thanks!

        • Re: Is there a way to get temp axis of cylindrical face?
          Terrell Sprecher

          First.JPGSecond.jpg

          My assembly in the centre has a cylinder, however it is broke with a seam so the axis obviously doesn't show. But all the othe axis' show such as the blue one in the background for the sheet as a whole. These are simply reference geometry and can be shut off and on with the push of the View Temporary Axis button.

          • Re: Is there a way to get temp axis of cylindrical face?
            Artem Taturevych

            I'm afraid the only way to access the temporary axis is select it by coordinate:

             

            swModel.Extension.SelectByID2 "", "AXIS", -1, 0, 0, False, 0, Nothing, 0

             

            ____________________________________________________

            Regards,

            Artem Taturevych, Application Engineer at Intercad (Australia)

             

            translationXpert – add-in to translate SolidWorks models

            myIntercad an integrated tool for SolidWorks Professionals

            LinkedIn SolidWorks API Education Group

              • Re: Is there a way to get temp axis of cylindrical face?
                Tore Magne Bjornodegard

                Thanks for answers!

                 

                What i wanted to do is to make a macro that could convert the face selection to temp axis selection, it is time consuming to select the right axis when you have a lot of them on top of each other....

                I see that this will hard to do if even possible...

                  • Re: Is there a way to get temp axis of cylindrical face?
                    Dave Branco

                    Hey not sure if you are still looking for an answer to this question but I was and i have a solution for you.  It's true that you need to select the axis by the coordinate (i believe) but that is easy enough to find.  This macro will select the temporary axis of the selected face.  note that temporary axes need to be visible in order to select them.  I dont like all the clutter, so that macro shows them and hides them after it is already selected:

                     

                     

                    '----------------------------------

                     

                     

                    '

                     

                     

                    ' Preconditions: Model document is open and a cylindrical surface is selected.

                     

                     

                    '

                     

                     

                    ' Postconditions: The temporary axis of that surface is selected

                     

                     

                    '

                     

                     

                    '----------------------------------

                     

                     

                    Option Explicit

                     

                     

                    Sub main()

                     

                     

                        Dim swApp                   As SldWorks.SldWorks

                     

                     

                        Dim swModel                 As SldWorks.ModelDoc2

                     

                     

                        Dim swSelMgr                As SldWorks.SelectionMgr

                     

                     

                        Dim swFace                  As SldWorks.Face2

                     

                     

                        Dim swSurf                  As SldWorks.Surface

                     

                     

                        Dim vCylinder               As Variant

                     

                     

                        Dim i                       As Long

                     

                     

                        Dim bRet                    As Boolean

                     

                     

                       

                        'Set swApp = CreateObject("SldWorks.Application")

                        Set swApp = Application.SldWorks

                        Set swModel = swApp.ActiveDoc

                     

                     

                        Set swSelMgr = swModel.SelectionManager

                     

                     

                        Set swFace = swSelMgr.GetSelectedObject5(1)

                     

                     

                        Set swSurf = swFace.GetSurface

                     

                     

                       

                        If swSurf.IsCylinder Then

                     

                     

                            vCylinder = swSurf.CylinderParams

                     

                     

                           

                            Debug.Print "origin         = (" & vCylinder(0) * 1000# & ", " & vCylinder(1) * 1000# & ", " & vCylinder(2) * 1000# & ") mm"

                     

                     

                            Debug.Print "axis           = (" & vCylinder(3) & ", " & vCylinder(4) & ", " & vCylinder(5) & ")"

                     

                     

                            Debug.Print "radius         = " & vCylinder(6) * 1000# & " mm"

                            bRet = swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayTemporaryAxes, True)

                           

                            bRet = swModel.Extension.SelectByID2("", "AXIS", vCylinder(0), vCylinder(1), vCylinder(2), False, 0, Nothing, 0)

                           

                            bRet = swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayTemporaryAxes, False)

                        End If

                     

                     

                    End Sub

                    • Re: Is there a way to get temp axis of cylindrical face?
                      Dave Branco

                      I took it one step further in case you would like to select the axis within an assembly:

                       

                       

                      Sub test()

                       

                          Dim swApp                   As SldWorks.SldWorks

                       

                       

                          Dim swModel                 As SldWorks.ModelDoc2

                       

                       

                          Dim swselmgr                As SldWorks.SelectionMgr

                       

                       

                          Dim swFace                  As SldWorks.Face2

                       

                       

                          Dim swSurf                  As SldWorks.Surface

                       

                       

                          Dim vCylinder               As Variant

                       

                       

                          Dim i                       As Long

                       

                       

                          Dim bret                    As Boolean

                       

                       

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc

                          Set swselmgr = swModel.SelectionManager

                       

                       

                          Set swFace = swselmgr.GetSelectedObject5(1)

                          Dim swXform As MathTransform

                          Dim swmathutil As MathUtility

                          Dim swcomp  As Component2

                          If swModel.GetType = swDocASSEMBLY Then

                              'need a transform

                              Set swmathutil = swApp.GetMathUtility

                              Set swcomp = swselmgr.GetSelectedObjectsComponent(1)

                              Set swXform = swcomp.Transform2

                           End If

                         

                          Set swSurf = swFace.GetSurface

                          Dim myaxis() As Double

                         

                          ReDim myaxis(1 To 3)

                         

                         

                          If swSurf.IsCylinder Then

                       

                       

                              vCylinder = swSurf.CylinderParams

                       

                       

                             

                              Debug.Print "origin         = (" & vCylinder(0) * 1000# & ", " & vCylinder(1) * 1000# & ", " & vCylinder(2) * 1000# & ") mm"

                       

                       

                              Debug.Print "axis           = (" & vCylinder(3) & ", " & vCylinder(4) & ", " & vCylinder(5) & ")"

                       

                       

                              Debug.Print "radius         = " & vCylinder(6) * 1000# & " mm"

                       

                       

                              myaxis(1) = vCylinder(0)

                              myaxis(2) = vCylinder(1)

                              myaxis(3) = vCylinder(2)

                             

                              If swModel.GetType = swDocASSEMBLY Then

                                  'transform the axis origin to assembly space         

                                  Dim mypoint As MathPoint

                                  Set mypoint = swmathutil.CreatePoint(myaxis)

                                  Set mypoint = mypoint.MultiplyTransform(swXform)

                                  myaxis(1) = mypoint.ArrayData(0)

                                  myaxis(2) = mypoint.ArrayData(1)

                                  myaxis(3) = mypoint.ArrayData(2)

                              End If

                                'display temp axes so you can select them

                              bret = swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayTemporaryAxes, True)

                             bret = swModel.Extension.SelectByID2("", "AXIS", myaxis(1), myaxis(2), myaxis(3), False, 0, Nothing, 0)

                             Debug.Assert bret

                              'hide the temporary axes

                             bret = swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayTemporaryAxes, False)

                       

                          End If

                       

                       

                      End Sub