- 积分
- 512
- 明经币
- 个
- 注册时间
- 2005-12-26
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2012-1-22 12:18:15
|阅读模式
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.D​ocumentManager.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.
真是坑爹,刚好遇到这个问题,害的我调试了很久,原来真的如上所说这样。
|
|