Select text and set string

Select text and set string

npompe
Explorer Explorer
2,834 Views
5 Replies
Message 1 of 6

Select text and set string

npompe
Explorer
Explorer

Hello all,

 

Here's my problem

 

I have drawing with 80 views. At bottom of each view there is an text. I want to read text on each view en put it in a string to use it for creating an index.

For now I only be able to select text with ThisDrawing.Utility.GetEntity adEntity, basePnt, "pick text"

But I want to select it with coordinates so I dont have to click on screen. For now I have this but string keeps empty

 

  Dim sstext As AcadSelectionSet
  Dim FilterType(3) As Integer
  Dim FilterData(3) As Variant

  Dim text As String

  Dim startPoint(0 To 2) As Double
  Dim endPoint(0 To 2) As Double


  Set sstext = ThisDrawing.SelectionSets.Add("SS6")
  FilterType(0) = -4
  FilterData(0) = "<or"
  FilterType(1) = 0
  FilterData(1) = "TEXT"
  FilterType(2) = 0
  FilterData(2) = "MTEXT"
  FilterType(3) = -4
  FilterData(3) = "or>"

  sstext.SelectOnScreen FilterType, FilterData

    startPoint(0) = 840
    startPoint(1) = 3232.5
    startPoint(2) = 0#
    endPoint(0) = 910#
    endPoint(1) = 3225
    endPoint(2) = 0#
   
    On Error Resume Next

    sstext.Select acSelectionSetWindow, startPoint, endPoint, FilterType, FilterData
    text = sstext.textString
   

Hope somebody can help with this. I have been searching internet for weeks

0 Likes
2,835 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I have drawing with 80 views [...]

>> But I want to select it with coordinates

Not sure what you mean by "views", if you would really mean "view" (predefined zoom-coordinates and settings like visual style) then you would not have multiple text objects at the same position (as during creation of a selection set you ony have one coordinate-system).

And if you mean "layouts" then again it is not possible to select anything by coordinates as selection by coordinates can only be done in the active space.

 

My suggestion would be to select all text objects on a specific layer (hopefully you have layers you can filter to) and then scan through the objects in the selectionset and compare the text-insertion points with your coordinates to decide that is a text to work with or not.

 

Good luck, - alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 6

npompe
Explorer
Explorer

Hello Alfred,

 

Try to explain in less words. Sorry for my bad englisch

 

What I want is to read a single line tex. With this "ThisDrawing.Utility.GetEntity adEntity, basePnt, "Select text" I am asking the user to pick the text on screen. But I know exactly where the text is on the screen. So I dont want to ask user to select it I just want to select it with coordinates and then read it.

I know its possible to select it with selectionset but I also want to read the text.

 

Nico

0 Likes
Message 4 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

ok, then you can use the selectionset with option for window-selection (or crossing selection), but keep in mind:

the coordinates for the window have to be visible on screen, are the coordinates outside the screen-area you won't get it selected (you would not be able to select it with your cursor in that case too). So a zoom may be required.

Another issue with window-selection: keep in mind that the cursor/pickbox has to find something within the coordinates, if your text has an insertion point (lower-left corner of the textbox) of 0,0,0, the text size is 100, but your zoom-window is -1,-1 to 1,1 and you do a crossing-selection using the same -1,-1 to 1,1 you also might miss the text if the first letter is not visible within the area (like e.g. character "\").

Next issue might be that the user had frozen the layer with the text, in that case a selectionset with window- or crossing-selection also can't find/select the text-object.

 

Depending on the amount if data you have in the current space you might find the option better to built a selection set for your current space getting all text-objects, then scan through every item in that selectionset if the insertion point fit's to your filter and then do whatever you like to do with that text.

 

And to get a sample for that mode

  • selection set with all text-objects in current layout
  • then search by point for the text-object
  • the point is a point within the extents of the text-object

I have attached a VBA (vers. 7, should run on AutoCAD 2014 and 2015)

Attention: no error handling included, not tested, especially the method for calculation of object-extents can be critical.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 6

npompe
Explorer
Explorer

Hello Alfred,

 

Thanks It select the tekst and color is red. But I want to read what the text says. So want a msgbox with the text displayed in it. Is this possible now

0 Likes
Message 6 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

I just showed a sample so you can find a text by coordinates without manually selecting it.

To switch the text to red was just to show you have access to it, make whatever you like with the text, I have marked the position in the code with a comment, so you can also make a msgbox with the text's content.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes