Get the Associated Leader from BlockReference

Get the Associated Leader from BlockReference

Gepaha
Collaborator Collaborator
924 Views
5 Replies
Message 1 of 6

Get the Associated Leader from BlockReference

Gepaha
Collaborator
Collaborator

This may seem like a stupid question but I found no solution in the research I did.
I can associate a Block with a leader like:

 

 

var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
   var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
   var blkId = bt["Circle"];
   var blkref = new BlockReference(new Point3d(0.5, 4, 0), blkId);
   var ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
   ms.AppendEntity(blkref);
   tr.AddNewlyCreatedDBObject(blkref, true);
   var ldr = new Leader();
   ldr.AppendVertex(new Point3d(0, 0, 0));
   ldr.AppendVertex(new Point3d(0, 4, 0));
   ms.AppendEntity(ldr);
   tr.AddNewlyCreatedDBObject(ldr, true);
   // associate the block to the leader
   ldr.Annotation = blkref.ObjectId;
   tr.Commit()
}

 

 

As I get the opposite? I have the block reference and want the leader associated with it.

Thanks in advance.

 

 

0 Likes
Accepted solutions (1)
925 Views
5 Replies
Replies (5)
Message 2 of 6

ActivistInvestor
Mentor
Mentor
Accepted solution

Since block references do not store information about objects that reference them the only way you can do that is by searching all leaders in the same space for the one whose Annotation property contains the ObjectId of the block reference.

0 Likes
Message 3 of 6

Gepaha
Collaborator
Collaborator

Thank you very much for that answer.
I thought there might be a hidden method or property that I didn't know about.

0 Likes
Message 4 of 6

Gepaha
Collaborator
Collaborator

Since using the .NET API it is not possible to get Leader associated with BlockReference, I am looking for alternatives.

It looks like the Leader is stored with a soft pointer in some dictionary.

How is it possible to obtain the Leader ObjectId associated with the BlockReference directly, without having to go through the entire database?

BlockRefrence with Leader AssociatedBlockRefrence with Leader Associated

If anyone can help I am grateful.

0 Likes
Message 5 of 6

Gepaha
Collaborator
Collaborator

Someone to help?

0 Likes
Message 6 of 6

Gepaha
Collaborator
Collaborator

I have tried several ways to get the Leader associated with the BlockReference and I have not been successful.

I'm trying to avoid runs through the entire database.

Somewhere the block stores the associated Leader information.

Can anyone help?

0 Likes