public static void ManualInsertbAttribute(string nameBlock) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead); if (!blockTable.Has(nameBlock)) { ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock); return; } AcDb.BlockTableRecord curSpace = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); AcDb.BlockReference blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]); blockReference.TransformBy(ed.CurrentUserCoordinateSystem); curSpace.AppendEntity(blockReference); tr.AddNewlyCreatedDBObject(blockReference, true); AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead); AcDb.DBText text; foreach (AcDb.ObjectId id in btr) { if (id.ObjectClass.Name == "AcDbAttributeDefinition") { AcDb.AttributeDefinition attDef = (AcDb.AttributeDefinition)tr.GetObject(id, AcDb.OpenMode.ForRead); text = new AcDb.DBText { TextString = "jig_test" }; TextPlacementJig jig = new TextPlacementJig(text); //PromptResult pr = ed.Drag(jig); AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword; while (stat == AcEd.PromptStatus.Keyword) { AcEd.PromptResult pr = ed.Drag(jig); stat = pr.Status; if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword) { return; } } AcDb.AttributeReference attRef = new AcDb.AttributeReference(); attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform); AcDb.ObjectId attId = blockReference.AttributeCollection.AppendAttribute(attRef); tr.AddNewlyCreatedDBObject(attRef, true); tr.Commit(); //if (pr.Status != PromptStatus.OK) blockReference.Erase(); } } //tr.Commit(); } }
public static void ReplaceAttributeBlock(AcDb.BlockReference blockReference, Dictionary <string, string> tags, Boolean visible) { using (AcDb.Transaction trAdding = db.TransactionManager.StartTransaction()) { AcDb.BlockTable btTable = (AcDb.BlockTable)trAdding.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead); AcDb.BlockTableRecord btrTable = (AcDb.BlockTableRecord)btTable[blockReference.Name].GetObject(AcDb.OpenMode.ForRead); if (btrTable.HasAttributeDefinitions) { var attDefs = btrTable.Cast <AcDb.ObjectId>() .Where(n => n.ObjectClass.Name == "AcDbAttributeDefinition") .Select(n => (AcDb.AttributeDefinition)n.GetObject(AcDb.OpenMode.ForRead)); foreach (AcDb.AttributeDefinition attDef in attDefs) { AcDb.AttributeReference attRef = new AcDb.AttributeReference(); attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform); foreach (var tag in tags) { attRef.UpgradeOpen(); if (tag.Key.ToUpper() == attRef.Tag) { attRef.TextString = tag.Value; } else { attRef.TextString = "NoneValue"; } attRef.Visible = visible; attRef.Rotation = 0; } blockReference.AttributeCollection.AppendAttribute(attRef); trAdding.AddNewlyCreatedDBObject(attRef, false); } } else { ed.WriteMessage("\n < ERROR > "); } trAdding.Commit(); } }
private void insertBending(R.Raud _ALFA_, G.Point insertion) { string layerName = "K023TL"; string blockName = getBendingBlockName(_ALFA_); _Ge.Point3d insertPointBlock = new _Ge.Point3d(insertion.X, insertion.Y, 0); using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[blockName])) { newBlockReference.Layer = layerName; _c.modelSpace.AppendEntity(newBlockReference); _c.trans.AddNewlyCreatedDBObject(newBlockReference, true); newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(L._V_.Z_DRAWING_SCALE, insertPointBlock)); _Db.BlockTableRecord blockBlockTable = _c.trans.GetObject(_c.blockTable[blockName], _Db.OpenMode.ForRead) as _Db.BlockTableRecord; if (blockBlockTable.HasAttributeDefinitions) { foreach (_Db.ObjectId objID in blockBlockTable) { _Db.DBObject obj = _c.trans.GetObject(objID, _Db.OpenMode.ForRead) as _Db.DBObject; if (obj is _Db.AttributeDefinition) { _Db.AttributeDefinition attDef = obj as _Db.AttributeDefinition; if (!attDef.Constant) { using (_Db.AttributeReference attRef = new _Db.AttributeReference()) { attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform); attRef.Position = attDef.Position.TransformBy(newBlockReference.BlockTransform); setBendingBlockParameters(attRef, _ALFA_); newBlockReference.AttributeCollection.AppendAttribute(attRef); _c.trans.AddNewlyCreatedDBObject(attRef, true); } } } } } } }
private void insertRow(G.Point insertion, T.TableBendingRow rowData, double scale, string tableBendingRow) { _Ge.Point3d insertPointBlock = new _Ge.Point3d(insertion.X, insertion.Y, 0); using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[tableBendingRow])) { newBlockReference.Layer = bendingLayer; _c.modelSpace.AppendEntity(newBlockReference); _c.trans.AddNewlyCreatedDBObject(newBlockReference, true); newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(scale, insertPointBlock)); _Db.BlockTableRecord blockBlockTable = _c.trans.GetObject(_c.blockTable[tableBendingRow], _Db.OpenMode.ForRead) as _Db.BlockTableRecord; if (blockBlockTable.HasAttributeDefinitions) { foreach (_Db.ObjectId objID in blockBlockTable) { _Db.DBObject obj = _c.trans.GetObject(objID, _Db.OpenMode.ForRead) as _Db.DBObject; if (obj is _Db.AttributeDefinition) { _Db.AttributeDefinition attDef = obj as _Db.AttributeDefinition; if (!attDef.Constant) { using (_Db.AttributeReference attRef = new _Db.AttributeReference()) { attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform); attRef.Position = attDef.Position.TransformBy(newBlockReference.BlockTransform); setRowParameters(attRef, rowData); newBlockReference.AttributeCollection.AppendAttribute(attRef); _c.trans.AddNewlyCreatedDBObject(attRef, true); } } } } } } }