Selection Set does not return the same set everytime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What I am trying to do:
Get all the objects that are within a certain 'tolerance' distance from a line.
How I am trying to do this:
Step 1: Store all necessary information about the lines in which I am interested in a custom data type called 'dataLine'. Among the information that i am storing are the handle, x and y coordinates of start and end points.
Step 2: Make a bounding rectangle using the start and end coordinates of the line.
Step 3: Clear the Selectionset. Use Selectionset 's SelectByPolygonmethod with acSelectionSetCrossingPolygon mode and using the bounding rectangle created in the previous step as input to get the objects crossing the bounding rectangle.
Step 4: Loop through the selection set, and after necessary logical tests take appropriate actions.
What is going wrong:
The program does not run exactly the same way every time event though I am not changing anything on the drawing. When I say it does not run the same way I mean that Step 3 does not return the exact same set of objects when the same bounding rectangle co-ordinates are supplied and nothing is changed on the drawing in two different runs. I have verified this by saving to a text file the supplied bounding rectangle co-ordinates and the selection set returned in step 3 in two different runs and then compared them via notepad++. (See the debugging option portion of the code below)
The only change to the drawing that I make between each run is that at the end of each run i highlight all the lines that did not have any objects crossing its bounding rectangle.
This is a minimal version of the code:
writeSelSect =True
'Loop through the lines For ii = 0 To UBound(dataLine) sp = dataLine(ii).xy_start ep = dataLine(ii).xy_end
' Points Array is a 0 to 11 array that has the 3-D coordinates of the 4 corners of the bounding rectangle makeBoundingRectangle sp(0), ep(0), sp(1), ep(1), pointsArray ssetObj.Clear ssetObj.SelectByPolygon acSelectionSetCrossingPolygon, pointsArray
' Debugging option If writeSelSect Then ssetStr = "Line " & ii & ": " boundaryString = "Line " & ii & ": " For Each pp1 In pointsArray boundaryString = boundaryString & pp1 & ":" Next Print #fileoutnum, boundaryString End If
' Loop through the selection set For jj = 0 To ssetObj.count - 1 'Debuggin option If writeSelSect Then If TypeOf ssetObj.Item(jj) Is AcadBlockReference Then ssetStr = ssetStr & ssetObj.Item(jj).EffectiveName & "," Else ssetStr = ssetStr & TypeName(ssetObj.Item(jj)) & "," End If End If ' Do other logical checks on each object Next 'Print the result out to a line If writeSelSect Then Print #fileoutnum, ssetStr End If Next
close #fileoutnum
This is a screenshot from notepad compare between two different runs:
File on the left and the right are from two different runs.
For each line XX following information is returned:
- Line XX: all the coordinates that were supplied as the input for the ssetObj.SelectByPolygon method
- Line XX : all the objects that are returned.
Notice that for lines 70 to 73, the objects returned by selection set are not the same, even though I am giving the same bounding rectangle input (Notepad++ would highlight if the lines with co-ordinates were different). For instance, in line 70, in first run the selectbypolygon method did not return "Led_Logic" block but in the second run it did return "Led_Logic" for same return bounding rectangle input.
Any suggestions on what could be the reason behind this?