/// <summary> /// Синхронизация атрибутов блока. Требуется запущенная транзакция /// </summary> public static void SynchronizeAttributes([NotNull] this BlockTableRecord target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } var tr = target.Database.TransactionManager.TopTransaction; if (tr == null) { throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoActiveTransactions); } var attDefs = target.GetAttributes(tr); foreach (ObjectId id in target.GetBlockReferenceIds(true, false)) { var br = id.GetObjectT <BlockReference>(); br.ResetAttributes(attDefs, tr); } if (target.IsDynamicBlock) { target.UpdateAnonymousBlocks(); foreach (ObjectId id in target.GetAnonymousBlockIds()) { var btr = id.GetObjectT <BlockTableRecord>(); attDefs = btr.GetAttributes(tr); foreach (ObjectId brId in btr.GetBlockReferenceIds(true, false)) { var br = brId.GetObject <BlockReference>(OpenMode.ForWrite); br?.ResetAttributes(attDefs, tr); } } } }
public static void SynchronizeAttributes(this BlockTableRecord target) { if (target == null) { throw new ArgumentNullException("target"); } Transaction tr = target.Database.TransactionManager.TopTransaction; if (tr == null) { throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoActiveTransactions); } List <AttributeDefinition> attDefs = target.GetAttributes(tr); foreach (ObjectId id in target.GetBlockReferenceIds(true, false)) { BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForWrite); br.ResetAttributes(attDefs, tr); } if (target.IsDynamicBlock) { target.UpdateAnonymousBlocks(); foreach (ObjectId id in target.GetAnonymousBlockIds()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead); attDefs = btr.GetAttributes(tr); foreach (ObjectId brId in btr.GetBlockReferenceIds(true, false)) { BlockReference br = (BlockReference)tr.GetObject(brId, OpenMode.ForWrite); br.ResetAttributes(attDefs, tr); } } } }
public BlockReference GetObject(Point3d position, List <string> attrTextValues) { if (this._blockId != ObjectId.Null) { _createBlockRecord(_name, _annotativeState, _origin, false); } BlockReference br = null; Tools.StartTransaction(() => { if (_blockRecordId != ObjectId.Null) { BlockTable bt = _db.BlockTableId.GetObjectForRead <BlockTable>(); BlockTableRecord ms = bt[BlockTableRecord.ModelSpace].GetObjectForWrite <BlockTableRecord>(); BlockTableRecord btr = _blockRecordId.GetObjectForRead <BlockTableRecord>(); br = new BlockReference(position, _blockRecordId); ObjectContextManager ocm = btr.Database.ObjectContextManager; ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES"); if (btr.Annotative == AnnotativeStates.True) { br.AddContext(occ.CurrentContext); } ObjectId brId = ms.AppendEntity(br); _db.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(br, true); // Add attributes from the block table record List <AttributeDefinition> attributes = btr.GetAttributes(); int i = 0; foreach (AttributeDefinition acAtt in attributes) { if (!acAtt.Constant) { using (AttributeReference acAttRef = new AttributeReference()) { //acAttRef.RecordGraphicsModified(true); acAttRef.SetAttributeFromBlock(acAtt, br.BlockTransform); //acAttRef.Position = acAtt.Position.TransformBy(br.BlockTransform); acAttRef.TextString = attrTextValues[i++]; //if (acAtt.Annotative == AnnotativeStates.True) //acAttRef.AddContext(occ.CurrentContext); br.AttributeCollection.AppendAttribute(acAttRef); _db.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(acAttRef, true); } } } _insertPoint = position; _blockId = br.Id; } }); return(br); }