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

Selection set filter & vbnet

6 REPLIES 6
Reply
Message 1 of 7
itamarcus
2441 Views, 6 Replies

Selection set filter & vbnet

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
6 REPLIES 6
Message 2 of 7
Danny.isr
in reply to: itamarcus

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
Message 3 of 7
chiefbraincloud
in reply to: itamarcus

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
Message 4 of 7
itamarcus
in reply to: itamarcus

incredible!! it work!! thank you very much to everybody...
Marco
Message 5 of 7
NathTay
in reply to: itamarcus

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.
Message 6 of 7
chiefbraincloud
in reply to: itamarcus


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
Message 7 of 7
NathTay
in reply to: itamarcus

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.

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