000

Index Labels

Picking Points With Visual Aid

.
Again, this article was prompted with the discussion in the same thread from Autodesk's .NET discussion here.

As we all know, using PromptPointOptions with Editor.GetPoint(), one can use its properties UseBasePoint and BasePoint tp let AutoCAD show a rubber band line while picking points.

Some times, there are many points to pick, and user may want to have certain visual hint showing the points he/she has picked during the picking process. It may also be helpful to show a trace line follow the order of the points being picked.

Here is the code I do it, in a class called "PickPoints":

using System.Collections.Generic;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;

namespace PickPointWithVisualSpot
{
public class PickPoints
{
private Document _dwg;
private Editor _editor;
private List _points = null;
private List _circles = null;

private bool _drawPline = false;
private Polyline _pline = null;

private int _color = 1;
private double _radius = 0.1;

public PickPoints(Document dwg)
{
_dwg = dwg;
_editor = _dwg.Editor;
}

public Point3d[] PickedPoints
{
get
{
if (_points == null)
return null;
else
return _points.ToArray();
}
}

public void DoPick(bool drawTraceLine)
{
try
{
//Pick first point
Point3d pt;
if (!PickFirstPoint(out pt)) return;

_drawPline = drawTraceLine;

_points = new List();
_circles = new List();

_points.Add(pt);

//Crate visual at the point
CreateCircle(pt);

while (true)
{
if (!PickNextPoint()) break;
}
}
catch { }
finally
{
//Clear Transient graphics
if (_circle != null)
{

if (_circles.Count > 0)
{
foreach (Circle c in _circles)
{
TransientManager.CurrentTransientManager.
EraseTransient(c, new IntegerCollection());

c.Dispose();
}
}

_circles.Clear();
_circles = null;
}

ClearTraceLine();
}
}

private bool PickFirstPoint(out Point3d pt)
{
pt = new Point3d();

PromptPointOptions opt =
new PromptPointOptions("\nPick start point: ");
PromptPointResult res = _editor.GetPoint(opt);
if (res.Status == PromptStatus.OK)
{
pt = res.Value;
return true;
}
else
{
return false;
}
}

private bool PickNextPoint()
{
PromptPointOptions opt=
new PromptPointOptions("\nPick next point: ");
opt.UseBasePoint=true;
opt.BasePoint=_points[_points.Count-1];
if (_points.Count>2)
{
opt.Keywords.Add("Close");
opt.AppendKeywordsToMessage=true;
}

PromptPointResult res=_editor.GetPoint(opt);
if (res.Status==PromptStatus.OK)
{
_points.Add(res.Value);

CreateCircle(res.Value);

if (_points.Count > 1 && _drawPline )
{
DrawTraceLine();
}

return true;
}
else if (res.Status==PromptStatus.Keyword)
{
return false;
}
else
{
return false;
}
}

private void CreateCircle(Point3d pt)
{
Circle c = new Circle();
c.Center = pt;
c.Radius = _radius;
c.ColorIndex = _color;
c.Highlight();

TransientManager.CurrentTransientManager.AddTransient(c,
TransientDrawingMode.Highlight,128, new IntegerCollection());

_circles.Add(c);
}

private void DrawTraceLine()
{
ClearTraceLine();

_pline = new Polyline(_points.Count);

for (int i = 0; i < _points.Count; i++)
{
Point2d p = new Point2d(_points[i].X, _points[i].Y);
_pline.AddVertexAt(i, p, 0.0, 0.0, 0.0);
}

_pline.ColorIndex = _color;

TransientManager.CurrentTransientManager.AddTransient(_pline,
TransientDrawingMode.Highlight, 128, new IntegerCollection());
}

private void ClearTraceLine()
{
if (_pline != null)
{
TransientManager.CurrentTransientManager.
EraseTransient(_pline, new IntegerCollection());

_pline.Dispose();
_pline = null;
}
}
}
}
Then the use of the class in custom command. There are 2 commands: one shows trace line, while the other does not:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(PickPointWithVisualSpot.MyCommand))]

namespace PickPointWithVisualSpot
{
public class MyCommand
{
[CommandMethod("MyPick1", CommandFlags.Session)]
public static void RunThisMethod1()
{
Document dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

PickPoints pick = new PickPoints(dwg);

pick.DoPick(false);
if (pick.PickedPoints != null)
{
dwg.Editor.WriteMessage("\nMyCommand executed: {0} points picked.", pick.PickedPoints.Length);
}
else
{
dwg.Editor.WriteMessage("\n*Cancelled*");
}
}

[CommandMethod("MyPick2", CommandFlags.Session)]
public static void RunThisMethod2()
{
Document dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

PickPoints pick = new PickPoints(dwg);

pick.DoPick(true);
if (pick.PickedPoints != null)
{
dwg.Editor.WriteMessage("\nMyCommand executed: {0} points picked.", pick.PickedPoints.Length);
}
else
{
dwg.Editor.WriteMessage("\n*Cancelled*");
}
}
}
}

See this video clip for the code's behaviour.

Note: thanks to Irvin who prompted a bug in the "PickPoints" class' DoPick() method in the try...finally{...} block. I have corrected in red.

Blog Archive

Labels

