Author Topic: How to read text in xref  (Read 1650 times)

0 Members and 1 Guest are viewing this topic.

sling blade

  • Guest
How to read text in xref
« on: October 17, 2011, 07:36:00 AM »
Hi,

I have a drawing whose title block is xref in.

I need to read values from the title block but after a lot of searching I cannot find out how to do this.

Is it possible to read values from an xref drawing?


Jeff H

  • Needs a day job
  • Posts: 6151
Re: How to read text in xref
« Reply #1 on: October 17, 2011, 10:56:19 AM »
Do you mean attributes or just regular text?
If so yes and yes.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: How to read text in xref
« Reply #2 on: October 17, 2011, 12:53:38 PM »
Do you mean attributes or just regular text?
If so yes and yes.

So Jeff, I guess the answer is yes?

Sling, how are you planning on selecting the text? User picks text/attribute or just all the text/attributes associated with a paticular XREF? If you could be more specific, Im sure Jeff already has an example.
Revit 2019, AMEP 2019 64bit Win 10

Jeff H

  • Needs a day job
  • Posts: 6151
Re: How to read text in xref
« Reply #3 on: October 17, 2011, 01:15:01 PM »
By the the way that's a great name MexicanCuatard
 
That was what I was thinking if it is a Attribute you have the tag property to filter it out and if it is just Mtext or DBtext without xdata or an extensionDictionary then picking it or knowing its general location would be needed.

Jeff H

  • Needs a day job
  • Posts: 6151
Re: How to read text in xref
« Reply #4 on: October 17, 2011, 02:28:41 PM »
A xref is like a 'Insert' as it copies the entites into a BlockTableRecord
Take a look at XrefGraph Class

Here is a quick example of printing all Mtext and Dbtext to the command line of a xref that name ends with TitleBlock.dwg 
 
 
 
Code: [Select]
    [CommandMethod("XRefMtextAndDBTextValues")]
        public void XRefMtextAndDBTextValues()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction trx = db.TransactionManager.StartTransaction())
            {
                BlockTable blocktable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
               
                foreach (ObjectId objId in blocktable)
                {
                    BlockTableRecord btr = (BlockTableRecord)trx.GetObject(objId, OpenMode.ForRead);
                    if (btr.IsFromExternalReference && btr.PathName.EndsWith("TitleBlock.dwg"))
                    {
                        foreach (ObjectId id in btr)
                        {
                            if (id.ObjectClass == RXClass.GetClass(typeof(MText)))
                            {
                                MText txt = (MText)trx.GetObject(id, OpenMode.ForRead);
                                ed.WriteMessage("\n{0}", txt.Text);
                           
                            }
                            if (id.ObjectClass == RXClass.GetClass(typeof(DBText)))
                            {
                                DBText txt = (DBText)trx.GetObject(id, OpenMode.ForRead);
                                ed.WriteMessage("\n{0}", txt.TextString);
                            }
                        }
                   
                    }
                }
                trx.Commit();
            }
        }
 

sling blade

  • Guest
Re: How to read text in xref
« Reply #5 on: October 17, 2011, 04:44:44 PM »
You guys are awesome, thanks Jeff!

Sorry for the delay in getting back, its a time zone thing (just got up).

@MC I am searching for text on a particular layer. thanks for answering!

Thanks for the code Jeff, since I know the layer and the type I should be able to iterate through BlockTableRecord to find what I need.