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
Hi,
Maybe this can help:
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html
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
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?")
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
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.