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#
Solved! Go to Solution.
Solved by cadMeUp. Go to Solution.
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.
Also, you may give a look at this example from Kean's blog:
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; }