public void MyPolyJig() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // Get the current UCS, to pass to the Jig Matrix3d ucs = ed.CurrentUserCoordinateSystem; // Create our Jig object PlineJig jig = new PlineJig(ucs); // Loop to set the vertices directly on the polyline bool bSuccess = true; for (int i = 0; i < 2; i++) { PromptResult res = ed.Drag(jig); bSuccess = (res.Status == PromptStatus.OK); // A new point was added if (bSuccess) { jig.AddLatestVertex(); } } jig.RemoveLastVertex(); // If the jig completed successfully, add the polyline // Append entity Database db = doc.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = ((BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)); btr.AppendEntity(jig.GetEntity()); tr.AddNewlyCreatedDBObject(jig.GetEntity(), true); tr.Commit(); } }
public void MyPolyJig() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // Get the current UCS, to pass to the Jig Matrix3d ucs = ed.CurrentUserCoordinateSystem; //ensures that the layer the object will be created on exists, if it doesn't creates it GeneralMenu.CreateLayer("DIM", 1, "Continuous", true); // Create our Jig object PlineJig jig = new PlineJig(ucs); // Loop to set the vertices directly on the polyline bool bSuccess = true; for (int i = 0; i < 2; i++) { PromptResult res = ed.Drag(jig); bSuccess = (res.Status == PromptStatus.OK); // A new point was added if (bSuccess) { jig.AddLatestVertex(); } } jig.RemoveLastVertex(); Ellipse el = InsertElipse(); //formula for calculating a polar point based on a base point, an angle, and the distance Point3d newpoint = new Point3d(el.Center.X + 0.04492187 * Math.Cos(angleA + 4.71238898), el.Center.Y + 0.04492187 * Math.Sin(angleA + 4.71238898), 0); jig.ReplaceOrigin(newpoint); MText tx = addText(); // If the jig completed successfully, add the polyline // Append entity Database db = doc.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = ((BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)); btr.AppendEntity(jig.GetEntity()); btr.AppendEntity(el); btr.AppendEntity(tx); tr.AddNewlyCreatedDBObject(jig.GetEntity(), true); tr.AddNewlyCreatedDBObject(el, true); tr.AddNewlyCreatedDBObject(tx, true); tr.Commit(); } }
public static ObjectId MyPolyJig(out bool status) { using (DocumentLock docLock = Application.DocumentManager.MdiActiveDocument.LockDocument()) { ObjectId oid = ObjectId.Null; Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // Get the current UCS, to pass to the Jig Matrix3d ucs = ed.CurrentUserCoordinateSystem; // Create our Jig object PlineJig jig = new PlineJig(ucs); // Loop to set the vertices directly on the polyline bool bSuccess = true, bComplete = false; do { PromptResult res = ed.Drag(jig); bSuccess = (res.Status == PromptStatus.OK); // A new point was added if (bSuccess) { jig.AddLatestVertex(); } // Null input terminates the command bComplete = (res.Status == PromptStatus.None); if (bComplete) { // Let's clean-up the polyline before adding it jig.RemoveLastVertex(); } } while (bSuccess && !bComplete); // If the jig completed successfully, add the polyline if (bComplete) { if (((Polyline)jig.GetEntity()).NumberOfVertices <= 2) { status = true; return(ObjectId.Null); } // Append entity Database db = doc.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject( db.BlockTableId, OpenMode.ForRead, false ); BlockTableRecord btr = (BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false ); oid = btr.AppendEntity(jig.GetEntity()); tr.AddNewlyCreatedDBObject(jig.GetEntity(), true); tr.Commit(); } status = true; } else { status = false; } return(oid); } }