public static void ManualInsertMText(AcDb.MText oMText) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); oMText.Normal = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis; btr.AppendEntity(oMText); tr.AddNewlyCreatedDBObject(oMText, true); MTextPlacementJig pj = new MTextPlacementJig(oMText); AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword; while (stat == AcEd.PromptStatus.Keyword) { AcEd.PromptResult res = ed.Drag(pj); stat = res.Status; if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword) { return; } } tr.Commit(); //return (MText)pj.Entity; } }
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(); } }