using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
public class Commands
{
[CommandMethod("Create3DPolyline")]
public void Create3DPolyline()
{
// Get the current document and database
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
// Start a transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Open the BlockTable for read
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the BlockTableRecord (model space) for write
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Prompt the user to select the first point
PromptPointResult firstPointResult = doc.Editor.GetPoint("Select the first point: ");
if (firstPointResult.Status != PromptStatus.OK) return;
// Prompt the user to select the second point
PromptPointResult secondPointResult = doc.Editor.GetPoint("Select the second point: ");
if (secondPointResult.Status != PromptStatus.OK) return;
// Create a 3D polyline with the selected points
Polyline3d polyline = new Polyline3d();
polyline.AddVertexAt(0, firstPointResult.Value.Convert3d(), 0, 0, 0);
polyline.AddVertexAt(1, secondPointResult.Value.Convert3d(), 0, 0, 0);
// Add the polyline to the block table record
btr.AppendEntity(polyline);
tr.AddNewlyCreatedDBObject(polyline, true);
// Commit the transaction
tr.Commit();
}
}
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime;
public class Commands { [CommandMethod("Create3DPolyline")] public void Create3DPolyline() { // Get the current document and database Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database;
}