
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey Everyone,
I've been going through some examples on http://through-the-interface.typepad.com to create polylines and i've managed to make some code run. One thing that I can't seem to find information on though, is how to use the default AutoCAD command line options in my code. For instance, I would like to be able to prompt the user whether they would like to snap the polyline to an insertion point, everytime they create a new verticie. I'm not sure how to do this, does anyone have an suggestions or experience with this?
Cheers
Vince
Below is some example code from the site that i'm working from:
namespace MyPlineApp
{
public class MyPlineCmds
{
[CommandMethod("MYPOLY")]
public void MyPoly()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Get the current color, for our temp graphics
Color col = doc.Database.Cecolor;
// Create a point collection to store our vertices
Point3dCollection pts = new Point3dCollection();
// Set up the selection options
// (used for all vertices)
PromptPointOptions opt =
new PromptPointOptions(
"\nSelect polyline vertex: "
);
opt.AllowNone = true;
// Get the start point for the polyline
PromptPointResult res = ed.GetPoint(opt);
while (res.Status == PromptStatus.OK)
{
// Add the selected point to the list
pts.Add(res.Value);
// Drag a temp line during selection
// of subsequent points
opt.UseBasePoint = true;
opt.BasePoint = res.Value;
res = ed.GetPoint(opt);
if (res.Status == PromptStatus.OK)
{
// For each point selected,
// draw a temporary segment
ed.DrawVector(
pts[pts.Count - 1], // start point
res.Value, // end point
col.ColorIndex, // current color
false); // highlighted?
}
}
if (res.Status == PromptStatus.None)
{
// Get the current UCS
Matrix3d ucs =
ed.CurrentUserCoordinateSystem;
Point3d origin = new Point3d(0, 0, 0);
Vector3d normal = new Vector3d(0, 0, 1);
normal = normal.TransformBy(ucs);
// Create a temporary plane, to help with calcs
Plane plane = new Plane(origin, normal);
// Create the polyline, specifying
// the number of vertices up front
Polyline pline = new Polyline(pts.Count);
pline.Normal = normal;
foreach (Point3d pt in pts)
{
Point3d transformedPt = pt.TransformBy(ucs);
pline.AddVertexAt(pline.NumberOfVertices, plane.ParameterOf(transformedPt),0, 0, 0);
}
// Now let's add the polyline to the modelspace
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
ObjectId plineId = btr.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
tr.Commit();
ed.WriteMessage("\nPolyline entity is: " + plineId.ToString());
}
}
// Clear the temp graphics (polyline should be in
// the same location, if selection was not cancelled)
// We could "redraw" instead of "regen" here
ed.Regen();
}
}
}
Solved! Go to Solution.