We talked about the count limit of available selection sets in Auto/Visual LISP, AutoCAD .NET, and AutoCAD ActiveX/COM interfaces, did some tiny experiments respectively for each of these APIs and all together, and suggested some good practices in some earlier posts.
In this article, let’s see how to create a selection set from some fencing points using AutoCAD .NET API and discuss about some tips and tricks about it. Here is the sample code/command first.
[CommandMethod("FenceSelectAndLinetype", CommandFlags.Modal)]
public void FenceSelectAndLinetype_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
Point3dCollection pts = new Point3dCollection();
PromptPointOptions prPntOpt = new PromptPointOptions("\nFence point: (Enter to finish)");
prPntOpt.AllowArbitraryInput = true;
prPntOpt.AllowNone = true;
prPntOpt.UseBasePoint = false;
prPntOpt.UseDashedLine = true;
Point3d prePnt = new Point3d(double.NegativeInfinity, 0, 0);
while (true)
{
if (!double.IsNegativeInfinity(prePnt.X))
{
prPntOpt.UseBasePoint = true;
prPntOpt.BasePoint = prePnt;
}
PromptPointResult prPntRes = ed.GetPoint(prPntOpt);
if (prPntRes.Status == PromptStatus.OK)
{
pts.Add(prPntRes.Value);
prePnt = prPntRes.Value;
}
else
break;
}
PromptSelectionResult prSelRes = ed.SelectFence(pts);
if (prSelRes.Status == PromptStatus.OK)
{
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("\nFence selection failed!");
}
catch (System.Exception ex)
{
ed.WriteMessage(Environment.NewLine + ex.ToString());
}
}
The above code is self explainable enough. Here, however, we’d like to point out one thing specifically. The SelectFence() method honors the line types of AutoCAD entities. If the fence goes through some gap of a particular line type such as dashed, the entity won’t be collected into the resultant entity set in case no other fence segments intercept with the entity either. Here is such an example:
The output of the command:
Command:
FENCESELECTANDLINETYPE
Fence point: (Enter to finish):
Fence point: (Enter to finish):
Fence point: (Enter to finish):
Fence selection failed!
If the fence avoids those gaps, things are just fine.
Command:
FENCESELECTANDLINETYPE
Fence point: (Enter to finish):
Fence point: (Enter to finish):
Fence point: (Enter to finish):
The SS is good and has 2 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: |