public static void ManualInsertText(AcDb.DBText oText) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); oText.Normal = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis; btr.AppendEntity(oText); tr.AddNewlyCreatedDBObject(oText, true); TextPlacementJig pj = new TextPlacementJig(oText); 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 (DBText)pj.Entity; } }
public static AcDb.ObjectId ManualInsertBlock(string nameBlock, double scaleBlock, Dictionary <string, string> tags) { AcDb.ObjectId idBlock = AcDb.ObjectId.Null; 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(idBlock); } AcDb.BlockTableRecord curSpace = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); AcDb.BlockReference blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]) { ScaleFactors = new AcGe.Scale3d(scaleBlock, scaleBlock, scaleBlock) }; blockReference.TransformBy(ed.CurrentUserCoordinateSystem); curSpace.AppendEntity(blockReference); tr.AddNewlyCreatedDBObject(blockReference, true); AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead); BlockPlacementJig jig = new BlockPlacementJig(blockReference, tags); AcEd.PromptResult pr = ed.Drag(jig); if (pr.Status != AcEd.PromptStatus.OK) { blockReference.Erase(); } tr.Commit(); } return(idBlock); }
public static void BuildingRectangle() { try { AcDb.Database db = CurrentCAD.Database; AcEd.Editor ed = CurrentCAD.Editor; AcEd.PromptKeywordOptions pko; AcEd.PromptPointOptions ppt; AcEd.PromptPointResult ppr; AcGe.Point3d basePoint; AcGe.Point3d diractionPoint; pko = new AcEd.PromptKeywordOptions("\nПобудова прямокутника"); pko.Keywords.Add("по Діагоналі"); pko.Keywords.Add("по Напрямку та діагоналі"); pko.Keywords.Add("по Ширині та висота"); pko.Keywords.Default = "по Ширині та висота"; pko.AllowNone = false; AcEd.PromptResult pkr = ed.GetKeywords(pko); if (pkr.Status != AcEd.PromptStatus.OK) { return; } MethodConstructingRectangle methodConstructing; if (pkr.StringResult == "Діагоналі") { methodConstructing = MethodConstructingRectangle.Diagonal; } else if (pkr.StringResult == "Напрямку") { methodConstructing = MethodConstructingRectangle.DirectionAndDiagonal; } else { methodConstructing = MethodConstructingRectangle.HeightAndWidth; } ppt = new AcEd.PromptPointOptions("\nВкажіть першу точку прямокутника:"); ppr = ed.GetPoint(ppt); if (ppr.Status != AcEd.PromptStatus.OK) { return; } basePoint = ppr.Value; if (methodConstructing == MethodConstructingRectangle.Diagonal) { diractionPoint = basePoint.Add(AcGe.Vector3d.XAxis); } else { ppt = new AcEd.PromptPointOptions("\n"); if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal) { ppt.Message = "\nВкажіть точку напрямку прямокутника:"; } else if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal) { ppt.Message = "\nВкажіть ширину прямокутника:"; } ppt.UseBasePoint = true; ppt.BasePoint = basePoint; ppr = ed.GetPoint(ppt); if (ppr.Status != AcEd.PromptStatus.OK) { return; } diractionPoint = ppr.Value; } jigger = new RectangleJig(methodConstructing, basePoint, diractionPoint); ed.Drag(jigger); using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline(); ent.SetDatabaseDefaults(); for (int i = 0; i < jigger.Corners.Count; i++) { AcGe.Point3d pt3d = jigger.Corners[i]; AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y); ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid); } ent.Closed = true; ent.TransformBy(jigger.UCS); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); tr.Commit(); } } catch (System.Exception ex) { CurrentCAD.Editor.WriteMessage(ex.ToString()); } }