.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Set screen center to my point
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
At this time I tried to set screen center. I have some object and I want to set screen position to this object.
What I did:
AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServi
using (Transaction tr = doc.Database.TransactionManager.StartTransaction()
{
Entity en = (Entity)tr.GetObject(objectId, OpenMode.ForRead); // get my obj by Id
Extents3d ext = en.GeometricExtents;
Point3d p_center = new Point3d( // get center
(ext.MinPoint.X + ext.MaxPoint.X) / 2,
(ext.MinPoint.Y + ext.MaxPoint.Y) / 2,
(ext.MinPoint.Z + ext.MaxPoint.Z) / 2
);
// set center point of current view
ed.UpdateTiledViewportsInDatabase();
ViewportTableRecord viewportTableRec = tr.GetObject(ed.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;
viewportTableRec.CenterPoint = new Point2d(p_center.X, p_center.Y);
ed.UpdateTiledViewportsFromDatabase();
// Ok!
tr.Commit();
}
// set object as selected - it works
doc.Editor.SetImpliedSelection(new ObjectId[] { objectId });
I see that SetImpliedSelection works fine (as I see current object) but screen center is moved to unknown point.
How I can set screen center to my point?
Thanks,
Pavel.
Solved! Go to Solution.
Re: Set screen center to my point
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Something like this will do your work
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
Point3d p_center = new Point3d( // get center
(ext.MinPoint.X + ext.MaxPoint.X) / 2,
(ext.MinPoint.Y + ext.MaxPoint.Y) / 2,
(ext.MinPoint.Z + ext.MaxPoint.Z) / 2
).TransformBy(ucs);
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Set screen center to my point
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
No changes ![]()
Re: Set screen center to my point
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I had created new schema and this code works, but still doesn't work in old, stored file.
It's very strange.
It seems in old file I have very specific view but I have no idea what it is.
Thanks,
Pavel.
Re: Set screen center to my point
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
You need to transform the Extents3d from World Coordinates System to the viewport Display Coordinates System before calculating the center point.
private void SetViewCenterToObject(ObjectId id)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
using (Transaction tr = doc.TransactionManager.StartTransaction())
using (ViewTableRecord view = ed.GetCurrentView())
{
Matrix3d DCS2WCS =
Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
Matrix3d.Displacement(view.Target - Point3d.Origin) *
Matrix3d.PlaneToWorld(view.ViewDirection);
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
Extents3d ext = ent.GeometricExtents;
ext.TransformBy(DCS2WCS.Inverse());
view.CenterPoint = new Point2d(
(ext.MaxPoint.X + ext.MinPoint.X) / 2.0,
(ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
ed.SetCurrentView(view);
tr.Commit();
}
}
Re: Set screen center to my point
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Wow! It works! Thanks, gile!
Pavel.
