// Gets the display name of an object type. public static string GetDisplayName(RXClass classObject) { using (RXObject rawObject = classObject.Create()) { if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(AecDbObject)))) { AecDbObject dbObject = (AecDbObject)rawObject; return(dbObject.DisplayName); } else if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(AecEntity)))) { AecEntity entity = (AecEntity)rawObject; return(entity.DisplayName); } else if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(DBObject)))) { string dxfName = classObject.DxfName; if (dxfName == null) { return(classObject.Name); } else { return(dxfName); } } } throw new ArgumentException("wrong class type"); }
void RecursiveReferencesToOfSeletedObject() { // // Transaction processing // Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = Application.DocumentManager.MdiActiveDocument.Database; TransactionManager tm = db.TransactionManager; Transaction trans = tm.StartTransaction(); try { PromptEntityOptions entopts = new PromptEntityOptions("Select an Aec Entity "); entopts.SetRejectMessage("Must select an Aec Entity, please!"); entopts.AddAllowedClass(typeof(Autodesk.Aec.DatabaseServices.Entity), false); PromptEntityResult ent = null; try { ent = ed.GetEntity(entopts); } catch { ed.WriteMessage("You did not select a valid entity"); return; } if (ent.Status == PromptStatus.OK) { ObjectId entId = ent.ObjectId; Autodesk.Aec.DatabaseServices.Entity aecent = tm.GetObject(entId, OpenMode.ForRead, false) as Autodesk.Aec.DatabaseServices.Entity; DBObjectRelationshipManager mgr = new DBObjectRelationshipManager(); DBObjectRelationshipCollection refsTo = mgr.GetReferencesToThisObjectRecursive(aecent, 0, false); ed.WriteMessage("\n\n"); foreach (DBObjectRelationship relTo in refsTo) { ed.WriteMessage("Ent ID = " + entId.ToString() + " " + entId.ObjectClass.Name.ToString() + " is referenced recursively by: " + relTo.Id.ToString() + "(" + relTo.Id.ObjectClass.Name + ")" + ", whose relationship type is " + relTo.RelationshipType.ToString() + "\n"); } } trans.Commit(); } catch (System.Exception e) { trans.Abort(); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message); } finally { trans.Dispose(); } }