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

VB.NET Selection Set Convert VBA to .NET

7 REPLIES 7
Reply
Message 1 of 8
chase.hochstrasser
2783 Views, 7 Replies

VB.NET Selection Set Convert VBA to .NET

So, I have looked online but with no success found the correct way to convert the below code from VBA to VB.NET. I have tried using PromptSelection to get the selection set but i get an error each time, so i must be doing something wrong to convert this code. can someone help me with this?

 

Sub redoScale()

'---set scale to the scale of last block
'---this is for the case when a drawing is reopened and the
'---scale is different than the default of 1

Dim ent As Object
Dim EntGrp(0) As Integer
Dim EntPrp(0) As Variant
Dim ssNew As Object
Dim fuseAtts As Variant
Dim entlast As AcadEntity

'---if TBLK not yet defined, error occurs when trying to delete it
On Error GoTo errHandle

If ThisDrawing.SelectionSets.count > 0 Then

'---delete previous instance of TBLK selection set
ThisDrawing.SelectionSets("TBLK").Delete
End If

Set ssNew = ThisDrawing.SelectionSets.Add("TBLK")

'Filter for Group code 2, the block name
EntGrp(0) = 2

'The name of the block to filter for
EntPrp(0) = "device?,fuse?"

'find the block
ssNew.Select acSelectionSetAll, , , EntGrp, EntPrp

If ssNew.count = 0 Then
'---no fuses found
dScale = 1
pScale = 0.0002
Else
'---set scale to that of last block drawn
findLastInsert
End If
scaleCheck = True

Exit Sub

errHandle:
MsgBox Err.Description & vbCrLf & "Error Number: " & Err.Number
Resume Next
End Sub

7 REPLIES 7
Message 2 of 8
_gile
in reply to: chase.hochstrasser

Hi,

 

Maybe this can help:

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 8
chase.hochstrasser
in reply to: _gile

no not so much, thanks though. so far i have been looking at promptselectionresult but this has not been working as expected
Message 4 of 8
Jeff_M
in reply to: chase.hochstrasser

Post what you have tried, Chase. What is it not doing or what is the error you are getting?

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 8
chase.hochstrasser
in reply to: Jeff_M

This is what i have so far

Public Shared Sub redoScale()
On Error GoTo errHandle

'' Create Document, Database, and Editor
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acDb As Database = acDoc.Database
Dim acDocEd As Editor = acDoc.Editor

'' Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.BlockName, "device?,fuse?"), 0)

'' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)

'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.SelectAll(acSelFtr)

'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value

'' Set scale to that of last block drawn
findLastInsert()
GlobalClass.scaleCheck = True
Else
'' No fuses found set defaults
GlobalClass.dScale = 1
GlobalClass.pScale = 0.0002
acDocEd.WriteMessage("Number of objects selected: 0")
End If

'' Exit subrutine
Exit Sub

errHandle:
acDocEd.WriteMessage(Err.Description & vbCrLf & "Error Number: " & Err.Number)
Resume Next
End Sub

 

 

and I recieve an error on acssprompt = acdoced.selectall(acselftr) each time

 

maybe i do have this correct but i'm not sure

Message 6 of 8
Jeff_M
in reply to: chase.hochstrasser

What error do you get? I don't see anything obvious in your code that would make it fail at that point, but then I don't VB.NET much (c# is my language choice). One thing I noted that I've seen done differnetlky is this line:

acTypValAr.SetValue(New TypedValue(DxfCode.BlockName, "device?,fuse?"), 0)

 

perhaps try changing it to this:

acTypValAr(0) = New TypedValue(DxfCode.BlockName, "device?,fuse?")

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 8

what error do you get? I tried your code and it works without error here

 

as a side note: replace the ugly GoTo with a Try...Catch statement

Message 8 of 8

so i was wrong, this did work but i had a problem with another part which i fixed. thanks for looking into this and i will change the got to Try Catch thanks. 

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