.NET

Reply
Active Member
itamarcus
Posts: 7
Registered: ‎11-19-2008
Message 1 of 7 (1,041 Views)

Selection set filter & vbnet

1041 Views, 6 Replies
11-19-2008 12:51 AM
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
Active Member
Danny.isr
Posts: 9
Registered: ‎11-19-2008
Message 2 of 7 (1,041 Views)

Re: Selection set filter & vbnet

11-19-2008 01:25 AM 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
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 3 of 7 (1,041 Views)

Re: Selection set filter & vbnet

11-19-2008 10:42 AM 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
Active Member
itamarcus
Posts: 7
Registered: ‎11-19-2008
Message 4 of 7 (1,041 Views)

Re: Selection set filter & vbnet

11-19-2008 01:00 PM in reply to: itamarcus
incredible!! it work!! thank you very much to everybody...
Marco
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 5 of 7 (1,041 Views)

Re: Selection set filter & vbnet

11-19-2008 01:51 PM 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.
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 6 of 7 (1,041 Views)

Re: Selection set filter & vbnet

11-19-2008 02:06 PM 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
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 7 of 7 (1,041 Views)

Re: Selection set filter & vbnet

11-19-2008 02:16 PM 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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.