9 Replies Latest reply on Jan 25, 2013 6:45 PM by Artem Taturevych

    Select plane from Transform

    Oleg Bezyaev

      If I have an array swXform.ArrayData how can I select a plane? Ie, do the opposite - to the existing array (for example string[]), select the plane.

       

      UPD: I do not know the name of the plane in advance.

        • Re: Select plane from Transform
          Keith Rice

          Oleg,

           

          If I am understanding you correctly: for whatever reason, you already have the transform array data but now you want the plane selected that has that array data? Why not just traverse all reference planes, getting their array data, and then compare that array data to the array data you already have?

           

          Keith

          Video Tutorials for the SolidWorks API

            • Re: Select plane from Transform
              Oleg Bezyaev

              Yes, you understand me correctly. But it may have a direct way (like SelectByID), without iterate over all the planes.

                • Re: Select plane from Transform
                  Keith Rice

                  IModelDocExtension::SelectByID2 can be unreliable if you don't know the name of the feature. Anyway if that's all you want to do then here's that VBA example modified to reselect the plane afterward based purely on the array data describing translation:

                   

                  ========

                   

                  Sub main()

                      Dim swApp As SldWorks.SldWorks

                      Dim swModel As SldWorks.ModelDoc2

                      Dim swSelMgr As SldWorks.SelectionMgr

                      Dim swFeat As SldWorks.Feature

                      Dim swRefPlane As SldWorks.RefPlane

                      Dim swXform As SldWorks.MathTransform

                     

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swSelMgr = swModel.SelectionManager

                      Set swFeat = swSelMgr.GetSelectedObject5(1)

                      Set swRefPlane = swFeat.GetSpecificFeature2

                      Set swXform = swRefPlane.Transform

                   

                      Debug.Print "    Origin = (" & -1# * swXform.ArrayData(9) * 1000# & ", " & -1# * swXform.ArrayData(10) * 1000# & ", " & -1# * swXform.ArrayData(11) * 1000# & ") mm"

                      Debug.Print "    Rot1   = (" & swXform.ArrayData(0) & ", " & swXform.ArrayData(1) & ", " & swXform.ArrayData(2) & ")"

                      Debug.Print "    Rot2   = (" & swXform.ArrayData(3) & ", " & swXform.ArrayData(4) & ", " & swXform.ArrayData(5) & ")"

                      Debug.Print "    Rot3   = (" & swXform.ArrayData(6) & ", " & swXform.ArrayData(7) & ", " & swXform.ArrayData(8) & ")"

                      Debug.Print "    Trans  = (" & swXform.ArrayData(9) * 1000# & ", " & swXform.ArrayData(10) * 1000# & ", " & swXform.ArrayData(11) * 1000# & ") mm"

                      Debug.Print ""

                   

                      swModel.ClearSelection2 True

                      Stop

                      swModel.Extension.SelectByID2 Empty, "PLANE", swXform.ArrayData(9), swXform.ArrayData(10), swXform.ArrayData(11), False, 0, Nothing, 0

                  End Sub

                   

                  ========

                   

                  Keith

                  Video Tutorials for the SolidWorks API

                • Re: Select plane from Transform
                  Oleg Bezyaev

                  Workaround.

                  Thank you.

                    • Re: Select plane from Transform
                      Artem Taturevych

                      Hi Oleg,

                       

                      You may also try ModelDoc2::SelectByRay because it gives you the ability to specify the direction. Having your transform you may find the plane normal which will be your direction and the closest point to plane (the point(may be transform translation point) which is moved a bit in direction of normal).

                       

                      This may produce quite accurate results but I cannot be very confident. This method is never been in the scope of my use - just for testing and learning purposes. 

                      __________________________

                      Regards,

                      Artem Taturevych

                      Application Engineer at Intercad

                      http://intercad.com.au/

                      Tel: +61 2 9454 4444