Find position of a nested block from a BlockReference

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I've been struggling to do this for a few days now, im hoping someone can shed some light.
Here's what i'm trying to accomplish:
Using C# .NET, I have two blocks that I want to insert chained next to each other. A specific point on end of the first one touches a point on the start of the second one. The blocks happen to be dynamic blocks.
Here's how i'm trying to do it:
I have put a nested block (circle) in the first block that I have named "PINK_DOT". You can see the circle in the screenshot below. I think I can insert the first block, then get the modelspace position of the nested (PINK_DOT) block from the BlockReference. I can then use the modelspace position of the PINK_DOT block as the insertion point for my second block.
My procedure is as follows:
1) I insert the first block using it's BlockName, and then set the blocks visibility state, to the one i want. This gives me the BlockReference for the insertion.
2) I would like to find the position of the PINK_DOT block that I have nested in the BlockReference that was just inserted.
3) I will then use that position as the insertion point for the second block.
Here is the code im using to get the Point3d of the block named "PINK_DOT". The first block has already been inserted into modelspace. I start by getting the BlockReference from the first block from the ObjectId
var blockReference = m_trans.GetObject(objectId, mode, false, true) as BlockReference;
if (blockReference.Visible == true) { BlockTableRecord blockTableRecord = m_trans.GetObject(blockReference.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; foreach (ObjectId oid in blockTableRecord) { DBObject brDbo = m_trans.GetObject(oid, OpenMode.ForRead, false, true); if (brDbo is BlockReference && ((Autodesk.AutoCAD.DatabaseServices.BlockReference)brDbo).Visible == true) { BlockReference possibleInsertionPoint = (BlockReference)brDbo; if (possibleInsertionPoint.Name == "PINK_DOT") { return possibleInsertionPoint.Position; } } } }
Problems:
1. The above code ends up returning {0,0,0} for the modelspace position which isn't correct.
2. I want to insert the first block multiple times and be able to get the modelspaceposition of it's PINK_DOT for each of them. Im concerned about being able to keep track of which BlockReference, I'm grabbing the PINK_DOT for. I could do this easily if I could get the Point3d for the PINK_DOT given a BlockReference.
Summary:
In Computer Science terminology im trying to write an implementation for this method (where the Objectid is a reference to a DynamicBlock that has been inserted):
Point3d GetPositionOfNestedBlock(ObjectId objectId, string nestedBlockName)
{
//Please help implement me :)
}