Author Topic: zoom to object in xref  (Read 2150 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
zoom to object in xref
« on: June 15, 2016, 03:27:46 AM »
How would you go about selecting an entity and then open the xref and zoom to it?

Here is minimal code that seems to work for minimal testing I have done.
The code
  • Prompts for nested entity
  • Checks to see if selected entity is from different database
  • Iterates the containers from PromptNestedResult and stores handle of the last one which is in same database
  • Opens xref and sendstring with Editor.Command to zoom to object
Code - C#: [Select]
  1. public class TestClass4 : CommandClass
  2.     {
  3.  
  4.         private static Handle? hnd = null;
  5.         [CommandMethod("zoomxref")]
  6.         public void zoomxref()
  7.         {
  8.             hnd = null;
  9.             var pneo = new PromptNestedEntityOptions("\nSelect xref object");
  10.             var pner = Ed.GetNestedEntity(pneo);
  11.             if (pner.Status != PromptStatus.OK)
  12.             {
  13.                 return;
  14.             }
  15.  
  16.             var id = pner.ObjectId;
  17.             if (id.Database.UnmanagedObject == Db.UnmanagedObject)
  18.             {
  19.                 Ed.WriteLine("Select xref object");
  20.                 return;
  21.             }
  22.  
  23.             foreach (ObjectId conId in pner.GetContainers())
  24.             {
  25.                 if (conId.Database.UnmanagedObject == pner.ObjectId.Database.UnmanagedObject)
  26.                 {
  27.                     id = conId;
  28.                 }
  29.  
  30.             }
  31.  
  32.             using (Transaction trx = Doc.TransactionManager.StartTransaction())
  33.             {
  34.                 var ent = id.GetEntity();
  35.                 hnd = ent.Handle;
  36.                 trx.Commit();
  37.             }
  38.  
  39.             var doc = Application.DocumentManager.Open(pner.ObjectId.Database.Filename, false);
  40.             doc.SendStringToExecute("zoomxrefobject ", true, false, false);
  41.  
  42.         }
  43.  
  44.  
  45.         [CommandMethod("zoomxrefobject", CommandFlags.NoHistory)]
  46.         public void zoomxrefobject()
  47.         {
  48.             if (!hnd.HasValue) return;
  49.             var id = Db.GetObjectId(false, (Handle)hnd, 0);
  50.             var ss = SelectionSet.FromObjectIds(new ObjectId[] { id });
  51.             Ed.Command("_Zoom", "_Object", ss, "");
  52.         }
  53.      
  54.     }
  55.  
  56.  

BillZndl

  • Guest
Re: zoom to object in xref
« Reply #1 on: June 15, 2016, 06:40:34 AM »
The following code is what I use to zoom up to the entities comprising an AutoCAD "Group".
I must've gotten some help on how to do this, most likely from this board,
so I don't have an explanation on how it all works.
Just thought it might help...

Code - C#: [Select]
  1. private static void ZoomToPart(ObjectId[] Eids, Transaction trans, Document doc)
  2.         {                    
  3.                 Extents3d exts =
  4.                     Eids.Select(id => ((Entity)trans.GetObject(id, OpenMode.ForRead)).GeometricExtents).Aggregate(
  5.                     (e1, e2) => { e1.AddExtents(e2); return e1; });        
  6.                                                
  7.                 int CvId = Convert.ToInt32((Application.GetSystemVariable("CVPORT")));
  8.                        
  9.                 using (Manager gm = doc.GraphicsManager)
  10.                 using (View vw = gm.GetGsView(CvId, true))
  11.                 {
  12.                     vw.ZoomExtents(exts.MinPoint, exts.MaxPoint);                    
  13.                     gm.SetViewportFromView(CvId, vw, true, true, false);
  14.                 }  
  15.         }

Jeff H

  • Needs a day job
  • Posts: 6150
Re: zoom to object in xref
« Reply #2 on: June 15, 2016, 07:54:40 AM »
GetGsView was removed in 2015 I think.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: zoom to object in xref
« Reply #3 on: June 15, 2016, 08:43:20 AM »
I use a zoom method that takes an entity extents and a zoom factor to controls the amount of "zoomification" around the entity.  You have the entity id so getting its extents is not a big deal.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

BillZndl

  • Guest
Re: zoom to object in xref
« Reply #4 on: June 16, 2016, 04:47:27 PM »
amount of "zoomification".

Hmmm,
must be a technical term.  :2funny: