Im trying to draw some objects using vb.net but they get drawn away from their coordinates since the viewport in the drawing is not using the WorldCS. So what i will do is first set the UCS in the viewport to the WorldCS, then draw the objects, then set it back to the previous UCS.
But i cant find how to get the current CS in the viewport.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
Typically, when drawing by code, we do not need to set UCS.
You cant translate coordinates from UCS to WCS using the TransformBy() method with Editor.CurrentUserCoordinateSystem property which returns the transformation matrix from UCS to WCS (for the inverse tansformation, use Editor.CurrentUserCoordinateSystem.Inverse()).
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim pointResult As PromptPointResult = ed.GetPoint("\nPick a point: ") Dim ucsPoint As Point3d = pointResult.Value Dim wcsPoint As Point3d = ucsPoint.TransformBy(ed.CurrentUserCoordinateSystem)
If you absolutely want to change the current coordinate system, you can do:
' save current ucs Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem ' set the CS to World ed.CurrentUserCoordinateSystem = Matrix3d.Identity ' do yor stuff... ' restore the previous ucs ed.CurrentUserCoordinateSystem =ucs
@jwe03 wrote:Hi @_gile, thank you for your reply.
I have tried this method, but its really extra work to add TransformBy every time.
Don't you agree that it would less work to follow the procedure:
1 - change to WCS
2 - Do the required changes.
3 - change to previous UCS
?
You shouldn't have to do this unless you are scripting AutoCAD commands via the Command() method and want to supply many world coordinates rather than transform each to the current UCS. If you are getting input from your user, you are not supposed to change their UCS while getting the input, because they may be depending on it.
Can't find what you're looking for? Ask the community or share your knowledge.