Get a selections set... why does this work?

Get a selections set... why does this work?

mdhutchinson
Advisor Advisor
606 Views
17 Replies
Message 1 of 18

Get a selections set... why does this work?

mdhutchinson
Advisor
Advisor
I pain stakingly wrote this code and it works ... but, I am not fully sure just why with confidence enough to add commentary to it... can someone assist?

Public Function getPolyLineBlockCorrals() As AcadSelectionSet
Dim FilterType(0 To 2) As Integer
Dim FilterData(0 To 2) As Variant

FilterType(0) = 8
FilterData(0) = "ContNum"
FilterType(1) = 0
FilterData(1) = "INSERT"
FilterType(2) = 2
FilterData(2) = "`*U*"

On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("test2corrals")
If Err Then Set objSS = ThisDrawing.SelectionSets.Add("test2corrals")
objSS.Select acSelectionSetAll, , , FilterType, FilterData
Set getPolyLineBlockCorrals = objSS
End Function
0 Likes
607 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable
You are creating two arrays that form the required parts to a filtered
selection set.

One array holds the DXF codes for the filter.
The other array holds the actual values for each of the DXF codes.

You are filtering for a layer (8) named "ContNum", objects (0) that are
inserts (BlockReferences), and are named (2) as anonymous. The last filter
is likely a problem-spot. Dynamic blocks that have been altered from their
default look will be anonymous. But DBlocks that are reset or in their
original condition will still have the default block name.

You will skip the error that will occur when a named selection set does not
already exist. You next attempt to get the existing selection set. If that
failed, the On Error Resume Next allows the next line to run, which checks
if there was an error, and if so, creates a new selection set.

You then create the selection set, using the filter you created. Finally,
you return the selection set to the calling procedure.

--
R. Robert Bell


wrote in message news:5419353@discussion.autodesk.com...
I pain stakingly wrote this code and it works ... but, I am not fully sure
just why with confidence enough to add commentary to it... can someone
assist?

Public Function getPolyLineBlockCorrals() As AcadSelectionSet
Dim FilterType(0 To 2) As Integer
Dim FilterData(0 To 2) As Variant

FilterType(0) = 8
FilterData(0) = "ContNum"
FilterType(1) = 0
FilterData(1) = "INSERT"
FilterType(2) = 2
FilterData(2) = "`*U*"

On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("test2corrals")
If Err Then Set objSS = ThisDrawing.SelectionSets.Add("test2corrals")
objSS.Select acSelectionSetAll, , , FilterType, FilterData
Set getPolyLineBlockCorrals = objSS
End Function
0 Likes
Message 3 of 18

mdhutchinson
Advisor
Advisor
The getPolyLineBlockCorrals shown in my initial post works consistently... but the following similar code from the same application does not...
I am having trouble figuring out just why?

Public Function getMarkBlksFromCorral(Vertices As Variant) As AcadSelectionSet
' this function gets the all the MarkBlks from the block corrals and returns a selection set

Dim FilterType(0 To 2) As Integer ' set up a 2x2 array filter
Dim FilterData(0 To 2) As Variant ' for the mark blocks

FilterType(0) = 8 ' layer dxf group code
FilterData(0) = "Pc-Mark" ' The "Pc-Mark" layer
FilterType(1) = 100 ' object type dxf group code
FilterData(1) = "AcDbBlockReference" ' a block
FilterType(2) = 2 ' block name dxf group code
FilterData(2) = "pc-mark1" ' "pc-mark1"

' set up an error trap... check the selection set collection for a selectset
' referenced by the name "markblocks"
On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("markblocks")
If Err Then Set objSS = ThisDrawing.SelectionSets.Add("markblocks")
objSS.SelectByPolygon acSelectionSetCrossingPolygon, Vertices, FilterType, FilterData
Set getMarkBlksFromCorral = objSS
End Function
0 Likes
Message 4 of 18

Anonymous
Not applicable
SS filters do not recognize the 100 group code. Use 0 and "INSERT" in lieu
of the 100 and "AcDbBlockReference".

wrote in message news:5422985@discussion.autodesk.com...
The getPolyLineBlockCorrals shown in my initial post works consistently...
but the following similar code from the same application does not...
I am having trouble figuring out just why?

