.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Find Block in Xref
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Enyone know how to find a given block inside a Xref.
I can run trough the entir xref object and finde the block - by name -
but is it posibel to search direct like searching in the main drawing.
Re: Find Block in Xref
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> to search direct like searching in the main drawing
What is a "direct search" for you? ....and with "Block" you mean "BlockReferece" or "BlockTableRecord"?
Assuming you mean searching for BlockReferences by using a selectionset ==> no, because you can only find top-level-elements with a selectionset (elements placed in Modelspace or Paperspace), you can not find block-in-block with selectionsets, so you can't find block-in-xref.
What should be possible is to search for the BlockTableRecord within the database of your XRef, if you got it you can then use the function .GetBlockReferenceIds.
HTH, - alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Find Block in Xref
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
according to the thread "GetBlockReferenceIds Problems" provide GetBlockReferenceIds my not with a list of blockreferences in the drawing for a specifik block - as I have found out by trying.
Is there another smart way to get direct access to a block in an xref. like a search in the master drawing ??
Re: Find Block in Xref
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Have you had a look at how xref blocks appear in the database using the MgdDbg tool. You can get this plugin here: http://adndevblog.typepad.com/autocad/2012/04/dwg-
I looked into it and it seems that attribute block definitions come into your main drawing with names in an XrefFileName|BlockDefinitionName format. You will see that it uses a vertical pipe symbol to seperate the xref name from the block name.
So say you have an xref drawing named "XREF01.dwg" which contains a block table record with attributes named "MyAttributeBlock", then when you xref it into your main drawing you will get a block table record named "XREF01|MyAttributeBlock".
So here is my suggestion. How about you only access block table records with names that end with a pipe and your block definition name. You can then easily call GetBlockReferenceIds() to get the block references and their attribute values.
Here's what I mean in code...
[CommandMethod("XrefAttributes")]
public static void XrefAttributes()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
if (btr.Name.EndsWith("|MyAttBlock"))
{
ObjectIdCollection ids = btr.GetBlockReferenceIds(true, false);
foreach (ObjectId id in ids)
{
BlockReference br =
(BlockReference)tr.GetObject(id, OpenMode.ForRead);
AttributeCollection attc = br.AttributeCollection;
foreach (ObjectId attId in attc)
{
AttributeReference attr =
(AttributeReference)tr.GetObject(
attId,
OpenMode.ForRead
);
ed.WriteMessage("\n" + attr.TextString);
}
}
}
}
tr.Commit();
}
}
The only other option I can think of is to get the xref file names using the XrefGraph and XrefNode classes, and then load them into side databases for-read to search for your data. Try searching "side database" at the following blog for further details on this other technique: http://through-the-interface.typepad.com/
Art
