明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3308|回复: 1

Editor.SelectWindowPolygon问题

[复制链接]
发表于 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.

真是坑爹,刚好遇到这个问题,害的我调试了很久,原来真的如上所说这样。

发表于 2023-4-5 20:03:39 | 显示全部楼层
但是我的也放大了,可是还是有一部分选择不到,不知道是什么原因?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 21:23 , Processed in 0.175193 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表