Help with Selection set in VB

Help with Selection set in VB

Anonymous
Not applicable
719 Views
9 Replies
Message 1 of 10

Help with Selection set in VB

Anonymous
Not applicable
Ok, here is the story, I have copied this piece of code from this same forum & I’m using it in VB NOT VBA, (it works fine under AutoCAD VBA) for some odd reason some stuff won’t work. I have noted the things that aren’t working on the code. Thanks in advance for your help.

William


Dim SelSet As AcadSelectionSet

Dim FilterType(0 To 0) As Integer

Dim FilterData(0 To 0) As Object

Dim blk As AcadEntity


AcadDoc.SelectionSets.Add("SelSet")

*-*-*-* ‘I GET THE SQUIGLEE LINES HERE-*-*-*-*
SelSet = AcadDoc.SelectionSets("SelSet")

SelSet.Clear()



FilterType(0) = 0

FilterData(0) = "INSERT"


*-*-*-* ‘I GET AN INVALID FILTERTYP OR FILTERDATA -*-*-*-*
SelSet.Select(AcSelect.acSelectionSetAll, , , FilterType, FilterData)
'SelSet.SelectOnScreen(FilterType, FilterData)



If SelSet.Count = 0 Then Exit Sub

For Each blk In SelSet

MsgBox(blk.ObjectName)

Next
0 Likes
720 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
FilterData(0 to 0) must be Variant, not Object

These could be all sorts of things, but I don't think an Object would ever
be an appropriate value. Could be a layer name (string), any type of
numeric value, etc.

If you're having trouble understanding that part and you're not familiar
with DXF format, you may want to browse through the DXF Reference section,
particularly the Entities section. It would probably help in understanding
how the FilterType/FilterData arrays actually work.

wrote in message news:[email protected]...
Ok, here is the story, I have copied this piece of code from this same forum
& I'm using it in VB NOT VBA, (it works fine under AutoCAD VBA) for some odd
reason some stuff won't work. I have noted the things that aren't working on
the code. Thanks in advance for your help.

William


Dim SelSet As AcadSelectionSet

Dim FilterType(0 To 0) As Integer

Dim FilterData(0 To 0) As Object

0 Likes
Message 3 of 10

Anonymous
Not applicable
Tom, VB does not have a Variant type. The Object, in this case, is
correct.....


"TomD" wrote in message
news:[email protected]...
FilterData(0 to 0) must be Variant, not Object

These could be all sorts of things, but I don't think an Object would ever
be an appropriate value. Could be a layer name (string), any type of
numeric value, etc.

If you're having trouble understanding that part and you're not familiar
with DXF format, you may want to browse through the DXF Reference section,
particularly the Entities section. It would probably help in understanding
how the FilterType/FilterData arrays actually work.

wrote in message news:[email protected]...
Ok, here is the story, I have copied this piece of code from this same forum
& I'm using it in VB NOT VBA, (it works fine under AutoCAD VBA) for some odd
reason some stuff won't work. I have noted the things that aren't working on
the code. Thanks in advance for your help.

William


Dim SelSet As AcadSelectionSet

Dim FilterType(0 To 0) As Integer

Dim FilterData(0 To 0) As Object

0 Likes
Message 4 of 10

Anonymous
Not applicable
You beat me to it. VB Express got rid of a Variant type and replaced it with an Object.
0 Likes
Message 5 of 10

Anonymous
Not applicable
I'm going to guess that since you said "SQUIGLEE" you're not in VB or VBA
but rather VB.NET?

Sounds like your AcadDoc object is not instantiated.

wrote in message news:[email protected]...
Ok, here is the story, I have copied this piece of code from this same forum
& I'm using it in VB NOT VBA, (it works fine under AutoCAD VBA) for some odd
reason some stuff won't work. I have noted the things that aren't working on
the code. Thanks in advance for your help.

William


Dim SelSet As AcadSelectionSet

Dim FilterType(0 To 0) As Integer

Dim FilterData(0 To 0) As Object

Dim blk As AcadEntity


AcadDoc.SelectionSets.Add("SelSet")

*-*-*-* 'I GET THE SQUIGLEE LINES HERE-*-*-*-*
SelSet = AcadDoc.SelectionSets("SelSet")

SelSet.Clear()



FilterType(0) = 0

FilterData(0) = "INSERT"


*-*-*-* 'I GET AN INVALID FILTERTYP OR FILTERDATA -*-*-*-*
SelSet.Select(AcSelect.acSelectionSetAll, , , FilterType,
FilterData)
'SelSet.SelectOnScreen(FilterType, FilterData)



If SelSet.Count = 0 Then Exit Sub

For Each blk In SelSet

MsgBox(blk.ObjectName)

Next
0 Likes
Message 6 of 10

Anonymous
Not applicable
Thank you both and my sincerest apologies for the misleading answer.

.....Maybe I should be looking into VB Express?

wrote in message news:[email protected]...
You beat me to it. VB Express got rid of a Variant type and replaced it with
an Object.
0 Likes
Message 7 of 10

Anonymous
Not applicable
Here is the first part of the code that was not included in the origina post.

Dim acadApp As AcadApplication
Dim AcadDoc As AcadDocument
Dim AcadObj As AcadObject
Dim BlockRef As AcadBlockReference

Try
acadApp = GetObject(, "AutoCAD.Application")
Catch
acadApp = CreateObject("AutoCAD.Application")
End Try

AcadDoc = acadApp.ActiveDocument
0 Likes
Message 8 of 10

Anonymous
Not applicable
In VB.Net the Integer is now a 32 bit integer where Acad is expecting a 16
bit integer.....try this:
Dim FilterType(0) As Int16

wrote in message news:[email protected]...
Here is the first part of the code that was not included in the origina
post.

Dim acadApp As AcadApplication
Dim AcadDoc As AcadDocument
Dim AcadObj As AcadObject
Dim BlockRef As AcadBlockReference

Try
acadApp = GetObject(, "AutoCAD.Application")
Catch
acadApp = CreateObject("AutoCAD.Application")
End Try

AcadDoc = acadApp.ActiveDocument
0 Likes
Message 9 of 10

Anonymous
Not applicable
Also, you could use Short in lieu of Int16...

"Jeff Mishler" wrote in message
news:[email protected]...
In VB.Net the Integer is now a 32 bit integer where Acad is expecting a 16
bit integer.....try this:
Dim FilterType(0) As Int16
0 Likes
Message 10 of 10

Anonymous
Not applicable
Thanks Jeff & others for the suggestions. Your solution fixed the problem. "Int16"
0 Likes