.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selection Set in VB.Net

9 REPLIES 9
Reply
Message 1 of 10
as
3035 Views, 9 Replies

Selection Set in VB.Net

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
9 REPLIES 9
Message 2 of 10
as
in reply to: as

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.
Message 3 of 10
tangferry
in reply to: as

There is a bug in the managed wrapper class.You can use my DOTNETARX library to use the filter option in Selection sets.
Message 4 of 10
tangferry
in reply to: as

I'm sorry,you use the com!You should replace
Dim FilterType(0) As Integer
with
Dim FilterType(0) As short
Message 5 of 10
as
in reply to: as

You are right
Message 6 of 10
Anonymous
in reply to: as

Hello, Harold!
What do you filter in your sample?
Message 7 of 10
as
in reply to: as

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
Message 8 of 10
Anonymous
in reply to: as

Thank you, Harold.
Message 9 of 10
Naveen
in reply to: as

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.
Message 10 of 10
flongsworth
in reply to: as

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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost