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

UCS of Database

7 REPLIES 7
Reply
Message 1 of 8
fsztuczny
663 Views, 7 Replies

UCS of Database

Welcome
Is it possible to take CurrentUserCoordinateSystem of external Database object, like Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem?

Regards.

7 REPLIES 7
Message 2 of 8
chiefbraincloud
in reply to: fsztuczny

The Methods and properties under the Editor Object are not available when the drawing is not open in the Editor.

 

There is no way (that I can find or think of) to get the UCS as a CoordinateSystem3d when opening a database with ReadDwgFile, but you can get the Database.UcsOrg as Point3d, and the Database.UcsXdir and UcsYdir as Vector3d.

Dave O.                                                                  Sig-Logos32.png
Message 3 of 8
fsztuczny
in reply to: chiefbraincloud

I noticed it too. I guess that can be put together with the transformation matrix, but how? Data on the UCS are stored in the drawing that opens through the database, so can be able to read them.

Message 4 of 8
StephenPreston
in reply to: fsztuczny

Look in the ViewportTable. There should be one or more ViewportTableRecords with the name "*Active". These represent the views created by the VIEWPORT command (or a single record if you're using the default single view).

 

ViewportTableRecord inherits a UCS property from its parent AbstractViewTableRecord. The UCS property returns a CoordinateSystem3d.

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 5 of 8

Thanks Stephen,

 

Just out of curiosity, what if UcsSavedWithViewport = False?

Dave O.                                                                  Sig-Logos32.png
Message 6 of 8

Good point. I'm not sure how many users set UCSVP to 0, but if they have, and if they save the DWG with the UCS set in the active viewport, then it looks like you would have to construct your Matrix3d for your UCS coordinate system using the Database properties (and the Matrix3d.AlignCoordinateSystem method).

 

And that brings us back to the original question of how to calculate the Z-axis, given the X- and Y- axes. You can calculate that by simply taking the cross product of the X- and Y- axes. That would be something like:

 

db.Ucsxdir.CrossProduct(db.Ucsydir)

 

(Or it could be db.Ucsydir.CrossProduct(db.Ucsxdir) - I forget. If your Z-axis is in the opposite direction to what you expected, then it means you have to take the cross product the other way around).

 

Hope that helps,

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 7 of 8

Thanks again. 

 

The cross product follows the Right Hand Rule, so it would be Xdir.CrossProduct(Ydir)

Dave O.                                                                  Sig-Logos32.png
Message 8 of 8
fsztuczny
in reply to: StephenPreston

Thank you StephenPrestonIf I want to convert from WCS to UCS, it is sufficient

_matUCS = Matrix3d.AlignCoordinateSystem( new Point3d( 0, 0, 0 ), new Vector3d( 1, 0, 0 ), new Vector3d( 0, 1, 0 ), new Vector3d( 0, 0, 1 ), db.Ucsorg, db.Ucsxdir, db.Ucsydir, db.Ucsxdir.CrossProduct( db.Ucsydir ) );

 ?

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