Jump to content

Recommended Posts

Posted

I am confused (not for the first time).

 

I need to select all the text on a particular layer. In VBA I made my selection set as follows

 

Set mySelSet = ThisDrawing.SelectionSets.Add("TextOnLayer")
gpCode(0) = 8 'layer
gpCode(1) = 0 'item
groupCode = gpCode
dataValue(0) = frmExportFerrule.cmbLayer.Text  'layer name
dataValue(1) = "TEXT" 'item type
dataCode = dataValue
mySelSet.Select acSelectionSetAll, , , groupCode, dataCode

 

I am sure this is simple but I can't work out how to do this in VB.Net. I can select all the text in the drawing but I can't work out how to filter it again. Can somebody point me to some sample code that I can study please. I am sure I shouldn't have to iterate through the set (although I may do that soon).

Posted

Here's some info that might help you:

 

Specify a single selection criterion for a selection set

 

The following code prompts users to select objects to be included in a selection set, and

filters out all objects except for circles.

 

VB.NET

 

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.EditorInput

_

Public Sub FilterSelectionSet()

'' Get the current document editor

Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor

'' Create a TypedValue array to define the filter criteria

Dim acTypValAr(0) As TypedValue

acTypValAr.SetValue(New TypedValue(DxfCode.Start, "CIRCLE"), 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.GetSelection(acSelFtr)

'' If the prompt status is OK, objects were selected

If acSSPrompt.Status = PromptStatus.OK Then

Dim acSSet As SelectionSet = acSSPrompt.Value

Application.ShowAlertDialog("Number of objects selected: " & _

acSSet.Count.ToString())

Else

Application.ShowAlertDialog("Number of objects selected: 0")

End If

End Sub

Posted

Thanks Tyke but I am pretty much there already. I can select all the TEXT or all the MTEXT or all the objects on Layer0. What I can't find is how to select all the TEXT on Layer0.

 

I have

 

[size=2]
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myEd [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Editor = DocumentManager.MdiActiveDocument.Editor
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myTVs(0) [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] TypedValue[/size]

[size=2]' comment out for different selection
[/size][size=2][color=#008000][size=2][color=#008000]'myTVs(0) = New TypedValue(DxfCode.Start, "TEXT")
[/color][/size][/color][/size][size=2]myTVs(0) = [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.LayerName, [/size][size=2][color=#a31515][size=2][color=#a31515]"0"[/color][/size][/color][/size][size=2])
[/size][size=2][color=#008000][size=2][color=#008000]'myTVs(0) = New TypedValue(DxfCode.l .Start, "MTEXT")
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myFilter [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] SelectionFilter(myTVs)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myPSR [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] PromptSelectionResult = myEd.SelectAll(myFilter)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] myPSR.Status = PromptStatus.OK [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] mySS [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] SelectionSet = myPSR.Value
myForm.Label2.Text = mySS.Count
[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]If
[/color][/size][/color][/size]

Posted
Thanks Tyke but I am pretty much there already. I can select all the TEXT or all the MTEXT or all the objects on Layer0. What I can't find is how to select all the TEXT on Layer0.

 

I have

 

[size=2]
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myEd [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Editor = DocumentManager.MdiActiveDocument.Editor
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myTVs(0) [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] TypedValue[/size]

[size=2]' comment out for different selection
[/size][size=2][color=#008000][size=2][color=#008000]'myTVs(0) = New TypedValue(DxfCode.Start, "TEXT")
[/color][/size][/color][/size][size=2]myTVs(0) = [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.LayerName, [/size][size=2][color=#a31515][size=2][color=#a31515]"0"[/color][/size][/color][/size][size=2])
[/size][size=2][color=#008000][size=2][color=#008000]'myTVs(0) = New TypedValue(DxfCode.l .Start, "MTEXT")
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myFilter [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] SelectionFilter(myTVs)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myPSR [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] PromptSelectionResult = myEd.SelectAll(myFilter)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] myPSR.Status = PromptStatus.OK [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] mySS [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] SelectionSet = myPSR.Value
myForm.Label2.Text = mySS.Count
[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]If
[/color][/size][/color][/size]

 

You neglected the "AND", or "OR" Operator as needed; sample code copied from link mentioned above:

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput

<CommandMethod("FilterForText")> _
Public Sub FilterForText()
 '' Get the current document editor
 Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor

 '' Create a TypedValue array to define the filter criteria
 Dim acTypValAr(3) As TypedValue
 acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "<or"), 0)
 acTypValAr.SetValue(New TypedValue(DxfCode.Start, "TEXT"), 1)
 acTypValAr.SetValue(New TypedValue(DxfCode.Start, "MTEXT"), 2)
 acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "or>"), 3)

 '' 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.GetSelection(acSelFtr)

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

     Application.ShowAlertDialog("Number of objects selected: " & _
                                 acSSet.Count.ToString())
 Else
     Application.ShowAlertDialog("Number of objects selected: 0")
 End If
End Sub

Posted

I didn't neglect it, that was the bit I couldn't find.

 

Now to see if I can get this working before I am meant to give this drawing back....

Posted

I didn't neglect it, that was the bit I couldn't find.

 

Now to see if I can get this working before I am meant to give this drawing back....

 

:surrender: ... However you want to phrase it, Dave, is fine by me... Just trying to help a friend. :beer:

Posted

YAAAAAAY!

 

[size=2]
[/size][size=2][color=#008000][size=2][color=#008000]'Add bit about counting text on layer
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myEd [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Editor = DocumentManager.MdiActiveDocument.Editor
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myTVs(3) [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] TypedValue
myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.Operator, [/size][size=2][color=#a31515][size=2][color=#a31515]"<AND"[/color][/size][/color][/size][size=2]), 0)
myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.Start, [/size][size=2][color=#a31515][size=2][color=#a31515]"TEXT"[/color][/size][/color][/size][size=2]), 1)
myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.LayerName, [/size][size=2][color=#a31515][size=2][color=#a31515]"0"[/color][/size][/color][/size][size=2]), 2)
myTVs.SetValue([/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] TypedValue(DxfCode.Operator, [/size][size=2][color=#a31515][size=2][color=#a31515]"AND>"[/color][/size][/color][/size][size=2]), 3)
[/size][size=2][color=#008000][size=2][color=#008000]'myTVs(0) = New TypedValue(DxfCode.l .Start, "MTEXT")
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myFilter [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] SelectionFilter(myTVs)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] myPSR [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] PromptSelectionResult = myEd.SelectAll(myFilter)
[/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] myPSR.Status = PromptStatus.OK [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] mySS [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] SelectionSet = myPSR.Value
myForm.Label2.Text = mySS.Count
[/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]If
[/color][/size][/color][/size]

 

Thanks BB, that's one hurdle over, several more to go......

Posted

Thanks BB, that's one hurdle over, several more to go......

 

You're welcome; I'm happy to help. :)

 

BTW - How'd you make out on this thread? Not sure if this is part of that same initiative, or not. :unsure:

Posted
You're welcome; I'm happy to help. :)

 

BTW - How'd you make out on this thread? Not sure if this is part of that same initiative, or not. :unsure:

WWEEEELLLL,

 

same initiative in that we have to go through PADRs (development review) every year and I said I NEED to look at migrating from VBA to VB.Net and please buy me this book. The book was bought at Christmas and in a month or two I have to show the results of my migration. I decided that the cloud routine that the former request covered would be impressive but have now decided to do something less impresive but one that I have a chance of completing! :rofl: In other words, that one has died for now but will be back.

Posted

Well, let us know how you get on... And remember to use these (as applicable):

 

   Try
       DocumentLock
           Transaction
               '' <-- do something
           Commit()
   Catch
   Finally

Posted

fixo, thanks for link. I'll have a look when I get time to register.

 

Tyke, I am looking to get an old VBA routine to work as a VB.Net one but I don't want to just convert it. Now seems to be a good time to try and learn the language (and tidy up my code). Unfortunately I only get a few hours at it at a time as some project managers expect their drawings back.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...