|
I found a intersting issue when using
Editor.SelectWindowPolygon()/SelectCrossingPolygon(), that cost me quite
sime time to debug my project. The problem is, the selecting polygon
(crossing or window) MUST be within Acad editor's current view. That is, the
polygon must be entirely viewable within the current view. If part of the
polygon is out side the current view, the returned PromtSelectionResult's
Status property will be "Error".
Backgroud: in my project, I need to find some entities with a closed
polyline. So, I used the closed polyline as selecting polygon with the
SelectCrossingPolygon() method. During my code executing, the drawing's view
could be zoomed/paned so that the polyline may be moved partly outside
current view. The result my find entity logic was not consistent: some time
it finds entities it is supposed to, some time it does not find. I
eventually foudn the reason. Here is the testing code:
[CommandMethod("CSTest")]
public static void CrossingPolygonSelect()
{
Document dwg =
Autodesk..ApplicationServices.Application.DocumentManager.MdiActiveDocument;
//Pick a polyline as selecting crossing polygon
PromptEntityResult res = dwg.Editor.GetEntity("\nPick a polyline:");
if (res.Status != PromptStatus.OK) return;
//Get selecting polyline object
Polyline pline = null;
using (Transaction tran =
dwg.Database.TransactionManager.StartTransaction())
{
pline = (Polyline)tran.GetObject(res.ObjectId, OpenMode.ForRead);
}
//Get Poin3dCollection
Point3dCollection pts = new Point3dCollection();
for (int i = 0; i CPolygon", and managed to move part of selecting
polygon outside current view. The result was always correct, i.e. the "With
View" requirement is only applies programatical selecting.
Since the poor documentation of ObjectARX NET API, I could not find any
information on if it is be design or it is a bug, I post the issue here.
So, I work around to this iisue in my project would be to zoom to extents
before using SelectCrossingPolygon()/SelectWindowPolygon(), so that the
selecting polygon is shown entirely with the current view. This work around,
of cause, would cause issue if the drawing size is huge: zooming in this
case takes time if regen is required. Fortunately, the drawings my project
deals are all fairly small in size.
真是坑爹,刚好遇到这个问题,害的我调试了很久,原来真的如上所说这样。 |
|