strange behavior in creating selectionset

strange behavior in creating selectionset

a.kouchakzadeh
Advocate Advocate
700 Views
4 Replies
Message 1 of 5

strange behavior in creating selectionset

a.kouchakzadeh
Advocate
Advocate

I have noticed a strange behavior while creating a selection set. my program gets two corners of a rectangle to create a window selectionset, then passes the two points to another method to create the selection set. but the user has to pick an object fist, so the program could find out whats the type of the object to make its filter, also to find out the layer that it has to filter.

whats strange is, this is the window that Im selecting:

akouchakzadeh_0-1654010384163.png

then I zoom in to pick a block object,

akouchakzadeh_1-1654010444166.png

surprisingly, the operation which in my case is trimming the lines inside the blocks, only trims the lines which are seen on the zoomed screen! I even added a watch on my selection set and noticed that

var selectionResult =  ed.SelectWindow(firstCorner, secondCorner,selectionFilter) does not care about the specified corners and instead uses the zoomed window cordination instead!

I think, I had the same issue with VBA?! I'm not sure though.

how can I fix this problem?

 

private static SelectionSet CreateSelectionSet(Document doc, string objectType
            , List<Point3d> pointList, Type type)
        {
            var ed = doc.Editor;
            var db = doc.Database;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                Entity entity = null;
                string objectLayer = "SPRKVIEW";
                var strType = type.ToString().Substring(34, type.ToString().Length-34);
                try
                {
                    if ((objectType.ToUpper()=="LINE" || objectType.ToUpper()=="INSERT"))
                    {
                        var peo = new PromptEntityOptions("\nSelect a " + strType +
                            " represting the desired object");
                        peo.SetRejectMessage("\nNot a valid Object! Select a " + strType);
                        peo.AddAllowedClass(type , true);
                        peo.AllowNone=true;
                        peo.AllowObjectOnLockedLayer=true;
                        var res = ed.GetEntity(peo);

                        entity = tr.GetObject(res.ObjectId, OpenMode.ForRead) as Entity;
                        if (res.Status != PromptStatus.OK)
                        {
                            tr.Abort();
                            return null;
                        }
                        objectLayer = entity.Layer;
                    }

                    var firstCorner = pointList[0];
                    var secondCorner = pointList[1];
                    var filterValue = new TypedValue[2];
                    filterValue.SetValue(new TypedValue((int)DxfCode.Start, objectType), 0);
                    filterValue.SetValue(new TypedValue((int)DxfCode.LayerName, objectLayer), 1);

                    var selectionFilter = new SelectionFilter(filterValue);
                    var selectionResult = ed.SelectWindow(firstCorner, secondCorner, selectionFilter);
                    var selectionSet = selectionResult.Value as SelectionSet;

                    if (selectionSet!=null)
                    {
                        tr.Commit();
                        return selectionSet;
                    }
                    else
                    {
                        tr.Abort();
                        return null;
                    }
                    
                }
                catch (System.Exception ex)
                {
                    Application.ShowAlertDialog("Error occured: " + ex.Message);
                    return null;
                }
            }
        }
0 Likes
Accepted solutions (2)
701 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Yes, what you observed in both VBA and .NET API is the limitation of using Editor.Select[Crossing/Polygon/Window]() (.NET) and AcadSelectionSet.Select(acSelectionSetWindow/Crossing/Polygon, ...) methods: the selecting window/polygon must be within the current view. So, before you call Edotor.SelectWindow(), you need to make sure the window is visibly with in the current view. Usually, you zoom out to the window/polygon before calling Editor.SelectWindow[Polygon](). 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

a.kouchakzadeh
Advocate
Advocate

thanks for your reply Mr. Yuan, but now Im stuck with the zoom function. am I doing some thing wrong or is it really this complicated?

Giles in this post uses acadApp.ZoomExtents() but its not working for me?

when I type acadApp... I cant see the intellisense. 

Im trying to Zoomwindow and then zoom previous.

 

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Because it was calling AutoCAD COM API with late binding (dynamic in C#), thus not intellisense.

to call COM API's ZoomWindow(), you simply:

 

dynamic cadApp=Application.AcadApplication

var double[] point1=new[]{0.0,0.0,0.0}; // use your own winodow's lowerleft corner and upperright corner

var double[] point2=new[]{100,100,0};

cadApp.ZoomWindow(point1, point2);

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

a.kouchakzadeh
Advocate
Advocate

many thanks sir!

0 Likes