Public Function getMarkBlksFromCorral(Vertices As Variant) As
AcadSelectionSet
' this function gets the all the MarkBlks from the block corrals and returns
a selection set

Dim FilterType(0 To 2) As Integer ' set up
a 2x2 array filter
Dim FilterData(0 To 2) As Variant ' for
the mark blocks

FilterType(0) = 8 ' layer
dxf group code
FilterData(0) = "Pc-Mark" ' The
"Pc-Mark" layer
FilterType(1) = 100 ' object
type dxf group code
FilterData(1) = "AcDbBlockReference" ' a
block
FilterType(2) = 2 ' block
name dxf group code
FilterData(2) = "pc-mark1" '
"pc-mark1"

' set up an error trap... check the selection set collection for a selectset
' referenced by the name "markblocks"
On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("markblocks")
If Err Then Set objSS = ThisDrawing.SelectionSets.Add("markblocks")
objSS.SelectByPolygon acSelectionSetCrossingPolygon, Vertices,
FilterType, FilterData
Set getMarkBlksFromCorral = objSS
End Function
0 Likes
Message 5 of 18

mdhutchinson
Advisor
Advisor
ooh... I would have figured that it would work with 100 dxf group code... hmm...

Okay... I changed it but it still doesnt find the matching blocks... it doesn't error out either it just doesn't collect the blocks. (see the below corrected code.)

I checked the vertices... and they look right.
The vertices form 4 points of a rectangle...
... this looks right... but it doesn't place the blocks into the select set.

What could I be missing?

Public Function getMarkBlksFromCorral(Vertices As Variant) As AcadSelectionSet
' this function gets the all the MarkBlks from the block corrals and returns a selection set

Dim FilterType(0 To 2) As Integer ' set up a 2x2 array filter
Dim FilterData(0 To 2) As Variant ' for the mark blocks

FilterType(0) = 8 ' layer dxf group code
FilterData(0) = "Pc-Mark" ' The "Pc-Mark" layer
FilterType(1) = 0 ' object type dxf group code
FilterData(1) = "INSERT" ' a block
FilterType(2) = 2 ' block name dxf group code
FilterData(2) = "pc-mark1" ' "pc-mark1"

' set up an error trap... check the selection set collection for a selectset
' referenced by the name "markblocks"
On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("markblocks")
If Err Then Set objSS = ThisDrawing.SelectionSets.Add("markblocks")
objSS.SelectByPolygon acSelectionSetCrossingPolygon, Vertices, FilterType, FilterData
Set getMarkBlksFromCorral = objSS
End Function

The lisp data is as follows for one of the blocks I need to collect:
(entget (car (entsel)))

