static public void GetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForRead); AcDb.ResultBuffer rb = obj.XData; if (rb == null) { ed.WriteMessage("\nEntity does not have XData attached."); } else { int n = 0; foreach (AcDb.TypedValue tv in rb) { ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value); } rb.Dispose(); } } } }
static public void DynamicBlockProps() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: "); pso.AllowSpaces = true; _AcEd.PromptResult pr = ed.GetString(pso); if (pr.Status != _AcEd.PromptStatus.OK) { return; } _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { _AcDb.BlockReference br = null; // If a null string was entered allow entity selection if (pr.StringResult == "") { // Select a block reference _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: "); peo.SetRejectMessage("\nEntity is not a block."); peo.AddAllowedClass(typeof(_AcDb.BlockReference), false); _AcEd.PromptEntityResult per = ed.GetEntity(peo); if (per.Status != _AcEd.PromptStatus.OK) { return; } // Access the selected block reference br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference; } else { // Otherwise we look up the block by name _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable; if (!bt.Has(pr.StringResult)) { ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist."); return; } // Create a new block reference referring to the block br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]); } _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead); // Call our function to display the block properties DisplayDynBlockProperties(ed, br, btr.Name); // Committing is cheaper than aborting tr.Commit(); } }
static public void SetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForWrite); AddRegAppTableRecord("KEAN"); AcDb.ResultBuffer rb = new AcDb.ResultBuffer( new AcDb.TypedValue(1001, "KEAN"), new AcDb.TypedValue(1000, "This is a test string") ); obj.XData = rb; rb.Dispose(); tr.Commit(); } } }
static public void ZoomToEntity() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; // Get the entity to which we'll zoom _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions( "\nSelect an entity:" ); _AcEd.PromptEntityResult per = ed.GetEntity(peo); if (per.Status != _AcEd.PromptStatus.OK) { return; } // Extract its extents _AcDb.Extents3d ext; _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject( per.ObjectId, _AcDb.OpenMode.ForRead ); ext = ent.GeometricExtents; tr.Commit(); } ext.TransformBy( ed.CurrentUserCoordinateSystem.Inverse() ); // Call our helper function // [Change this to ZoomWin2 or WoomWin3 to // use different zoom techniques] ZoomWin(ed, ext.MinPoint, ext.MaxPoint); }