Author Topic: Create a selection set of objects based on a text string  (Read 3977 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set of objects based on a text string
« Reply #15 on: February 12, 2016, 11:04:23 AM »
Maybe something like this?:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _Conv_Pickset_To_EnameList (ss / i ret)
  3.   (if ss
  4.     (repeat (setq i (sslength ss))
  5.       (setq ret (cons (ssname ss (setq i (1- i))) ret))
  6.     )
  7.   )
  8. )
  9.  
  10. (defun c:Test ( / fuzz ptLst str ss ssOut)
  11.   (if
  12.     (and
  13.       (/= "" (setq str (getstring T "\nLook for TEXT entities containing this string: ")))
  14.       (setq ss (ssget "_X" (list '(0 . "TEXT") (cons 410 (getvar 'ctab)) (cons 1 (strcat "*" str "*")))))
  15.       (setq ptLst
  16.         (mapcar
  17.           '(lambda (enme)
  18.             (vlax-get (vlax-ename->vla-object enme) 'insertionpoint)
  19.           )
  20.           (_Conv_Pickset_To_EnameList ss)
  21.         )
  22.       )
  23.     )
  24.     (progn
  25.       (vla-zoomextents (vlax-get-acad-object)) ; Crossing points must be visible on screen.
  26.       (setq fuzz 1.0)
  27.       (setq ssOut (ssadd))
  28.       (mapcar
  29.         '(lambda (pt / ss)
  30.           (setq pt (trans pt 0 1))
  31.           (if
  32.             (setq ss
  33.               (ssget
  34.                 "_C"
  35.                 (mapcar '- pt (list fuzz fuzz 0.0))
  36.                 (mapcar '+ pt (list fuzz fuzz 0.0))
  37.                 '((0 . "LINE,LWPOLYLINE,POINT,TEXT"))
  38.               )
  39.             )
  40.             (foreach enme (_Conv_Pickset_To_EnameList ss)
  41.               (ssadd enme ssOut)
  42.             )
  43.           )
  44.         )
  45.         ptLst
  46.       )
  47.       (if (/= 0 (sslength ssOut))
  48.         (sssetfirst nil ssOut)
  49.       )
  50.     )
  51.   )
  52.   (princ)
  53. )

Dave M

  • Newt
  • Posts: 196
Re: Create a selection set of objects based on a text string
« Reply #16 on: February 12, 2016, 01:27:31 PM »
That worked!  At first I didn't think it was working, but the text string I used had a lot of objects.  The only downside is that it selects everything that shares or crosses that common point.  Would it be difficult to specify what is to be selected?  I used Quick Select to further filter the selection.


Thank you very much!

Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Create a selection set of objects based on a text string
« Reply #17 on: February 12, 2016, 05:02:59 PM »
Quote
Would it be difficult to specify what is to be selected?

See line 38 in the code posted by roy.

Quote
'((0 . "LINE,LWPOLYLINE,POINT,TEXT"))
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set of objects based on a text string
« Reply #18 on: February 13, 2016, 04:22:21 AM »
The code in my previous post was actually my 2nd stab at this. In my first attempt (see the code below) I tried to solve the problem in a more efficient way by creating a single selection set using a complex point filter. This solution actually works fine and since it looks at points is more critical in what is selected. The only problem is that for polylines only the first point is checked by the filter.

Alternative code (the code assumes that all entities have an OCS that matches the WCS):
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _Conv_Pickset_To_EnameList (ss / i ret)
  3.   (if ss
  4.     (repeat (setq i (sslength ss))
  5.       (setq ret (cons (ssname ss (setq i (1- i))) ret))
  6.     )
  7.   )
  8. )
  9.  
  10. (defun GeneratePtFilter (ptLst grpCd fuzz)
  11.   (apply
  12.     'append
  13.     (mapcar
  14.       '(lambda (pt)
  15.         (list
  16.           '(-4 . "<AND")
  17.           '(-4 . ">,>,*")
  18.           (cons grpCd (mapcar '- pt (list fuzz fuzz 0.0)))
  19.           '(-4 . "<,<,*")
  20.           (cons grpCd (mapcar '+ pt (list fuzz fuzz 0.0)))
  21.           '(-4 . "AND>")
  22.         )
  23.       )
  24.       ptLst
  25.     )
  26.   )
  27. )
  28.  
  29. (defun c:Test ( / ptLst str ss ssOut)
  30.   (if
  31.     (and
  32.       (/= "" (setq str (getstring T "\nLook for TEXT entities containing this string: ")))
  33.       (setq ss (ssget "_X" (list '(0 . "TEXT") (cons 410 (getvar 'ctab)) (cons 1 (strcat "*" str "*")))))
  34.       (setq ptLst
  35.         (mapcar
  36.           '(lambda (enme)
  37.             (vlax-get (vlax-ename->vla-object enme) 'insertionpoint)
  38.           )
  39.           (_Conv_Pickset_To_EnameList ss)
  40.         )
  41.       )
  42.       (setq ssOut
  43.         (ssget
  44.           "_X"
  45.           (append
  46.             (list
  47.               '(0 . "LINE,LWPOLYLINE,POINT,TEXT")
  48.               (cons 410 (getvar 'ctab))
  49.               '(-4 . "<OR")
  50.             )
  51.             (GeneratePtFilter ptLst 10 1.0)
  52.             (GeneratePtFilter ptLst 11 1.0)
  53.             '((-4 . "OR>"))
  54.           )
  55.         )
  56.       )
  57.     )
  58.     (sssetfirst nil ssOut)
  59.   )
  60.   (princ)
  61. )

« Last Edit: February 13, 2016, 04:29:01 AM by roy_043 »

Dave M

  • Newt
  • Posts: 196
Re: Create a selection set of objects based on a text string
« Reply #19 on: February 15, 2016, 11:06:59 AM »
Thank you for taking the time to help me with this!  I really appreciated it!
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox