We demonstrated about some AutoCAD selection set building APIs such as Editor.SelectFence. Editor.SelectWindow, Editor.SelectCrossingWindow and Editor.SelectCrossingPolygon, and presented our PointCollector coder a few times before.
Now let’s see how to use AutoCAD .NET selection set APIs and the PointCollector coder together to make the selection work nicer and quicker. Specifically in this case, let us use the PointCollector to collect points composing a circle (regular polygon with many sizes actually) visually first and use the Editor.SelectWindowPolygon to build up a selection set from the circular area.
[CommandMethod("SelectCirclePolygonAndPointCollector", CommandFlags.Modal)]
public static void SelectCirclePolygonAndPointCollector_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (PointCollector pc = new PointCollector(PointCollector.Shape.Circle))
{
PromptSelectionResult prSelRes = ed.SelectWindowPolygon(pc.Collect());
if (prSelRes.Status == PromptStatus.OK)
{
using (SelectionSet ss = prSelRes.Value)
{
if (ss != null)
ed.WriteMessage("\nThe SS is good and has {0} entities.", ss.Count);
else
ed.WriteMessage("\nThe SS is bad!");
}
}
else
ed.WriteMessage("\nSelection failed!");
}
}
catch (System.Exception ex)
{
ed.WriteMessage(Environment.NewLine + ex.ToString());
}
}
The above code is self explainable enough. In terms of the code of the PointCollector, we have demonstrated about it a few times before so haven’t appended it here for brevity purpose. In case necessary, please refer to earlier posts for details about it.
Here is how the command behaves in AutoCAD.
As can be seen, the circle is approximated by a many side regular polygon and is displayed nicely with the proper CONTRAST graphics drawing mode (specifically using the TransientDrawingMode.Contrast enum in the TransientManager.CurrentTransientManager.AddTransient call) which is chosen automatically by the PointCollector. In addition, as also can be seen, the PointCollector honors UCS perfectly.
After the center and radius of the circle are set as above, we may get back some.
Command: SELECTCIRCLEPOLYGONANDPOINTCOLLECTOR
Center:
Radius <10>:
The SS is good and has 9 entities.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides project wizards in C#, VB.NET and CLI/Managed C++, and various item wizards such as Event Handlers, Command/LispFunction Definers, and Entity/Draw Jiggers in both C# and VB.NET, to help program AutoCAD addins.
Posted by: |