Jump to content

Selection Set Crossing Issue


abraxus

Recommended Posts

i'll first give a code snippet

 

    For Each ent In ssText
     pt1(0) = ent.InsertionPoint(0) - 3
     pt1(1) = ent.InsertionPoint(1) - 3
     pt2(0) = ent.InsertionPoint(0) + 3
     pt2(1) = ent.InsertionPoint(1) + 3
     On Error Resume Next
     ThisDrawing.SelectionSets("overlap").Delete
     On Error GoTo 0
     grpCode(0) = 8
     filterType = grpCode
     grpValue(0) = "STPL_Merch_Text"
     filterData = grpValue
     Set ssOverlap = ThisDrawing.SelectionSets.Add("overlap")
     ' filter by merch layer
     ssOverlap.Select acSelectionSetCrossing, pt1, pt2, filterType, filterData
     If ssOverlap.Count > 0 Then
       ent.Delete
     End If
   Next

in short, what i'm trying to do (and it works, kinda) is detect an mtext entity (on a different, specific layer) inserted in almost the same position as an existing mtext entitity (within a 3 inch radius) - and that's the part that works

 

but it only finds the mtext entities when they are within the current zoom window, the ones outside of the zoom arent detected

 

sure, the work around would be to just zoom extents before the detection, but that seems like a half-ass way of doing it - i'd rather try to understand why it's happening and fix it properly

 

without asking anyone to write code for me, could anyone give me a hint on why this would be happening? it makes no sense...

 

______

 

****, i just noticed that my 2nd "on error" (which was supposed to say "goto 0") said "resume next"

 

but now i cant test it til work tomorrow... ugh

 

still, if anyone has any ideas other than that...

Link to comment
Share on other sites

i'll first give a code snippet

 

    For Each ent In ssText
     pt1(0) = ent.InsertionPoint(0) - 3
     pt1(1) = ent.InsertionPoint(1) - 3
     pt2(0) = ent.InsertionPoint(0) + 3
     pt2(1) = ent.InsertionPoint(1) + 3
     On Error Resume Next
     ThisDrawing.SelectionSets("overlap").Delete
     On Error GoTo 0
     grpCode(0) = 8
     filterType = grpCode
     grpValue(0) = "STPL_Merch_Text"
     filterData = grpValue
     Set ssOverlap = ThisDrawing.SelectionSets.Add("overlap")
     ' filter by merch layer
     ssOverlap.Select acSelectionSetCrossing, pt1, pt2, filterType, filterData
     If ssOverlap.Count > 0 Then
       ent.Delete
     End If
   Next

in short, what i'm trying to do (and it works, kinda) is detect an mtext entity (on a different, specific layer) inserted in almost the same position as an existing mtext entitity (within a 3 inch radius) - and that's the part that works

 

but it only finds the mtext entities when they are within the current zoom window, the ones outside of the zoom arent detected

 

sure, the work around would be to just zoom extents before the detection, but that seems like a half-ass way of doing it - i'd rather try to understand why it's happening and fix it properly

 

without asking anyone to write code for me, could anyone give me a hint on why this would be happening? it makes no sense...

 

______

 

****, i just noticed that my 2nd "on error" (which was supposed to say "goto 0") said "resume next"

 

but now i cant test it til work tomorrow... ugh

 

still, if anyone has any ideas other than that...

 

 

To me it's a known issue that can be managed only by appropriate zooming.

A less "half-ass way" could be to zoom just the area of interest (if any) by some code like this one

 

 
element.GetBoundingBox minExt, maxExt ' define the area occupied by the element of interest
ZoomWindow minExt, maxExt ' zoom appropiately

 

and then do your ssOverlap

 

in some code of mine I did that with acSelectionSetWindowPolygon selection mode since I was interested only in elements that thoroughly lied within the relevant "box". maybe this doesn't match your today issue but for further issues I hereby give you that code snippet

 


element.GetBoundingBox minExt, maxExt ' define the area occupied by the element of interest
' enlarge appropriately the area, so as to involve elements on its border as well 
DX = (maxExt(0) - minExt(0)) * 0.001 ' 1/1000 box enlargement in X direction
DY = (maxExt(1) - minExt(1)) * 0.001 ' 1/1000 box enlargement in X direction
minExt(0) = minExt(0) - DX
minExt(1) = minExt(1) - DY
maxExt(0) = maxExt(0) + DX
maxExt(1) = maxExt(1) + DY

ZoomWindow minExt, maxExt ' zoom appropiately

