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

Strange behavior when trying to edit block reference

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
matthewvclearspaninc
401 Views, 3 Replies

Strange behavior when trying to edit block reference

My DrawMember method currently draws a rectangle, appends it to a block definition, and inserts a block reference to it.  When I try to use the Block Editor to edit the block inside of AutoCAD, however, the screen blinks and then all block references on the screen vanish.  The blocks do still exist in the Block Table (I confirmed this using the ARXDBG app), but they are gone from model space.

 

Why is this happening? My best guess is that there is a problem with the way I'm using Transactions.  I have attached my code if you would like to take a look.  The method is called from within a separate transaction.

 

-AutoCAD 2015

-.NET/C#

Tags (2)
3 REPLIES 3
Message 2 of 4

A couple of the attributes you create are being added to the block but you also need to add them to the transaction:

trans.AddNewlyCreatedDBObject(AttributeDefinition)

 

Any new entity you create need to be added to something, and also needs to be added to a transaction, if using transactions.

 

Also, typically when you add a blockref to model/paper space you need to additionally add the attributes as

AttributeReference objects from the AttributeDefinition's in the block record.

Message 3 of 4
mcicognani
in reply to: cadMeUp

Message 4 of 4
mcicognani
in reply to: mcicognani

This is a little code snippet that insert a BlockReference with attributes:

 


/// generic InsertBlock()
/// pOrg: Insertion point
/// BlockDef: Objectid of block definition in BlockTable
/// cSpace: target space (ModelSpace or PaperSpace)
/// tr: current active transaction (must be provided by caller)

public
 static ObjectId InsertBlock(Point3d pOrg, ObjectId BlockDef, BlockTableRecord cSpace, Transaction tr) {     // create a new block-reference     BlockReference br = new BlockReference(pOrg, BlockDef);     br.SetDatabaseDefaults(cSpace.Database);     cSpace.AppendEntity(br);     tr.AddNewlyCreatedDBObject(br, true);     // Copy annotative info, if present     BlockTableRecord bd = (BlockTableRecord)tr.GetObject(BlockDef, OpenMode.ForRead);     if (bd.Annotative == AnnotativeStates.True)     {         ObjectContextManager ocm = cSpace.Database.ObjectContextManager;         ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");         ObjectContexts.AddContext(br, occ.CurrentContext);     }     // copy attributes     foreach (ObjectId attId in bd)     {         Entity ent = (Entity)tr.GetObject(attId, OpenMode.ForRead);         if (ent is AttributeDefinition)         {             AttributeDefinition ad = (AttributeDefinition)ent;             AttributeReference ar = new AttributeReference();             ar.SetAttributeFromBlock(ad, br.BlockTransform);             br.AttributeCollection.AppendAttribute(ar);             tr.AddNewlyCreatedDBObject(ar, true);         }     }     return br.Id; }

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