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

Get current UCS using vb.net

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jwe03
3044 Views, 5 Replies

Get current UCS using vb.net

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.

5 REPLIES 5
Message 2 of 6
_gile
in reply to: jwe03

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
in reply to: _gile

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

 

?

Message 4 of 6
_gile
in reply to: jwe03

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
in reply to: _gile

@_gile, Thank you.

This worked great !

Message 6 of 6
ActivistInvestor
in reply to: jwe03


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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report