Community
TypedValue[] filList = {new TypedValue(-4, "<AND"), new TypedValue((int)DxfCode.Start, "INSERT"), new TypedValue((int)DxfCode.BlockName, "GTP*"), new TypedValue(-4, "AND>")};
TypedValue[] filList = {new TypedValue(-4, "<AND"), new TypedValue((int)DxfCode.ExtendedDataRegAppName, "AcDbDynamicBlockTrueName"), new TypedValue((int)DxfCode.ExtendedDataAsciiString, "GTP*"), new TypedValue(-4, "AND>")};
Try this one
static public string EffectiveName(Transaction tr, BlockReference bref) { BlockTableRecord btr = null; if ((bref.IsDynamicBlock) | (bref.Name.StartsWith("*U", StringComparison.InvariantCultureIgnoreCase))) { btr = tr.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord; } else { btr = tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; } return btr.Name; } [CommandMethod("dyb", CommandFlags.Modal)] public static void SelectDynamicBlocks() { Document dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; Database db = dwg.Database; ObjectIdCollection ids = new ObjectIdCollection(); string blkname = "wall"; using (Transaction tr = db.TransactionManager.StartTransaction()) { TypedValue[] tvs = new TypedValue[] {new TypedValue(0, "insert"), new TypedValue(2, "*,`*U*,wall") }; SelectionFilter filter = new SelectionFilter(tvs); PromptSelectionOptions pso = new PromptSelectionOptions(); pso.MessageForRemoval = "\nSelect blocks only"; pso.MessageForAdding = "\nSelect dynamic blocks: "; pso.RejectObjectsOnLockedLayers = true; pso.AllowSubSelections = false; pso.AllowDuplicates = false; PromptSelectionResult result = ed.GetSelection(pso, filter); if (result.Status == PromptStatus.OK) { ObjectId[] objs = result.Value.GetObjectIds(); ed.WriteMessage("\n{0}", objs.Length.ToString()); foreach (SelectedObject sobj in result.Value) { Entity ent = (Entity)tr.GetObject(sobj.ObjectId, OpenMode.ForRead, false); BlockReference bref = ent as BlockReference; if (bref != null) { if (EffectiveName(tr, bref) == blkname) { ids.Add(sobj.ObjectId); } } } Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog( string.Format("Selected: {0} blocks named \"{1}\"",ids.Count,blkname)); } tr.Commit(); } }
Tested on A2010,2009
~'J'~
Kean walmsley recently wrote an article on this topic, implementing both XData and the BlockTableRecord's list of anonymous references.
Can't find what you're looking for? Ask the community or share your knowledge.