Active Contributor
31 Posts
0 Kudos
Registered: ‎09-11-2009
Post 1 of 4

change block refference attribute. Dont want to change the block itself.

341 Views, 3 Replies
03-07-2010 09:21 PM
I have an issue regarding nesed entity.

Thanks in advace.
Herewith I explained the issue that I am facing now. Please reply as fast as possible.

I have a nested entity block reference. In this entity I have three blocks. if I change any of the block reference attribute defenision in the nested block reference then it is changing the original block itself.
Actually I am getting the handle of the selected block reference in the nested Entity. and change the attribute refference later. but it is making change in the block itself and other block reference too.

Here is my code:
static public void CONTACTS()

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
string contactName = string.Empty;//to hold contact name, from xdata
System.Collections.ArrayList arrXdata = new ArrayList();//array list to save array list
PromptNestedEntityResult rs = ed.GetNestedEntity("\nSelect the contact to move:");
string contactPath = GetSymbolPath();//get the symbol path
contactPath += "Contacts//IS";//set contact path
Handle parentContactID =new Handle();
string parentContactLayerName = string.Empty;//get the parent contact layer name
string parentContactPosition = string.Empty;//get the parent contact position
string parentDesignation = string.Empty;//get the parent designation
string currentLayerName =string.Empty;
System.Collections.Generic.Dictionary dictAttributes = new System.Collections.Generic.Dictionary();
if (rs.Status == PromptStatus.OK)
ObjectId[] objIds = rs.GetContainers();
//Get the selected nested entity layer name and designation of the nested entity//////////////////////////////////////////////
foreach (ObjectId dd in objIds)
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
AttributeReference attRefParent=null;
Entity en = (Entity)tr.GetObject(dd, OpenMode.ForRead);
if (en is BlockReference)
BlockReference rf = en as BlockReference;
Handle hn=rf.Handle; ///////////////????????? I am getting the handle here



Edited by: jithin.dcs on Mar 8, 2010 10:53 AM Edited by: jithin.dcs on Mar 8, 2010 10:54 AM
*Expert Elite*
1,286 Posts
37 Kudos
Registered: ‎06-21-2004
Post 2 of 4

Re: change block refference attribute. Dont want to change the block itself.

03-07-2010 10:38 PM in reply to: jithin.dcs
This was mentioned here

(defun botsbuildbots() (botsbuildbots))
Active Contributor
31 Posts
0 Kudos
Registered: ‎09-11-2009
Post 3 of 4

Re: change block refference attribute. Dont want to change the block itself.

03-08-2010 12:22 AM in reply to: jithin.dcs
I checked the link you have given. its not clear my issue.

Im my code I am reading the selected block reference handle as follows.

ObjectId id = (ObjectId)revIds.GetValue(1);// from nested entity collections
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
// ... and highlight the nested entity
if (ent is BlockReference)
BlockReference br = ent as BlockReference;
contactName = br.Name;
parentContactID = br.Handle; // getting the handle here

Once I got the handle I will update the sabe block reference as follows

ObjectId getParentID = db.GetObjectId(false,handle, 0);
Entity entParent = (Entity)tr.GetObject(getParentID, OpenMode.ForWrite, false);// Use it to open the current object!
if (entParent is BlockReference)
BlockReference brParent = entParent as BlockReference;
foreach (ObjectId id in brParent.AttributeCollection)
Entity ent2 = (Entity)tr.GetObject(id, OpenMode.ForRead, false);
attRef = (AttributeReference)tr.GetObject(id, OpenMode.ForWrite, false);
if (attRef.Tag == "LOCN")
attRef.TextString = "[" + subContactLayer + ":" + subContactPosition + "]";

But it is updating the original bokc attribute also...........................
please replay.
5 Posts
0 Kudos
Registered: ‎06-04-2012
Post 4 of 4

Re: getting entity by giving the handle name in autocad,net

06-07-2012 04:52 AM in reply to: jithin.dcs

my requirement is i am giving the handle name in the textbox.

    with that handle name i want to zoom tha that object when i pree button


please give logic

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post