Model Space Zoom level effects SelectCrossingWindow selection Set value.

oneMSN
Advocate
Advocate

Model Space Zoom level effects SelectCrossingWindow selection Set value.

oneMSN
Advocate
Advocate

I am using a SelectCrossingWindow to select entities close to a given point. But I got a curious bug if I have Model space zoomed out.

 

If the zoom level is not too great my method to find the entities works fine. But if I zoom model space out so everything is tiny and run my command I get multiple result in my selection set that I did not expect.

How should I modify my SelectCrossingWindow Pt1 and Pt2 values to account for the level of zoom in the current model space view?

 

My current extension method that does the selection for me:

 

public static IEnumerable<BlockReference> GetBlocksConnectedToPolylineAtEndpoint(this Database database, Point3d polylinePoint, bool isStartPoint)
{
    ThrowForNoTransaction(database);
    // Define crossing window dimensions.
    Point3d botLeft;
    Point3d topRight;
    if (isStartPoint)
    {
        botLeft = new Point3d(polylinePoint.X - 1, polylinePoint.Y - 1, 0);
        topRight = new Point3d(polylinePoint.X + 5.9, polylinePoint.Y + 1, 0);
    }
    else
    {
        botLeft = new Point3d(polylinePoint.X - 5.9, polylinePoint.Y - 1, 0);
        topRight = new Point3d(polylinePoint.X + 1, polylinePoint.Y + 1, 0);
    }

    var selectWindowResult = ActiveDocument.Editor.SelectCrossingWindow(botLeft, topRight);
    if (selectWindowResult.Status == PromptStatus.OK)
    {
        var selectionSet = selectWindowResult.Value;
        Debug.WriteLine($"DB_Extensions::GetBlocksConnectedToPolylineAtPoint identified {selectionSet.Count} related blocks");

        return selectionSet.GetObjectIds()
            .Where(oId => oId.ObjectClass.IsDerivedFrom(AutocadRxClassTypes.RX_BlockReferenceType))
            .Select(oId => (BlockReference)oId.GetObject(OpenMode.ForRead))
            .Where(br => BlockLibraryManager.Current.IsBlockLibraryBlock(br));

    }
    return Enumerable.Empty<BlockReference>();
}
0 Likes
Reply
Accepted solutions (1)
642 Views
3 Replies
Replies (3)

ActivistInvestor
Advisor
Advisor
Accepted solution

@oneMSN wrote:

I am using a SelectCrossingWindow to select entities close to a given point. But I got a curious bug if I have Model space zoomed out.

 

If the zoom level is not too great my method to find the entities works fine. But if I zoom model space out so everything is tiny and run my command I get multiple result in my selection set that I did not expect.

 


Graphical selection (window, crossing, fence, and picking a point) uses display geometry to find objects. Display geometry and the space it is in, is not a double-precision floating-point world. Put more simply, graphical selection is only accurate to one display pixel, the size of which in model space units, depends on the view magnification. So, the further out you are zoomed, the greater the size of one display pixel is in model space units. Any object whose display geometry falls within a single display pixel of the crossing/window box, will be selected, and that can include objects that are actually not within the box you started with, whose coordinates are expressed in model space units.

 

It's probably better to not rely on graphical selection if you can. If you have to use it, you may have to disqualify selected objects after the fact using more analytical means. What you find in the CrossingOrWindowSelectedObjects that appear in a selection set might be helpful for disqualifying objects. You might need to set the PrepareOptionalDetails property of the PromptSelectionOptions to get them, and you will have to try to cast each SelectedObject to a CrossingOrWindowSelectedObject in order to use them.

 

 

oneMSN
Advocate
Advocate

Yeah I was beginning to figure as much.

I had previously been enumerating all blocks in the drawing and filtering by their bounds value. But I thought using a crossing window would be more performant. Maybe I need to use a combination. Or go back to the way I was doing it at first.  I will need to do some tests and see what is the fastest way.

 

Thanks.

0 Likes

norman.yuan
Mentor
Mentor

This is by-design/known behaviour with Editor.SelectWindow[Polygon]()/SelectCrossingWindow[Polygon](). Well, I say "known", it may not be that well known to many who have not stayed with AutoCAD programming long enough, because of the poor API documentation.

 

When use these SelectXXXXX() methods, at least 2 things to know:

 

1. the selecting window/polygon MUST be limited in the current view. That is, if one or more of the window/polygon points are beyond the current view, the returned selectionset might not be as expected.

 

2. If the window/polygon's points are among a very crowded entities to be selected and the view is zoomed out too far, the returned selectionset might not be as expected, as you have already observed.

 

These methods are the API translation of AutoCAD design for user doing the selecting on screen, which is meant for user interaction. When user selecting on screen, the accuracy of pick is limited by the hardware (screen, mouse). AutoCAD has to translate screen coordinate into drawing DB coordinate...

 

The same limitation also applies to VBA's AcadSelectionSet.SelectXXXX() methods.

 

So, when using SelectWindow/Polygon(), it would be better to zoom the view to the selecting window/polygon (or even zoom out a little bit, so the view is slightly bigger than the window/polygon) before calling the method. If the selecting area is very crowded and the area is huge (thus you have to zoom out very far to make the area within the view, then it would better avoid using these methods and try other approach.

Norman Yuan

Drive CAD With Code

EESignature