8 Replies Latest reply on Jun 19, 2017 12:30 PM by Amen Allah Jlili

    Api issue

    Luigi Piron

      Hy guys, i nave to take a measure by API

      When i preselect the enttity all is ok

      The 1 entity is a Plane

      The 2nd is a coordinate system

      If i create measure it give me an error

      The reason is that it doesn t take the origin of the coordinate system

      Did anybody know how to bypass this bug?

      Or Tell me whats wrong?

      Thanks in Advance

        • Re: Api issue
          Dave Bear

          Hi Luigi,

          Have you tried using the magnifying glass (Search Bar) at the top right hand corner of the screen to search for relative posts about this. I'm sure you'll find something.

           

          Dave.

          • Re: Api issue
            Amen Allah Jlili

            Hi there!

             

            I have never been able to select the coordinates system in SOLIDWORKS. It's a design flaw of the API. I might be wrong. The thing is I don't really use the IMeasure interface because the results it gives are so ultraprecise (10^(-10m) precision) - which is something you don't really need especially if you're calculating perpendicularity between edges (for example) with a tolerances values in the 10^-3mm range - I have yet to see an application that plays at the angstrom level in SOLIDWORKS.

             

            If you're selecting a plane (IRefPlane), then you're having access to the RefPlane::CornerPoints property. This gives you four IMathPoint that belongs to the plane.

             

            Next, traverse all the features to get the coordinate system. Use Feature::GetDefinition to get the data object for the coordinate system feature (ICoordinateSystemFeatureData).

             

            This object has a property called OriginEntity. It will return Entity object. You need to figure what entity type this object is in order to cast into the right type and then get the coordinate or the origin.

             

            What is left to you is some simple math.

             

            Btw, this is blazingly faster than using Measure.

             

            Cheers,
            Amen
            CADHero.com

            • Re: Api issue
              Luigi Piron

              thank you everybody,

              i notice that i'm not be done clear with my question

              i'm in a context of assembly , i'm not in a part , and i need recursively take a measure beetween coordinate system inside a part

              and planes inside other parts

                • Re: Api issue
                  Amen Allah Jlili

                  A coordinate system has a transformation matrix that you can use.

                    • Re: Api issue
                      Luigi Piron

                      hy Amen you say truu

                      but if u have a component with a secondary coordinate system named for example "pippo" the transform Matrix

                       

                      Option Explicit

                      Public Enum swUserPreferenceStringValue_e

                          swFileSaveAsCoordinateSystem = 16

                      End Enum

                      Sub main()

                          Dim swApp                   As SldWorks.SldWorks

                          Dim swModel                 As SldWorks.ModelDoc2

                          Dim swDocExt                As SldWorks.ModelDocExtension

                          Dim swSelMgr                As SldWorks.SelectionMgr

                          Dim swFeat                  As SldWorks.Feature

                          Dim swXform                 As SldWorks.MathTransform

                          Dim sAxisName               As String

                          Dim bRet                    As Boolean

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc

                          Set swDocExt = swModel.Extension

                          Set swSelMgr = swModel.SelectionManager

                          Set swFeat = swSelMgr.GetSelectedObject5(1)

                         

                          Debug.Print "File = " & swModel.GetPathName

                          Debug.Print "  Current coordinate system = " & swModel.GetUserPreferenceStringValue(swFileSaveAsCoordinateSystem)

                          Debug.Print ""

                         

                          sAxisName = swFeat.Name

                          Set swXform = swDocExt.GetCoordinateSystemTransformByName(sAxisName)

                          Debug.Print "  " & sAxisName

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

                          Debug.Print "    Rotational sub-matrix 1   = (" & swXform.ArrayData(0) & ", " & swXform.ArrayData(1) & ", " & swXform.ArrayData(2) & ")"

                          Debug.Print "    Rotational sub-matrix 2   = (" & swXform.ArrayData(3) & ", " & swXform.ArrayData(4) & ", " & swXform.ArrayData(5) & ")"

                          Debug.Print "    Rotational sub-matrix 3   = (" & swXform.ArrayData(6) & ", " & swXform.ArrayData(7) & ", " & swXform.ArrayData(8) & ")"

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

                          Debug.Print "    Scale                     = " & swXform.ArrayData(12)

                      End Sub

                      this method doesn't work

                      how can i transform the coordinate system that is inside a component at the level of assembly ??

                  • Re: Api issue
                    Luigi Piron

                    Hy Amen , i need to verify the orientation of the secondary Coordinate system of the component in the assembly space , in order to verify if ,,,,,for example ....the z axis of the secondary Cs is concord or in opposite direction rispect the global Cs of the assembly.do you think is it the right method ??

                      • Re: Api issue
                        Amen Allah Jlili

                        I'm not sure I fully understand you Luigi. You can still apply the transform matrix on the (0,0,1) zee vector to get its orientation with the regards to the assembly's coordinate system? Actually, I think you can get the entity that make the zee axis for the coordinate system of the component, then you can transform it to the assembly to see its orientation.