Selection Set in VB.Net

Selection Set in VB.Net

Anonymous
Not applicable
4,617 Views
9 Replies
Message 1 of 10

Selection Set in VB.Net

Anonymous
Not applicable
I trie to create as Selection set in VB.Net, if I do not use any filters it functions well, but when I trie to use the filter option I get an Error.

This is the code:

Friend Function SelectionSet_Create(ByVal Name As String, ByVal Point3dList() As Point3d, ByVal ObjectName As String) As AcadSelectionSet
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim SSObj As AcadSelectionSet
Dim SSmode As Autodesk.AutoCAD.Interop.Common.AcSelect
Dim PointsArray As Array = PointlistToArray(Point3dList)

Try
acadApp = CType(GetObject(, AutoCadApplicatie), AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True

SSObj = acadDoc.SelectionSets.Add(Name)
SSmode = Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetCrossingPolygon

If ObjectName "*" Then
Dim FilterType(0) As Integer : FilterType(0) = 2
Dim FilterData(0) As String : FilterData(0) = ObjectName
SSObj.SelectByPolygon(SSmode, PointsArray, FilterType, FilterData)
Else
SSObj.SelectByPolygon(SSmode, PointsArray)
End If

SSObj.Highlight(True)

Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message(vbCrLf & SSObj.Count & " Objects selected" + vbCrLf)

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return Nothing

End Try
End Function

And this is the error I get is attached.

What is going wrong ?

Harold van Aarsen
The Netherlands
0 Likes
4,618 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
I have replaced the text :

Dim FilterType(0) As Integer : FilterType(0) = 2
Dim FilterData(0) As String : FilterData(0) = ObjectName

with :

Dim FilterType() As Int16 = {2}
Dim FilterData() As Object = {"Hsb_DbElement"}

and now it functions well.
0 Likes
Message 3 of 10

Anonymous
Not applicable
There is a bug in the managed wrapper class.You can use my DOTNETARX library to use the filter option in Selection sets.
0 Likes
Message 4 of 10

Anonymous
Not applicable
I'm sorry,you use the com!You should replace
Dim FilterType(0) As Integer
with
Dim FilterType(0) As short
0 Likes
Message 5 of 10

Anonymous
Not applicable
You are right
0 Likes
Message 6 of 10

Anonymous
Not applicable
Hello, Harold!
What do you filter in your sample?
0 Likes
Message 7 of 10

Anonymous
Not applicable
In this case I wanted to select some HSBcad object, but the general goal was to create some functions wich I can use in more cases.

Beneath are the functions I created in VB.Net 2003

#Region " Selections Sets "

Friend Function SelectionSet_CreateWindow(ByVal Name As String, ByVal ObjectName As String) As AcadSelectionSet
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim SSObj As AcadSelectionSet
Try
acadApp = CType(GetObject(, AutoCadApplicatie), AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True

SSObj = acadDoc.SelectionSets.Add(Name)

Dim FilterType() As Int16 = {0}
Dim FilterData() As Object = {ObjectName}
SSObj.SelectOnScreen(FilterType, FilterData)

Return SSObj

Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message(vbCrLf & SSObj.Count & " Objects selected" + vbCrLf)

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return Nothing

End Try
End Function

Friend Function SelectionSet_CreateAll(ByVal Name As String, ByVal ObjectName As String) As AcadSelectionSet
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim SSObj As AcadSelectionSet
Try
acadApp = CType(GetObject(, AutoCadApplicatie), AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True

SSObj = acadDoc.SelectionSets.Add(Name)

Dim FilterType() As Int16 = {0}
Dim FilterData() As Object = {ObjectName}
SSObj.Select(AcSelect.acSelectionSetAll, , , FilterType, FilterData)

Return SSObj

Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message(vbCrLf & SSObj.Count & " Objects selected" + vbCrLf)

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return Nothing

End Try
End Function

Friend Function SelectionSet_Delete(ByVal Name As String) As Boolean
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim Obj As AcadSelectionSet
Dim Found As Boolean = False

Try
acadApp = CType(GetObject(, AutoCadApplicatie), AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True
For Each Obj In acadDoc.SelectionSets
If Obj.Name = Name Then Found = True
Next

If Found = True Then acadDoc.SelectionSets.Item(Name).Delete()

Return True

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return False

End Try
End Function

#End Region
0 Likes
Message 8 of 10

Anonymous
Not applicable
Thank you, Harold.
0 Likes
Message 9 of 10

Anonymous
Not applicable
Hi,
Since you are discussing about selectionset, I have a question regarding it. How can I make a selection set as pickfirst selection set using .NET API.

Thanks
Naveen.
0 Likes
Message 10 of 10

Anonymous
Not applicable
when I try to get the selection set with this example I always get an error saying the AutoCAD window is invisible. Even if I set the visible state to true. Any idea what causes this error?
0 Likes