Valued Contributor
Posts: 59
Registered: ‎11-05-2013
Message 1 of 2 (178 Views)
Accepted Solution

Some mistake when change UCS

178 Views, 1 Replies
12-16-2013 06:37 PM

Hi All, 

I have one question in forum about UCS. My topic still related to UCS. This is, When i changed UCS the first time, its ok. But When i changed it second time or more. My ucs have some mistake. Hope everybody can understand my question. Thanks very much. And this is my code.



 <CommandMethod("ROTZ")> _
Public Sub NewUCS()
Dim result As PromptPointResult
Dim mat As Matrix3d
''get the current document and database
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
''inform user click point
Dim ptpoint As New PromptPointOptions("")
''set current user coordinate system
ptpoint.Message = vbLf & "Choose start Point:"
result = ed.GetPoint(ptpoint)
If (result.Status <> PromptStatus.OK) Then
End If
Dim pt1 As Point3d = result.Value
ptpoint.Message = vbLf & "Choose end Point"
result = ed.GetPoint(ptpoint)
Dim pt2 As Point3d = result.Value
Dim zAxis As Vector3d = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis
Dim xAxis As Vector3d = pt1.GetVectorTo(pt2)
Dim yAxis As Vector3d = xAxis.GetPerpendicularVector
mat = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, pt1, xAxis, yAxis, zAxis)
ed.CurrentUserCoordinateSystem = mat
Catch ex As System.Exception
End Try
End Sub


*Expert Elite*
Posts: 2,077
Registered: ‎04-29-2006
Message 2 of 2 (157 Views)

Re : Some mistake when change UCS

12-17-2013 12:20 AM in reply to: hoathuongphuoc



Points returnd by Editor.GetPoint() are defined in the current system coordinates. you have to transform them to WCS before using them to build a new UCS.


Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem
pt1 = pt1.TransformBy(ucs)
pt2 = pt2.TransformBy(ucs)
Dim zAxis As Vector3d = ucs.CoordinateSystem3d.Zaxis
Dim xAxis As Vector3d = pt1.GetVectorTo(pt2)
Dim yAxis As Vector3d = zAxis.CrossProduct(xAxis)
ed.CurrentUserCoordinateSystem = Matrix3d.AlignCoordinateSystem( _
    Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, _
    pt1, xAxis, yAxis, zAxis)


Gilles Chanteau

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community