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

Find Block in Xref

3 REPLIES 3
Reply
Message 1 of 4
Jbrauer
992 Views, 3 Replies

Find Block in Xref

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.

3 REPLIES 3
Message 2 of 4
Alfred.NESWADBA
in reply to: Jbrauer

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4
Jbrauer
in reply to: Alfred.NESWADBA

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 ??

 

I have drawings with hundreds of blocke inside several Xrefs, and I need to find one specificblock inside each xref - inside the block I nead to read some attribute values. 
It takes awful long to run through all blocke in each xref to find the right block. 
Via the XrefDatabase I  can find out if blocken in block table, but not if it is inserted in the drawing

 
 
 



 

 

Message 4 of 4
Artvegas
in reply to: Jbrauer

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-debugger-mgddbg-app-for-autocad-20122013.html

 

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

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