.NET

.NET

Reply
*Norman Yuan
Message 1 of 5 (1,490 Views)

Editor.SelectWindowPolygon()/SelectCrossingPolygon() method: bug or by design?

1490 Views, 4 Replies
10-15-2006 10:21 AM
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.AutoCAD.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 < pline.NumberOfVertices; i++)
{
Point3d pt = pline.GetPoint3dAt(i);
pts.Add(pt);
}

//Get SelectionSet
PromptSelectionResult ssres = dwg.Editor.SelectCrossingPolygon(pts);

if (ssres.Status == PromptStatus.OK)
dwg.Editor.WriteMessage("\n" + ssres.Value.GetObjectIds().Length + "
object(s) selected.");
else
{
switch (ssres.Status)
{
case PromptStatus.Cancel:
dwg.Editor.WriteMessage("\nSelection Error: Cancelled.");
break;
case PromptStatus.Error:
dwg.Editor.WriteMessage("\nSelection Error: Error.");
//<--This error is reported
break;
case PromptStatus.None:
dwg.Editor.WriteMessage("\nSelection Error: None.");
break;
case PromptStatus.Other:
dwg.Editor.WriteMessage("\nSelection Error: Other.");
break;
case PromptStatus.Keyword:
dwg.Editor.WriteMessage("\nSelection Error: Keyword.");
break;
case PromptStatus.Modeless:
dwg.Editor.WriteMessage("\nSelection Error: Modeless.");
break;
default:
dwg.Editor.WriteMessage("\nSelection Error: Unknown.");
break;
}
}
}

To test it:

1. Compile the code in a test project
2. Start Acad
3. "Netload" the test project
4. Draw a closed polyline
5. Draw a few entities with the polygon, or crossed by the polygon
6. Zoom to extents to make sure entire polygon is viewable
7. issue Command "CSTest", then pick the polygon. You would see at command
line: "X object(s) selected."
8. Zoom in so that part of the polygon is out of view
9. Issed Command "CSTest", then pick the polygon. You may see at command
line: "Selection Error: Error", depending on how must you zoomed in.

The same behaviour is also with SelectWindowPolygon. I did not test it with
SelectWindow() and SelectWindowPolygon(), but if they behaves the same, it
won't supprise me.

Interstingly enough, I trid Acad built-in Select with polygon command
manually, that is, "Select->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.
*Norman Yuan
Message 2 of 5 (1,490 Views)

Re: Editor.SelectWindowPolygon()/SelectCrossingPolygon() method: bug or by design?

10-15-2006 10:24 AM in reply to: *Norman Yuan
Additional though:

I haven't test this issue in VBA. It may be interesting to see if the same
thing happens in VBA. I'll do it later today when I have time.

"Norman Yuan" wrote in message
news:5362227@discussion.autodesk.com...
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.AutoCAD.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 < pline.NumberOfVertices; i++)
{
Point3d pt = pline.GetPoint3dAt(i);
pts.Add(pt);
}

//Get SelectionSet
PromptSelectionResult ssres = dwg.Editor.SelectCrossingPolygon(pts);

if (ssres.Status == PromptStatus.OK)
dwg.Editor.WriteMessage("\n" + ssres.Value.GetObjectIds().Length + "
object(s) selected.");
else
{
switch (ssres.Status)
{
case PromptStatus.Cancel:
dwg.Editor.WriteMessage("\nSelection Error: Cancelled.");
break;
case PromptStatus.Error:
dwg.Editor.WriteMessage("\nSelection Error: Error.");
//<--This error is reported
break;
case PromptStatus.None:
dwg.Editor.WriteMessage("\nSelection Error: None.");
break;
case PromptStatus.Other:
dwg.Editor.WriteMessage("\nSelection Error: Other.");
break;
case PromptStatus.Keyword:
dwg.Editor.WriteMessage("\nSelection Error: Keyword.");
break;
case PromptStatus.Modeless:
dwg.Editor.WriteMessage("\nSelection Error: Modeless.");
break;
default:
dwg.Editor.WriteMessage("\nSelection Error: Unknown.");
break;
}
}
}

To test it:

1. Compile the code in a test project
2. Start Acad
3. "Netload" the test project
4. Draw a closed polyline
5. Draw a few entities with the polygon, or crossed by the polygon
6. Zoom to extents to make sure entire polygon is viewable
7. issue Command "CSTest", then pick the polygon. You would see at command
line: "X object(s) selected."
8. Zoom in so that part of the polygon is out of view
9. Issed Command "CSTest", then pick the polygon. You may see at command
line: "Selection Error: Error", depending on how must you zoomed in.

The same behaviour is also with SelectWindowPolygon. I did not test it with
SelectWindow() and SelectWindowPolygon(), but if they behaves the same, it
won't supprise me.

Interstingly enough, I trid Acad built-in Select with polygon command
manually, that is, "Select->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.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 3 of 5 (1,490 Views)

Re: Editor.SelectWindowPolygon()/SelectCrossingPolygon() method: bug or by design?

10-15-2006 02:50 PM in reply to: *Norman Yuan
It is by design. The same issue in VisualLisp/VBA/ObjectARX.
*Norman Yuan
Message 4 of 5 (1,490 Views)

Re: Editor.SelectWindowPolygon()/SelectCrossingPolygon() method: bug or by design?

10-15-2006 09:42 PM in reply to: *Norman Yuan
OK, I test it with VBA code. The result is the same: if you zoomed in to
certain degree (i.e. the selecting polygon is partly outside of current
view), Acad will not find entities inside th selecting polygon. But you
never know exactly when or zooed in how much the SelectByPolyGon (in VBA) or
SelectCrossingPolygon() (in .NET API) will fail. To garantee your code to
work, you have to make sure the polygon is ENTIRELY within the current view.

I probably have to admit that it is "BY DESIGN", although, if you manuall
issue commad "SELECT->CPolygon" and before your last pick of the polygon's
point, you zoom in very much so that the large part of the selecting polygon
is outside of current view, you still get CORRECT result, as you expected!
So, the "BY DESIGN" trick is really designed to fool programmers, who have
no way to know this "By Design" shortcomming until they were trapped in it
and struggled with their code debugging.


wrote in message news:5362272@discussion.autodesk.com...
It is by design. The same issue in VisualLisp/VBA/ObjectARX.
*Alexander Rivilis
Message 5 of 5 (1,490 Views)

Re: Editor.SelectWindowPolygon()/SelectCrossingPolygon() method: bug or by design?

10-16-2006 07:55 AM in reply to: *Norman Yuan
Hi, Norman Yuan!

[Sorry, skipped]
NY> So, the "BY DESIGN" trick is really designed to
NY> fool programmers, who have no way to know this "By Design" shortcomming
NY> until they were trapped in it and struggled with their code debugging.
[Sorry, skipped]

It was "BY DESIGN" in all previous versions of AutoCAD. Remember description of
that was in AutoCAD R10 or R12. You using functions - analoges of (ssget "_CP" ...) and
(ssget "_WP" ...) in VisualLisp. All variants of (ssget) function except (ssget "_X" ...)
working _ONLY_ with visible on screen objects.
That is why SelectWindowPolygon()/SelectCrossingPolygon() also working only
with visible on screen objects.

Best Regards,
Alexander Rivilis.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.