'define polygonwindow to select elements within
ReDim pointsArray(0 To 3 * 4 - 1)
pointsArray(0) = minExt(0)
pointsArray(1) = minExt(1)
pointsArray(2) = 0#
pointsArray(3) = maxExt(0)
pointsArray(4) = minExt(1) 
pointsArray(5) = 0#
pointsArray(6) = maxExt(0)
pointsArray(7) = maxExt(1)
pointsArray( = 0#
pointsArray(9) = minExt(0) 
pointsArray(10) = maxExt(1)
pointsArray(11) = 0#

' Add to the selection set all the objects that thoroughly lie within the defined polygon 
mode = acSelectionSetWindowPolygon
ssetObj.SelectByPolygon mode, pointsArray, grpCode, dataVal

 

I one more stress that this work is worth only if you are interested in selecting elements that lie thoroughly within the window of interest. elements partially in and partially out of that window will not be selected.

 

and finally one question: it seems that your second selectionset (ssOverlap) will gather all elements type regardless they are of mtext type. is it correct?

 

bye

Link to comment
Share on other sites

I have had the same experience as RICVBA when selecting methods, it only works in the current graphics area and adopted a similar strategy to RICVBA, but I first zoomed all and after the selection zoomed previous to restore the original, it doesn't disturb the user that way. It is a known issue and one we have to live with.

 

I also noticed that you are selecting all entities on your named layer, you need to extend your filter to filter only MText entities.

 

BTW RICVBA welcome to the forum. A good post for your first. Tell us a little about yourself, location, discipline, experience, etc.

Link to comment
Share on other sites

I have had the same experience as RICVBA when selecting methods, it only works in the current graphics area and adopted a similar strategy to RICVBA, but I first zoomed all and after the selection zoomed previous to restore the original, it doesn't disturb the user that way. It is a known issue and one we have to live with.

 

I also noticed that you are selecting all entities on your named layer, you need to extend your filter to filter only MText entities.

 

BTW RICVBA welcome to the forum. A good post for your first. Tell us a little about yourself, location, discipline, experience, etc.

 

Thank tou Tyke

I'm from Parma, Italy. I work as head engineer for a precast company and we use Autocad for our dybyday design. I approached VBA some two years ago and found it very useful to link calculation with drawing as well as for improving drawing congruence and reducing labour time. Since now I've been peeping into various forums to learn from you people in there and eventually signed in when felt I could give something back. I hope that happened and will happen again. but, mainly, I hope that vba will still be supported in years to come.

bye

Link to comment
Share on other sites

Thank tou Tyke

I'm from Parma, Italy. I work as head engineer for a precast company and we use Autocad for our dybyday design. I approached VBA some two years ago and found it very useful to link calculation with drawing as well as for improving drawing congruence and reducing labour time. Since now I've been peeping into various forums to learn from you people in there and eventually signed in when felt I could give something back. I hope that happened and will happen again. but, mainly, I hope that vba will still be supported in years to come.

bye

 

I didn't even load VBA on the previous few release of AutoCAD. I thought it best to remove the temptation, especially since it's future looked grim. It forced me to focus on C#. I'm feeling pretty good there, now, and VBA is showing some staying power. DotNet comfort level aside, VBA development will always be faster (alas, I do not know AutoLisp). It looks like it is time to load VBA back on the system.

Link to comment
Share on other sites

Thanks everyone for your input on this matter, it's nice to know I'm not going crazy. And I see what you mean about doing a zoom extents, running the code, and then returning the user to their previous view - the drawing doesnt regen until the code is finished running, so the user will never see the zooming out, and it ensures the code works 100%

 

oh, and i guess i left that small mtext detail out - MTEXT is the only thing on the layer i'm using, so i dont technically need to add that to the selection set filter (good point tho!)

 

man, i love this site... lol

Link to comment
Share on other sites

Thanks everyone for your input on this matter, it's nice to know I'm not going crazy. And I see what you mean about doing a zoom extents, running the code, and then returning the user to their previous view - the drawing doesnt regen until the code is finished running, so the user will never see the zooming out, and it ensures the code works 100%

 

oh, and i guess i left that small mtext detail out - MTEXT is the only thing on the layer i'm using, so i dont technically need to add that to the selection set filter (good point tho!)

 

man, i love this site... lol

 

 

You are more than welcome.

 

The value of this site is the quality of its contributors :notworthy:

Link to comment
Share on other sites

The zooming problem is in Lisp as well and can be very frustrating when running code that works sometimes, till you get to know about the zoom problem. Rather than Z E I have used a zoom scale this is quick and dirty as you you know roughly how big an area you need to view.

 

Because your using filters it probably wont affect but often you need to set Osnaps to off sometimes to stop it picking wrong objects.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...