Author Topic: Attribute tag C#  (Read 13678 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Attribute tag C#
« Reply #15 on: April 22, 2011, 08:46:28 AM »
Thanks Bobby and Thorsten for these nice examples.

Ditto that.

I was off topic with my F# code

Are you lost? This is the swamp. Off topic IS on topic. Please continue to post your most valued code + comments my friend.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

A_LOTA_NOTA

  • Guest
Re: Attribute tag C#
« Reply #16 on: April 25, 2011, 08:53:00 AM »
Thank you for all the replies. I hope to have time today to look at it all. Thanks again.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Attribute tag C#
« Reply #17 on: May 03, 2011, 06:45:44 PM »
Another way using Linq extension methods

Code: [Select]
        public ObjectId[] SelByTag(string tag)
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            tag = tag.ToUpper();
            TypedValue[] filter = new TypedValue[2] { new TypedValue(0, "INSERT"), new TypedValue(66, 1) };
            PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
            if (psr.Status != PromptStatus.OK) return null;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                return psr
                    .Value
                    .GetObjectIds()
                    .Where(brId => ((BlockReference)tr.GetObject(brId, OpenMode.ForRead))
                        .AttributeCollection
                        .Cast<ObjectId>()
                        .Any(attId => ((AttributeReference)tr.GetObject(attId, OpenMode.ForRead))
                            .Tag == tag))
                    .ToArray();
            }
        }
« Last Edit: May 04, 2011, 02:10:34 AM by gile »
Speaking English as a French Frog