.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filtering - Dynamic Blocks

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
1552 Views, 4 Replies

Filtering - Dynamic Blocks


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
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous


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
Message 3 of 5
Anonymous
in reply to: Anonymous

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

 

Message 4 of 5
Hallex
in reply to: Anonymous

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
Message 5 of 5
Anonymous
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...

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report