.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Some mistake when change UCS

1 REPLY 1
SOLVED
Reply
Message 1 of 2
hoathuongphuoc
536 Views, 1 Reply

Some mistake when change UCS

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

 

1 REPLY 1
Message 2 of 2
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost