Attach Object Data immediately after creating entity

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am facing a strange problem with AutoCad.Net and Map 3d API.
I am creating a block inside a transaction block, add the newly created entity to modelspace and to transaction.AddNewlyCreatedDBObject(newEntity, true).
Immediately (before commiting the transaction) I am calling a method that attaches object data to the newly created entity. I am passing the objectid of the newly created entity to AddRecord of ODTable. Everything works fine without exceptions. Finally the transaction is committed. However the newly created block reference entity does not display in the editor, but I can select using QSelect. On saving the drawing, closing and re-opening the same drawing, the newly created block references are visible and the object data is intact (with values passed into AttachODData method).
What am I missing? What should I do to make the newly created blocks visible?
Below is the snippet of code
using(Transaction acTrans = currentDb.TransactionManager.StartTransaction())
{
using (BlockReference blkRef = new BlockReference(insPointValue, reducerBlockId))
{
blkRef.SetDatabaseDefaults();
Matrix3d currentUCS = ed.CurrentUserCoordinateSystem;
CoordinateSystem3d coordSys = currentUCS.CoordinateSystem3d;
blkRef.TransformBy(Matrix3d.Rotation(rotation, coordSys.Zaxis, insPointValue));
modelSpace.AppendEntity(blkRef);
acTrans.AddNewlyCreatedDBObject(blkRef, true);
ODHelper.AttachObjectData(acadDoc, blkRef.ObjectId, ODTableName, columnsValues);
}
}
void AttachObjectData(Document acadDoc, ObjectId objId, string odTableName, Dictionary<string, object> columnsValues)
{
Table ODTable = GetODTable(acadDoc);
using (FieldDefinitions fieldDefs = ODtable.FieldDefinitions)
{
using (Records records = ODtable.GetObjectTableRecords(Convert.ToUInt32(0), objId,
Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, true))
{
if (0 == records.Count)
{
using (Record newRecord = Record.Create())
{
ODtable.InitRecord(newRecord);
PopulateFieldValues(ODtable.FieldDefinitions, newRecord, columnsValues);
ODtable.AddRecord(newRecord, objId);
}
}
else
{
using (OD.Record firstRecord = records[0])
{
PopulateFieldValues(ODtable.FieldDefinitions, firstRecord, columnsValues);
records.UpdateRecord(firstRecord);
}
}
}
}
}
else
{
using (OD.Record firstRecord = records[0])
{
PopulateFieldValues(ODtable.FieldDefinitions, firstRecord, columnsValues);
records.UpdateRecord(firstRecord);
}
}
}
}
}