We demonstrated a while back that the fence option of the AutoCAD Selection API (specifically the Editor.SelectFence method) has some behavior that might confuse people regarding entity line types. That is, if the fence happens to go through some gap of non-continuous line type of an entity, it will be missed out in the collected back entity set.
Good or bad, that is what it is. In addition, the Crossing (Window) selection API (specifically the Editor.SelectCrossingWindow method) has similar behavior to the Fence one. We are going to talk about it in a bit detail here.
[CommandMethod("WindowCrossingSelectAndLinetype", CommandFlags.Modal)]
public void WindowCrossingSelectAndLinetype_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (PointCollector pc = new PointCollector(PointCollector.Shape.Window))
{
pc.Collect();
Point3dCollection winCorners = pc.CollectedPoints;
PromptSelectionResult prSelRes = ed.SelectCrossingWindow(winCorners[0], winCorners[1]);
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("\nCrossing window selection failed!");
}
}
catch (System.Exception ex)
{
ed.WriteMessage(Environment.NewLine + ex.ToString());
}
}
The above code is simple enough except for the PointCollector coder. We have demonstrated about the PointCollector coder a few times already and it should be simple too for readers who have read those previous posts. As can be seen, it is very easy to use and can be made easier, e.g. through returning the collected points from the Collect() call directly. If necessary, we may make the change in future. Please go ahead to make it yourself if cannot wait.
Here, however, we’d like to point out one thing specifically. The Editor.SelectCrossingWindow () method seems to pick things virtually instead of computationally. If the crossing window goes through some gap of a non-continuous line type such as dashed, the entity won’t be collected into the resultant entity set. Here is such an example:
WINDOWCROSSINGSELECTANDLINETYPE
The 1st corner:
The 2nd corner:
Crossing window selection failed!
If the crossing window overlaps any visual parts of the entities, even just a little, things are just fine.
Command: WINDOWCROSSINGSELECTANDLINETYPE
The 1st corner:
The 2nd corner:
The SS is good and has 2 entities.
It may not be a big deal in most cases. Bearing this in mind seems not a bad idea either when the crossing window selection option is being considered to be used in your program.
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: |