.NET

Reply
Distinguished Contributor
172 Posts
1 Kudo
Registered: ‎11-19-2003
Post 1 of 5

Filtering - Dynamic Blocks

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

I tried to filter Blocks with this
code

 

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.

size=2>http://www.pauser.at

 

hp workstation xw4200, 3GB
quadro
fx1400
AutoCAD 2007, 3DSMax 8.0 SP 2
Distinguished Contributor
172 Posts
1 Kudo
Registered: ‎11-19-2003
Post 2 of 5

Re: Filtering - Dynamic Blocks

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

Now i tried this code, didn't work,
too.

 

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.

href="http://www.pauser.at">http://www.pauser.at

 

hp workstation xw4200, 3GB
quadro fx1400
AutoCAD 2007, 3DSMax 8.0 SP
2
Contributor
24 Posts
1 Kudo
Registered: ‎10-14-2008
Post 3 of 5

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
16 GB RAM
*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 4 of 5

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;
            }
            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'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Member
7 Posts
1 Kudo
Registered: ‎09-22-2012
Post 5 of 5

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.

 

http://through-the-interface.typepad.com/through_the_interface/2012/09/creating-a-selection-filter-t...

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!