Problems selection set

Problems selection set

Anonymous
Not applicable
125 Views
3 Replies
Message 1 of 4

Problems selection set

Anonymous
Not applicable
Hi,

I am having some problems using selection sets correctly.

I have written a function which is supposed to check and see if there is any
text within a given rectangle. Basically I am using this to make sure that
I don't write text over existing text, so when I create a new piece of text
I send the bounding box of the new text to this function - if there is
already text anywhere in the box then I either delete the potential new text
or move it somewhere else.

The problem is that the selection set does not work consistently. Sometimes
it never picks up anything in the crossing (even though I know there is text
in the crossing during debug) and sometimes is does work. I am guessing it
has something to do with the creation of the selection set object, resetting
and scope?

After the code fails sometimes in the same session it will suddenly work?
As well, I am not too experienced in the use of On Error ? Sometimes I get
an error indidcating that the selection set already exists so I inserted the
On Error line (which is now commented out).

Can anyone point me in the right direction?

Thanks,
Natan Elsberg

--------------------------------------
The function:

Public Function IsTextInRectangle(corner1 As Variant, corner2 As Variant) As
Boolean
Dim ssetObj As AcadSelectionSet
Dim aobject As AcadObject
Dim aline As AcadLine

'On Error Resume Next
Set ssetObj = oacadApp.ActiveDocument.SelectionSets.Add("zzzzSSET")
Dim bAnswer As Boolean
bAnswer = False
Dim mode As Integer
mode = acSelectionSetCrossing
ssetObj.Select acSelectionSetCrossing, corner1, corner2
'Set aline = moSpace.AddLine(corner1, corner2)
For Each aobject In ssetObj
If aobject.ObjectName = "AcDbText" Then bAnswer = True
Next
ssetObj.Delete
IsTextInRectangle = bAnswer
End Function
0 Likes
126 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
What happens if you omit the On Error Resume Next statement?

- Tom

Natan Elsberg wrote in message
news:F296CD1DBE41B848E4DF5AC7651C846B@in.WebX.SaUCah8kaAW...
> Hi,
>
> I am having some problems using selection sets correctly.
>
> I have written a function which is supposed to check and see if
there is any
> text within a given rectangle. Basically I am using this to make
sure that
> I don't write text over existing text, so when I create a new piece
of text
> I send the bounding box of the new text to this function - if there
is
> already text anywhere in the box then I either delete the potential
new text
> or move it somewhere else.
>
> The problem is that the selection set does not work consistently.
Sometimes
> it never picks up anything in the crossing (even though I know there
is text
> in the crossing during debug) and sometimes is does work. I am
guessing it
> has something to do with the creation of the selection set object,
resetting
> and scope?
>
> After the code fails sometimes in the same session it will suddenly
work?
> As well, I am not too experienced in the use of On Error ?
Sometimes I get
> an error indidcating that the selection set already exists so I
inserted the
> On Error line (which is now commented out).
>
> Can anyone point me in the right direction?
>
> Thanks,
> Natan Elsberg
>
> --------------------------------------
> The function:
>
> Public Function IsTextInRectangle(corner1 As Variant, corner2 As
Variant) As
> Boolean
> Dim ssetObj As AcadSelectionSet
> Dim aobject As AcadObject
> Dim aline As AcadLine
>
> 'On Error Resume Next
> Set ssetObj = oacadApp.ActiveDocument.SelectionSets.Add("zzzzSSET")
> Dim bAnswer As Boolean
> bAnswer = False
> Dim mode As Integer
> mode = acSelectionSetCrossing
> ssetObj.Select acSelectionSetCrossing, corner1, corner2
> 'Set aline = moSpace.AddLine(corner1, corner2)
> For Each aobject In ssetObj
> If aobject.ObjectName = "AcDbText" Then bAnswer = True
> Next
> ssetObj.Delete
> IsTextInRectangle = bAnswer
> End Function
>
0 Likes
Message 3 of 4

Anonymous
Not applicable
The select method of selectionsets works with the display list (that is,
the list of objects in the display) in stead of the real list of entities
in your drawing. If you can't see an object in the display, probably the
select method will not select it.
One option to solve this, which is more a workaround, is to use the command
ZoomExtents before you use ssetObj.select.
This is one of the unfortunally aspects of selection sets which limits the
use of it.

wkr, jwk

Natan Elsberg had the next bright idea:

>Hi,
>
>I am having some problems using selection sets correctly.
>
>I have written a function which is supposed to check and see if there is
>any text within a given rectangle. Basically I am using this to make
>sure that I don't write text over existing text, so when I create a new
>piece of text I send the bounding box of the new text to this function -
>if there is already text anywhere in the box then I either delete the
>potential new text or move it somewhere else.
>
>The problem is that the selection set does not work consistently.
>Sometimes it never picks up anything in the crossing (even though I know
>there is text in the crossing during debug) and sometimes is does work.
>I am guessing it has something to do with the creation of the selection
>set object, resetting and scope?
>
>After the code fails sometimes in the same session it will suddenly
>work? As well, I am not too experienced in the use of On Error ?
>Sometimes I get an error indidcating that the selection set already
>exists so I inserted the On Error line (which is now commented out).
>
>Can anyone point me in the right direction?
>
>Thanks,
>Natan Elsberg
[snip]
0 Likes
Message 4 of 4

Anonymous
Not applicable
jwk,

I checked it out and you are right!

I placed some text on my own where I knew my application would place text.
In those spots only the text did not appear.

Meaning that the text entities that I created previously in my procedure are
not recognized by the selection set!!!

I don't think a zoom extents would be appropriate to solve my problem (as
this routine may iterate hundreds of times). Any other thoughts?

Thanks,
Natan

jwk wrote in message
news:8FD8E8475aoposhotmailcom@167.216.240.240...
> The select method of selectionsets works with the display list (that is,
> the list of objects in the display) in stead of the real list of entities
> in your drawing. If you can't see an object in the display, probably the
> select method will not select it.
> One option to solve this, which is more a workaround, is to use the
command
> ZoomExtents before you use ssetObj.select.
> This is one of the unfortunally aspects of selection sets which limits the
> use of it.
>
> wkr, jwk
>
> Natan Elsberg had the next bright idea:
>
> >Hi,
> >
> >I am having some problems using selection sets correctly.
> >
> >I have written a function which is supposed to check and see if there is
> >any text within a given rectangle. Basically I am using this to make
> >sure that I don't write text over existing text, so when I create a new
> >piece of text I send the bounding box of the new text to this function -
> >if there is already text anywhere in the box then I either delete the
> >potential new text or move it somewhere else.
> >
> >The problem is that the selection set does not work consistently.
> >Sometimes it never picks up anything in the crossing (even though I know
> >there is text in the crossing during debug) and sometimes is does work.
> >I am guessing it has something to do with the creation of the selection
> >set object, resetting and scope?
> >
> >After the code fails sometimes in the same session it will suddenly
> >work? As well, I am not too experienced in the use of On Error ?
> >Sometimes I get an error indidcating that the selection set already
> >exists so I inserted the On Error line (which is now commented out).
> >
> >Can anyone point me in the right direction?
> >
> >Thanks,
> >Natan Elsberg
> [snip]
0 Likes