Welcome
Is it possible to take CurrentUserCoordinateSystem of external Database object, like Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem?
Regards.
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.
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.
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.
Thanks Stephen,
Just out of curiosity, what if UcsSavedWithViewport = False?
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,
Thanks again.
The cross product follows the Right Hand Rule, so it would be Xdir.CrossProduct(Ydir)
Thank you StephenPreston. If 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 ) );
?