Get Point in UserCoordinateSystem

Get Point in UserCoordinateSystem

Anonymous
Not applicable
641 Views
2 Replies
Message 1 of 3

Get Point in UserCoordinateSystem

Anonymous
Not applicable

I have a Problem and need help.

 

I want to get the coordinates of an workpoint in a UserCoordinateSystem (UCS).

 

GetPointInUCS.png

 

I thought i can get it with the function „TransformBy“

point.TransformBy(UCS.Transformation)

 

But for the example in the screenshot i get the result: X: 0, Y: 2, Z: 0 … but it should be X: 0, Y: 0, Z: 0

 

Here a example-Code:

 

Public Sub test()

 

    Dim p As PartDocument

    Dim oTG As TransientGeometry

    Dim u As UserCoordinateSystem

    Dim wp As WorkPoint

    Dim point As point

    Dim v As Vector

   

    Set p = ThisDocument

    Set oTG = ThisApplication.TransientGeometry

    Set u = p.ComponentDefinition.UserCoordinateSystems.Item(1)

   

    For Each wp In p.ComponentDefinition.WorkPoints

   

        Debug.Print wp.Name

       

        If (InStr(1, wp.Name, "Point", vbTextCompare)) Then

       

            Debug.Print "Orig x: " & wp.point.X & ", y: " & wp.point.Y & ", z: " & wp.point.Z

            Set point = wp.point.Copy()

            Call point.TransformBy(u.Transformation)

            Debug.Print "Transform x: " & point.X & ", y: " & point.Y & ", z: " & point.Z

       

        End If

       

    Next

 

End Sub

 

0 Likes
Accepted solutions (1)
642 Views
2 Replies
Replies (2)
Message 2 of 3

johnster100
Collaborator
Collaborator

Hi Guys,

Did you ever manage to get this to work?????????

 

If so the code would be useful to me. I'm trying to output work point coordinates to excel using ilogic.

 

thanks,

John

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

i solved my problem and because some people asked if i already have a solution i want to share it with you

 

the transformation-matrix has to be inverted before transformation

 

Private Function TransformByUserCoordinate(ByVal Point As ADSKInventor.Point) As ADSKInventor.Point

  

  Dim UCS As ADSKInventor.UserCoordinateSystem = GetUserCoordinateSystem()
  TransformByUserCoordinate = Nothing

  

  If (UCS IsNot Nothing) Then

    TransformByUserCoordinate = Point.Copy()
    Dim TransformMatrix As ADSKInventor.Matrix = UCS.Transformation
    TransformMatrix.Invert()
    TransformByUserCoordinate.TransformBy(TransformMatrix)

  End If

 

End Function