Select object: ((-1 . ) (0 . "INSERT") (330 . ) (5 . "EF3DD") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "Pc-Mark") (48 . 0.5) (100 . "AcDbBlockReference") (66 . 1) (2 . "pc-mark1")
(10 2015.11 -14495.7 0.0) (41 . 48.0) (42 . 48.0) (43 . 48.0) (50 . 0.0) (70 .
0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
0 Likes
Message 6 of 18

Anonymous
Not applicable
Are the objects visible on screen?

--
R. Robert Bell


wrote in message news:5423065@discussion.autodesk.com...
ooh... I would have figured that it would work with 100 dxf group code...
hmm...

Okay... I changed it but it still doesnt find the matching blocks... it
doesn't error out either it just doesn't collect the blocks. (see the below
corrected code.)

I checked the vertices... and they look right.
The vertices form 4 points of a rectangle...
... this looks right... but it doesn't place the blocks into the select set.

What could I be missing?

Public Function getMarkBlksFromCorral(Vertices As Variant) As
AcadSelectionSet
' this function gets the all the MarkBlks from the block corrals and returns
a selection set

Dim FilterType(0 To 2) As Integer ' set up
a 2x2 array filter
Dim FilterData(0 To 2) As Variant ' for
the mark blocks

FilterType(0) = 8 ' layer
dxf group code
FilterData(0) = "Pc-Mark" ' The
"Pc-Mark" layer
FilterType(1) = 0 ' object
type dxf group code
FilterData(1) = "INSERT" ' a
block
FilterType(2) = 2 ' block
name dxf group code
FilterData(2) = "pc-mark1" '
"pc-mark1"

' set up an error trap... check the selection set collection for a selectset
' referenced by the name "markblocks"
On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("markblocks")
If Err Then Set objSS = ThisDrawing.SelectionSets.Add("markblocks")
objSS.SelectByPolygon acSelectionSetCrossingPolygon, Vertices,
FilterType, FilterData
Set getMarkBlksFromCorral = objSS
End Function

The lisp data is as follows for one of the blocks I need to collect:
(entget (car (entsel)))

Select object: ((-1 . ) (0 . "INSERT") (330 .
name: 7efcccf8>) (5 . "EF3DD") (100 . "AcDbEntity") (67 . 0) (410 . "Model")
(8 . "Pc-Mark") (48 . 0.5) (100 . "AcDbBlockReference") (66 . 1) (2 .
"pc-mark1")
(10 2015.11 -14495.7 0.0) (41 . 48.0) (42 . 48.0) (43 . 48.0) (50 . 0.0) (70
..
0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
0 Likes
Message 7 of 18

mdhutchinson
Advisor
Advisor
Yes...
I was wondering this also... and I checked.
... I also was looking at if my application dialog box covered up the objects and if somehow this was hosing it...
But code in the initial post works as well except that it doesn't use the selectbypolygon method.
0 Likes
Message 8 of 18

Anonymous
Not applicable
I think it boiled down to your argument name.

Sub Test()
Dim myPts(0 To 7) As Double
myPts(0) = 0: myPts(1) = 0
myPts(2) = 11: myPts(3) = 0
myPts(4) = 11: myPts(5) = 8.5
myPts(6) = 0: myPts(7) = 8.5

If getMarkBlksFromCorral(myPts) Then
MsgBox ThisDrawing.SelectionSets.Item("markblocks").Count & " blocks
found!"
End If
End Sub

Public Function getMarkBlksFromCorral(pPoints As Variant) As Boolean
' This function gets the all the MarkBlks from the block corrals and returns
True if selection set made
Dim fType(0 To 2) As Integer ' set up a
3-element array filter
Dim fData(0 To 2) As Variant ' for the mark
blocks

fType(0) = 0: fData(0) = "INSERT" ' blocks only
fType(1) = 2: fData(1) = "Titleline" ' specific block name
fType(2) = 8: fData(2) = "0" ' specific layer

' set up an error trap... check the selection set collection for a selectset
' referenced by the name "markblocks"
On Error Resume Next
Dim mySS As AcadSelectionSet
Set mySS = ThisDrawing.SelectionSets("markblocks")
If Err Then Set mySS = ThisDrawing.SelectionSets.Add("markblocks")
mySS.SelectByPolygon acSelectionSetCrossingPolygon, pPoints, fType, fData
If mySS.Count > 0 Then getMarkBlksFromCorral = True
End Function


--
R. Robert Bell


wrote in message news:5423074@discussion.autodesk.com...
Yes...
I was wondering this also... and I checked.
... I also was looking at if my application dialog box covered up the
objects and if somehow this was hosing it...
But code in the initial post works as well except that it doesn't use the
selectbypolygon method.
0 Likes
Message 9 of 18

mdhutchinson
Advisor
Advisor
so... 'Vertices As Variant'
won't work... ?
does the ... As Variant ... need to be there?

Can the argument have a different name from the one used where the function is called?
0 Likes
Message 10 of 18

mdhutchinson
Advisor
Advisor
I still cannot get it to fill the section set...

I wonder if there is some picularitity that prevents SelectByPolygon from working if a modeless dialog is acitve?
... the other function from my initial post works even though the dialog is modeless.
... how can I temporarily hide the dialog while the SelectByPolygon is running?
0 Likes
Message 11 of 18

mdhutchinson
Advisor
Advisor
I tried hiding the dialog but still doesn't work.
What could be wrong?
0 Likes
Message 12 of 18

Anonymous
Not applicable
Did you try my sample code? Just change the block name and layer name.

--
R. Robert Bell


wrote in message news:5423139@discussion.autodesk.com...
so... 'Vertices As Variant'
won't work... ?
does the ... As Variant ... need to be there?

Can the argument have a different name from the one used where the function
is called?
0 Likes
Message 13 of 18

mdhutchinson
Advisor
Advisor
yes I did try it... I worked it into my application... but still didn't get the result I need ...

I really want to thank you for your help... you've given me hope that I can learn this stuff...

In the attached (another effort) I tried your code as is just as you specified and got the same result... please see the attached zip (a dwg file and RobertBell.dvb)

can you get it to work on this dwg file?
0 Likes
Message 14 of 18

Anonymous
Not applicable
Oops, it wasn't your argument name.

Your On Error Resume Next was concealing an error in the points variant.
That argument requires 3D points, not 2D.

[code]
Sub Test()
Dim myPts(0 To 11) As Double
myPts(0) = 0: myPts(1) = 0: myPts(2) = 0
myPts(3) = 11: myPts(4) = 0: myPts(5) = 0
myPts(6) = 11: myPts(7) = 8.5: myPts(8) = 0
myPts(9) = 0: myPts(10) = 8.5: myPts(11) = 0
If getMarkBlksFromCorral(myPts) Then
MsgBox ThisDrawing.SelectionSets.Item("markblocks").Count & " blocks
found! "
End If
End Sub

Public Function getMarkBlksFromCorral(pPoints As Variant) As Boolean
' This function gets the all the MarkBlks from the block corrals and
returns True if selection set made
Dim fType(0 To 2) As Integer ' set up a 3-element array filter
Dim fData(0 To 2) As Variant ' for the mark Blocks

fType(0) = 0: fData(0) = "INSERT" ' blocks only
fType(1) = 2: fData(1) = "TITLELINE" ' specific block name
fType(2) = 8: fData(2) = "CONTNUM" ' specific layer

' set up an error trap... check the selection set collection for a
selectset
' referenced by the name "markblocks"
On Error Resume Next
Dim mySS As AcadSelectionSet
Set mySS = ThisDrawing.SelectionSets("markblocks")
If Err Then Set mySS = ThisDrawing.SelectionSets.Add("markblocks")
On Error GoTo 0

mySS.SelectByPolygon acSelectionSetCrossingPolygon, pPoints, fType, fData
If mySS.Count > 0 Then getMarkBlksFromCorral = True
End Function
[/code]

--
R. Robert Bell


wrote in message news:5423327@discussion.autodesk.com...
yes I did try it... I worked it into my application... but still didn't get
the result I need ...

I really want to thank you for your help... you've given me hope that I can
learn this stuff...

In the attached (another effort) I tried your code as is just as you
specified and got the same result... please see the attached zip (a dwg file
and RobertBell.dvb)

can you get it to work on this dwg file?
0 Likes
Message 15 of 18

mdhutchinson
Advisor
Advisor
yes ... but my code has 3d points... I am certain.
What about the myPts variant... your code specifies it as a Double? ... anyway...
Looks like your code works now on my machine!

but I will look again at mine again.
0 Likes
Message 16 of 18

mdhutchinson
Advisor
Advisor
Please look at the attached image... perhaps you can see what is wrong with my code?
0 Likes
Message 17 of 18

Anonymous
Not applicable
Your problem is not here....it's how you define the array in the calling
Sub. THAT array must be defined as a Double......go back & note the
difference between your vertice collecting code vs. the RobertBell.dvb code



So an array of Doubles is passed as an argument to the
wrote in message news:5423445@discussion.autodesk.com...
Please look at the attached image... perhaps you can see what is wrong with
my code?
0 Likes
Message 18 of 18

mdhutchinson
Advisor
Advisor
Found it... and corrected...

So ... these two definitions are different?
Dim Vertices(0 To 11) As Variant
Dim Vertices(0 To 11) As Double

When used in SelectByPolygon method it must be defined as a Double? ... both these structures look quit similar...

I was thrown off a bit by page 330 of Joe S book that states it is the data type is a Variant composed of alternating X, Y, and Z values... correct I guess but not precisely

It now works... but, I have a lot left to do with this before it is finished. I suppose a good thing to do would be to save off a copy of the code as it stands now... and then start on the next step...
The vertices are taken from an anonymous block's extended data (built from my lisp application that puts them into the dwg)
... next step is to sort the blocks found from the SelectByPolygon method given the OCS of the anonymous block... (easier said then done I'm afraid - but I am going to try)

Thanks again for your help!
0 Likes