Get current UCS using vb.net

Get current UCS using vb.net

jwe03
Advocate Advocate
3,452 Views
5 Replies
Message 1 of 6

Get current UCS using vb.net

jwe03
Advocate
Advocate

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.

0 Likes
Accepted solutions (1)
3,453 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

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)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6

jwe03
Advocate
Advocate

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

 

?

0 Likes
Message 4 of 6

_gile
Consultant
Consultant
Accepted solution

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

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 6

jwe03
Advocate
Advocate

@_gile, Thank you.

This worked great !

0 Likes
Message 6 of 6

ActivistInvestor
Mentor
Mentor

@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.

0 Likes