2D Drafting 3D design 3D Modeling 3D models 3D Printing 3D rendering 3D scanning 3D Sketch Inventor 3D visualization 3D Web App 3ds Max ACC Additive Manufacturing AEC Technology affordable Autodesk tools AI Design AI in CAD AI in Manufacturing AI Tools AR architectural design architectural modeling architectural visualization Architecture architecture design Architecture Firm Architecture Productivity architecture software Artificial Intelligence As-Built Model augmented reality AutoCAD AutoCAD advice AutoCAD Basics AutoCAD Beginners AutoCAD Civil 3D AutoCAD Civil3D AutoCAD commands AutoCAD efficiency AutoCAD features AutoCAD File Management AutoCAD Layer AutoCAD learning AutoCAD print settings AutoCAD productivity AutoCAD Teaching AutoCAD Techniques AutoCAD tips AutoCAD tools AutoCAD training. AutoCAD tricks AutoCAD Tutorial AutoCAD workflow AutoCAD Xref Autodesk Autodesk 2025 Autodesk 2026 Autodesk 3ds Max Autodesk AI Autodesk AI Tools Autodesk Alias Autodesk AutoCAD Autodesk BIM Autodesk BIM 360 Autodesk Certification Autodesk Cloud Autodesk Construction Cloud Autodesk Docs Autodesk Dynamo Autodesk features Autodesk Forge Autodesk FormIt Autodesk Fusion 360 Autodesk InfraWorks Autodesk Inventor Autodesk Inventor Frame Generator Autodesk Inventor iLogic Autodesk License Autodesk Navisworks Autodesk news Autodesk plugins Autodesk Recap Autodesk Revit Autodesk Software Autodesk Takeoff Autodesk Tips Autodesk training Autodesk update Autodesk Upgrade Autodesk Vault Autodesk Video Autodesk Viewer Automation Automation Tutorial automotive design automotive visualization Backup Basic Commands Basics Beginner Beginner Tips Big Data BIM BIM 360 BIM collaboration BIM Coordination BIM Data BIM for Infrastructure BIM Implementation BIM software BIM technology BIM tools BIM Trends BIM workflow Block Editor Building Maintenance Building Systems ByLayer CAD CAD API CAD Automation CAD commands CAD comparison CAD Data Management CAD Design CAD Evolution CAD File Size Reduction CAD Integration CAD line thickness CAD management CAD modeling CAD Optimization CAD plugins CAD Productivity CAD Security CAD Skills CAD software CAD software 2026 CAD software training CAD technology CAD Tips CAD workflow car design software Case Study CGI design Civil 3D civil engineering Clash Detection Class-A surfacing clean CAD file cleaning command client engagement Cloud CAD Cloud Collaboration Cloud design platform Cloud Engineering Cloud Management Cloud Storage Cloud-First collaboration command abbreviations concept car conceptual workflow construction Construction Analytics Construction BIM Construction Cloud Construction Technology contractor tools Contractor Workflow Contraints cost estimation Create resizable blocks CTB STB Cybersecurity Data Backup data management Data Protection Data Reference Data Security Data Shortcut Design Automation Design Collaboration Design Comparison design review Design Rules design software design software tips Design Technology Design Tools Design Workflow design-to-construction Designer Tools Digital Construction Technology Digital Design Digital engineering digital fabrication digital marketing digital takeoff Digital Twin Digital Twins digital workflow Drafting Standards Drawing Automation Dref Dynamic Block Dynamic Block AutoCAD Dynamic Blocks Dynamic doors Dynamic windows Dynamo automation early stage design eco design editing commands energy efficiency Engineering Engineering Automation engineering data Engineering Design Engineering Innovation Engineering Productivity engineering software Engineering Technology engineering tools Engineering Tools 2025 Engineering Workflow Excel Express Tools External Reference Facility Management Fast Structural Design File Recovery Forge Development Forge Viewer FreeCAD Fusion 360 Fusion 360 tutorial Future Skills Generative Design Geospatial Data GIS Global design teams green building Grips Handoff heavy CAD file Heavy CAD Files HVAC Design Tools HVAC Engineering Hydraulic Modeling iLogic Industry 4.0 infrastructure design Infrastructure Monitoring Infrastructure Planning Infrastructure Technology InfraWorks Insight interactive presentation Interior Design Inventor Inventor API Inventor Drawing Template Inventor Frame Generator Inventor Graphics Issues Inventor IDW Inventor Tips Keyboard Shortcuts Large Projects Laser Scan Learn AutoCAD Licensing Linked Models Machine Learning in CAD maintenance command Management Manufacturing Innovation Mapping Technology marketing visuals Mechanical Design Mechanical Engineering MEP Modeling Mesh-to-BIM Metal Structure Model Optimization Multi-User Environment Navisworks Best Practices ObjectARX .NET API Open Source CAD Organization OVERKILL OVERKILL AutoCAD Palette parametric design parametric family PDF PDM system Plot Style AutoCAD point cloud Post Construction Practice Drawing preconstruction workflow Predictive Maintenance Printing Quality Product Design Product Development product lifecycle product rendering Productivity productivity tools professional printing Professional Tips project management PTC Creo PURGE PURGE AutoCAD realistic rendering ReCap reduce CAD file size rendering engine rendering software Renovation Project Resizable Block Revit Revit add-ins Revit automation Revit Best Practices Revit integration Revit MEP Revit Performance Revit Scripting Revit skills Revit Tips Revit tutorial Revit Workflow Ribbon Scale Autodesk screen Secure Collaboration shortcut keys Shortcuts Siemens NX Simulation Sketch Small Firms Smart Block Smart City Smart Factory Smart Infrastructur Software Compliance Software Management Software Update SolidWorks Steel Structure Design Structural Optimization sustainability sustainable design Sustainable Manufacturing team training guide Technical Drawing time saving tools toolbar Troubleshooting Tutorial urban planning User Interface (UI) Vault Best Practices Vault Lifecycle Vault Mistakes vehicle modeling virtual reality visualization workflow VR VRED Water Infrastructure Water Management What’s New in Autodesk Workbook workflow Workflow Automation Workflow Optimization Worksets Worksharing Workspace XLS Xref