Author Topic: Error in selection set data to search in another selection set  (Read 1879 times)

0 Members and 1 Guest are viewing this topic.

vincent.r

  • Newt
  • Posts: 101
Hi guys,

I tried to write a code to search a string (extracted from selection set) in another selection set. this will return me closest specific text from left hand side of a given string. Tried with both, while and repeat.

For reference drawing attached.
I have used modified Tharwat's code from my earlier post.

Any help will be highly appreciated.


(setq valveassocvfd (ssget "_w" '(8.02218 21.63036) '(34.03070 3.93130) '((0 . "text,mtext") (1 . "M*"))))
(if (/= valveassocvfd nil) (progn
(repeat (setq inc (sslength valveassocvfd))
     (setq closest 40)
     (setq mn '())
     (setq Ename (ssname valveassocvfd (setq inc (1- inc))))
   (setq elst (entget Ename))
     (setq mno (cdr (assoc 1 elst)));delete later
     (setq allvalvenames2 (ssget "_w" '(8.02218 21.63036) '(34.03070 3.93130) '((0 . "text,mtext") (1 . "5,6,7,8"))))
     (while (/= allvalvenames2 nil)
        (setq MEname (ssname allvalvenames2 (setq ind (1- ind))))
      (setq Melst (entget MEname))
        (setq jbno (cdr (assoc 1 Melst)));delete later
     (if (> (car (cdr (assoc 11 elst))) (car (cdr (assoc 11 Melst))))
          (progn
       (setq distvfd (distance (cdr (assoc 11 elst)) (cdr (assoc 11 Melst))))
        (if (<= distvfd closest)
             (progn
              (setq closest distvfd)
            (setq closestvfdtext MEname)
            );progn
      );if
      );progn
     );if
     (setq allvalvenames2 (ssdel Melst allvalvenames2))
   );while
  (if closestvfdtext (progn (setq mn (cons (strcat "[" (cdr (assoc 1 (entget closestvfdtext))) "]") mn))))
(if closestvfdtext (progn (setq mn (cons (strcat "[" (cdr (assoc 1 (entget Ename))) "]") mn))))
  (setq valveinformation8 (cons mn valveinformation8))
  (setq valveassocvfd (ssdel Ename valveassocvfd))
  );repeat
));progn,if

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Error in selection set data to search in another selection set
« Reply #1 on: August 20, 2019, 11:47:05 AM »
The example drawing and the code provided do not have any valid selections?
Are you trying to group the closest # text with the nearest M### text?

Quick example of grouping by distance:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ ems ints s)
  2.   ;; Filter 5-8 and M* text
  3.   (cond ((setq s (ssget "_x" '((0 . "text,mtext") (1 . "[5-8],M*"))))
  4.          (foreach e (mapcar 'cadr (ssnamex s))
  5.            ;; Separate 5-8 text from M* text
  6.            (if (wcmatch (cdr (assoc 1 (entget e))) "#")
  7.              (setq ints (cons (cdr (assoc 11 (entget e))) ints))
  8.              (setq ems (cons (cdr (assoc 11 (entget e))) ems))
  9.            )
  10.          )
  11.          (foreach i ints
  12.            ;; Sort # text distance from all M* text and return closest
  13.            (grdraw i (car (vl-sort ems '(lambda (a b) (< (distance i a) (distance i b))))) 3)
  14.          )
  15.         )
  16.   )
  17.   (princ)
  18. )
« Last Edit: August 20, 2019, 12:01:07 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

vincent.r

  • Newt
  • Posts: 101
Re: Error in selection set data to search in another selection set
« Reply #2 on: August 20, 2019, 02:48:15 PM »
Hi ronjonp. Thanks for your efforts.

The example drawing and the code provided do not have any valid selections? - Yes in this case, do not have mtext but in next few drawings

Are you trying to group the closest # text with the nearest M### text? - No



I want only closest one and it should be on left side of string.

Quick example of grouping by distance: -Thaks for this



ronjonp

  • Needs a day job
  • Posts: 7527
Re: Error in selection set data to search in another selection set
« Reply #3 on: August 20, 2019, 03:02:23 PM »
Hi ronjonp. Thanks for your efforts.

The example drawing and the code provided do not have any valid selections? - Yes in this case, do not have mtext but in next few drawings

Are you trying to group the closest # text with the nearest M### text? - No

I want only closest one and it should be on left side of string.

Quick example of grouping by distance: -Thaks for this
Just curious but why are you doing this?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

vincent.r

  • Newt
  • Posts: 101
Re: Error in selection set data to search in another selection set
« Reply #4 on: August 22, 2019, 08:36:34 AM »
to generate report of associate values