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() Try Dim result As PromptPointResult Dim mat As Matrix3d ''get the current document and database Dim doc As Document = Application.DocumentManager.MdiActiveDocument doc.LockDocument() 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 Return 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
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
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)