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

How to retrieve all dbText entities with a given text value

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
624 Views, 1 Reply

How to retrieve all dbText entities with a given text value

I let user select a dbText, and I would like to retrieve all dbText objects whose content is equal to the selected on.

 

Thanks,

1 REPLY 1
Message 2 of 2
SENL1362
in reply to: Anonymous

Suppose this is part of youre drawing with TEXT(DBText not MTEXT) entities,

Screenshot_1.png

Then this code fragment:

 

string textPattern = ".*World";
using (Transaction tr = db.TransactionManager.StartTransaction())
{
 BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
 BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

 var matchingText = ms.Cast<ObjectId>()
 .Where(id => id.ObjectClass.DxfName.ToUpper() == "TEXT")
 .Select(id => (DBText)tr.GetObject(id, OpenMode.ForRead))
 .Where(txt => Regex.IsMatch(txt.TextString,textPattern,RegexOptions.IgnoreCase))
 .ToList();

 matchingText.ForEach(txt => ed.WriteMessage("\n Matching Text== '{0}'", txt.TextString));
 tr.Commit();
}

 

 

 

 

will find:

Matching Text== 'Hello World!'

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost