Block reference to inserted block #340
-
Wonderful code, truly.. Glad I found this. Question please. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
From what you wrote in your post you are working with dynamic blocks, and what you describe this is its normal behavior. Although netDxf can import them you will loose all its dynamic parameters, but you can still retrieve the information you seek. It is stored in the extended data information of the block record under an application registry called "AcDbBlockRepBTag", you can do something like this: // netDxf can read dynamic blocks but you will loose the information related with the parameters, actions and constrains
// for every insert AutoCad creates a new block definition with the name *U#, where # is a positive integer
// except in the case where the dynamic block parameters are not modified, in this case the original block will be used instead
DxfDocument drawing = DxfDocument.Load("YourDrawing.dxf");
// a dynamic block reference
Insert insert = drawing.Entities.Inserts.ElementAt(0);
// block referenced by the Insert
Block block = insert.Block;
// to access the original dynamic block we need to get first the extended data associated with the BlockRecord,
// the application registry for this extended data always has the name "AcDbBlockRepBTag"
// only the modified dynamic blocks "U#" store this handle, the original block stores other things of unknown use
XData xdata = block.Record.XData["AcDbBlockRepBTag"];
string handle = string.Empty;
// the original dynamic block record handle is stored in the extended data,
// use with care this is undocumented stuff, it appears to only store this value.
foreach (XDataRecord data in xdata.XDataRecord)
{
if (data.Code == XDataCode.DatabaseHandle)
{
handle = (string) data.Value;
}
}
// now we can get the original dynamic block record
BlockRecord originalDynamicBlockRecord = (BlockRecord) drawing.GetObjectByHandle(handle);
// this is the name of the original block
string dynamicBlockName = originalDynamicBlockRecord.Name;
// if we need the original block, we can get it from the list of blocks since we know its name
Block originalBlock = drawing.Blocks[dynamicBlockName]; You can also make a search for "dynamic blocks" in this repository, there are other post talking about them. One additional note: the blocks generated by an array also use the same "U#" nomenclature but only the ones belonging to dynamic blocks will store that extended data information. |
Beta Was this translation helpful? Give feedback.
From what you wrote in your post you are working with dynamic blocks, and what you describe this is its normal behavior. Although netDxf can import them you will loose all its dynamic parameters, but you can still retrieve the information you seek. It is stored in the extended data information of the block record under an application registry called "AcDbBlockRepBTag", you can do something like this: