.NET

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

Some mistake when change UCS

191 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()
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

 

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)

 

*Expert Elite*
_gile
Posts: 2,104
Registered: ‎04-29-2006
Message 2 of 2 (170 Views)

Re : Some mistake when change UCS

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

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)

 

Gilles Chanteau
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.