Distinguished Contributor
Posts: 172
Registered: ‎11-19-2003
Message 1 of 5 (357 Views)

Filtering - Dynamic Blocks

357 Views, 4 Replies
05-23-2006 02:57 AM

I tried to filter Blocks with this


TypedValue[] filList = {new TypedValue(-4, "<AND"),

new TypedValue((int)DxfCode.Start, "INSERT"),

new TypedValue((int)DxfCode.BlockName, "GTP*"),

new TypedValue(-4, "AND>")};

This works without any problems with nomal Blockreferences, but if there
are Dynamic Blocks and you change a parameter the filter does not work anymore.
Is it possible to filter for the effective name?

Roland Feletic
Ingenieurbuero A.
Pauser Ges.m.b.H.



hp workstation xw4200, 3GB
AutoCAD 2007, 3DSMax 8.0 SP 2
Distinguished Contributor
Posts: 172
Registered: ‎11-19-2003
Message 2 of 5 (357 Views)

Re: Filtering - Dynamic Blocks

05-23-2006 08:23 AM in reply to: RolandF

Now i tried this code, didn't work,


TypedValue[] filList = {new TypedValue(-4, "<AND"),

new TypedValue((int)DxfCode.ExtendedDataRegAppName, "AcDbDynamicBlockTrueName"),

new TypedValue((int)DxfCode.ExtendedDataAsciiString, "GTP*"),

new TypedValue(-4, "AND>")};

Roland Feletic
Ingenieurbuero A. Pauser Ges.m.b.H.



hp workstation xw4200, 3GB
quadro fx1400
AutoCAD 2007, 3DSMax 8.0 SP
Posts: 23
Registered: ‎10-14-2008
Message 3 of 5 (186 Views)

Re: Filtering - Dynamic Blocks

10-02-2012 04:52 AM in reply to: RolandF

Did you ever find an answer to this. I am having same problem and I am stuck


Troy Moore
Civil3D 2014
Windows 7 Pro, 64 bit
Intel Xeon E31225 @ 3.40Ghz
*Expert Elite*
Posts: 1,556
Registered: ‎10-08-2008
Message 4 of 5 (180 Views)

Re: Filtering - Dynamic Blocks

10-02-2012 05:27 AM in reply to: troymoore7595

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;
                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)

                        string.Format("Selected: {0} blocks named \"{1}\"",ids.Count,blkname));


Tested on A2010,2009



Active Member
Posts: 7
Registered: ‎09-22-2012
Message 5 of 5 (173 Views)

Re: Filtering - Dynamic Blocks

10-02-2012 06:05 AM in reply to: Hallex

Kean walmsley recently wrote an article on this topic, implementing both XData and the BlockTableRecord's list of anonymous references.





You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community