.NET

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

Filtering - Dynamic Blocks

418 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
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 2 of 5 (418 Views)

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
troymoore7595
Posts: 23
Registered: ‎10-14-2008
Message 3 of 5 (247 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
16 GB RAM
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 5 (241 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;
            }
            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
vinkd
Posts: 7
Registered: ‎09-22-2012
Message 5 of 5 (234 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.

 

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

 

 

You are not logged in.

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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

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

Ask the Community