Selection set filter & vbnet

Selection set filter & vbnet

Anonymous
Not applicable
3,165 Views
8 Replies
Message 1 of 9

Selection set filter & vbnet

Anonymous
Not applicable
HI,
i have a problem with "selection filter" and vbnet.
I occurred an error in this code.
ssetObj = activeDoc.SelectionSets.Add("SSET10")
mode = AutoCAD.AcSelect.acSelectionSetAll
Dim gpCode(0) As Integer
Dim dataValue(0) As Object
gpCode(0) = 8 'layer
dataValue(0) = "Raster" 'layer name
Dim groupCode As Object, dataCode As Object
groupCode = gpCode
dataCode = dataValue
ssetObj.Select(mode, , , groupCode, dataCode) <-----------------error....

i think it's a problem with declaration (like "datacode as object")
in VBA use "Variant" but in vbnet isn't possible...
can anyone help me?
thanks
Marco
0 Likes
3,166 Views
8 Replies
Replies (8)
Message 2 of 9

Danny.isr
Contributor
Contributor
in vb.net from ObjectARX 2009\samples\dotNet\SelectionSet
Public Class AcEdSSGetCommand

Shared SelentityCount As Integer = 0
Shared UseThisSelectionResult As PromptSelectionResult
Shared UseThisSelectionOption As PromptSelectionOptions = Nothing

'This command does a simple selection and ignores all
'entities other than red circles
_
Public Sub ssGetFilter()
'Setup
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

'Declare our filter entries this way.
'We build them the same way in ObjectARX.
'DxfCode.Start (equal to 0) - This is for 'Entity Name'
'DxfCode.Color is for ACI color - 1 = Red
Dim values() As TypedValue = { _
New TypedValue(DxfCode.Start, "CIRCLE"), _
New TypedValue(DxfCode.Color, 1) _
}
Dim sfilter As New SelectionFilter(values) ' Create the filter using our values...

'Set the selection options
Dim SelOpts As New PromptSelectionOptions()
SelOpts.MessageForAdding = "Select Red Circles:"
SelOpts.AllowDuplicates = True
'Make the selection:
Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

If Not res.Status = PromptStatus.OK Then Return

Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
'start a transaction
Dim myT As Transaction = tm.StartTransaction()
Try
Dim id As ObjectId
For Each id In idarray
Dim entity As Entity = tm.GetObject(id, OpenMode.ForRead, True)
ed.WriteMessage((ControlChars.Lf + "You selected: " + entity.GetType().FullName))
Next id
Finally
myT.Dispose()
End Try
End Sub Edited by: Danny.isr on Nov 19, 2008 9:26 AM
0 Likes
Message 3 of 9

chiefbraincloud
Collaborator
Collaborator
I had the same problem when I moved my VBA project to .NET, and it was not easy to find the answer, but I just looked and found some old code in which I have declared the filters gpCode as Short and dataValue as Object. I know that is not what the signatures say in the object browser, but it worked for me.



The other post here shows you how to do it in the managed environment. What you are doing is ActiveX or COM.
Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 4 of 9

Anonymous
Not applicable
incredible!! it work!! thank you very much to everybody...
Marco
0 Likes
Message 5 of 9

Anonymous
Not applicable
The first thing people moving from VBA to VB.NET need to know is that data types are different. Hence if you know the equivalent data types you avoid simple problems like this one.
0 Likes
Message 6 of 9

chiefbraincloud
Collaborator
Collaborator


While I can't argue that there are some differences it types, I would have avoided the whole problem altogether if the Object browser didn't show this as the signature for the filter on AcadSelectionSet.Select: (copied and pasted directly from the Object Browser)



Optional ByVal FilterType As Object = Nothing, Optional ByVal FilterData As Object = Nothing

If you use Object, it doesn't work, and while it's a short leap from {color:#0000ff}Integer{color} in VBA to {color:#0000ff}Short{color} in .NET, the leap from Object to Short is a little more obscure.

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 7 of 9

Anonymous
Not applicable
Sorry I didn't mean you to take offence just offering help for those making the move.



I will reiterate for people moving from VBA to a .NET language with the ActiveX API they can simply avoid these problems if they know what type they used with VBA and use the .NET equivalent type.
0 Likes
Message 8 of 9

Stakin
Collaborator
Collaborator

https://adndevblog.typepad.com/autocad/2012/07/creating-a-selection-set-using-com-interop.html Dim FilterType(0) 

Dim FilterType(0) As Int16 ' IMPORTANT: The type must be Int16,

                           ' otherwise you'll get an exception!

Dim FilterData(0) As Object
0 Likes
Message 9 of 9

kerry_w_brown
Advisor
Advisor
I'm migrating my VBA code to VB.NET and getting an exception . . . 

example of self inflicted injury.

I threw up into my mouth.

 

what a waste of good brain cells !!


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes