Author Topic: help!help!help!  (Read 4848 times)

0 Members and 1 Guest are viewing this topic.

Q1241274614

  • Guest
help!help!help!
« on: March 10, 2014, 12:23:54 PM »
( (A1 A2) (A3 A4) (A5 A6) (A7 A8) (A9 A10) (A11 A12) (A13 A14) )

ronjonp

  • Needs a day job
  • Posts: 7531

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: help!help!help!
« Reply #2 on: March 10, 2014, 01:45:57 PM »
 :lol:

BlackBox

  • King Gator
  • Posts: 3770
"How we think determines what we do, and what we do determines what we get."

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: help!help!help!
« Reply #4 on: March 10, 2014, 04:59:27 PM »
It seems the OP's problem is one of dividing a list into sublists. Some examples that may be useful:
http://www.theswamp.org/index.php?topic=37892.0

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: help!help!help!
« Reply #5 on: March 10, 2014, 05:03:21 PM »
Well I would interpret it as being he is looking to create a list of the endpoints of the selected lines. (the sample drawing contains plain lines)

The arrow pointing from the line to the list are what make me believe the above.
« Last Edit: March 10, 2014, 05:16:47 PM by snownut2 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help!help!help!
« Reply #6 on: March 10, 2014, 05:09:44 PM »
Q1241274614,

Your post is unclear regarding your requirements.

Do you intend collecting the Text values or the line endPoints ?

Will the collection be made manually (eg Select crossing) ?

The code to list either the text values or the line endpoints is relatively simple ... we just need your rules and a better explanation of what you want.

I hope that translates ok.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help!help!help!
« Reply #7 on: March 10, 2014, 07:01:30 PM »
If you want the points
Perhaps play with something like this

NOTE. For Clarity this code is not optimised.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun doit ()
  3.   (prompt "\nSelect lines and TEXT to evaluate")
  4.   (setq selection (ai_aselect))
  5.   (setq objectlist (kdub:ss->entlist selection)
  6.         pointlist  '()
  7.   )
  8.   (foreach ent objectlist
  9.     (setq obj     (entget ent)
  10.           objname (cdr (assoc 0 obj))
  11.     )
  12.     (cond ((= objname "TEXT")
  13.            ;; perhaps required later
  14.            ;;           (setq textlist
  15.            ;;                  (cons (list (cdr (assoc 10 obj)) (cdr (assoc 1 obj)))
  16.            ;;                        textlist
  17.            ;;                  )
  18.            ;;           )
  19.           )
  20.           ((= objname "LINE")
  21.            (setq startpoint (cdr (assoc 10 obj))
  22.                  endpoint   (cdr (assoc 11 obj))
  23.            )
  24.            ;; is line horizontal to within a fuzz distance
  25.            (if (equal (cadr startpoint) (cadr endpoint) 0.0001)
  26.              ;; sort points with smaller X first
  27.              (if (< (car startpoint) (car endpoint))
  28.                (setq
  29.                  pointlist (cons (list startpoint endpoint) pointlist)
  30.                )
  31.                ;; else
  32.                (setq
  33.                  pointlist (cons (list endpoint startpoint) pointlist)
  34.                )
  35.              )
  36.            )
  37.           )
  38.     )
  39.   )
  40.   pointlist
  41. )
  42.  
  43.  

Code - Auto/Visual Lisp: [Select]
  1. ;; sort pointList
  2.  
  3. (vl-sort (doit) (function (lambda ( a b ) (< (caar a) (caar b)))))

Quote

(
 ((473.704 553.807 0.0) (561.202 553.807 0.0))
 ((561.202 501.106 0.0) (644.977 501.106 0.0))
 ((644.977 599.729 0.0) (720.196 599.729 0.0))
 ((720.196 553.807 0.0) (778.612 553.807 0.0))
 ((778.612 599.729 0.0) (848.894 599.729 0.0))
 ((848.894 542.867 0.0) (904.572 542.867 0.0))
 ((904.572 663.203 0.0) (942.844 663.203 0.0))
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help!help!help!
« Reply #8 on: March 10, 2014, 07:05:34 PM »
You'll need this library function
Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;------------------------------------------------------------------
  3. ;;;
  4. (defun kdub:ss->entlist (ss / returnval)
  5.   (if (and ss (< 0 (sslength ss)))
  6.     (setq returnval (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  7.   )
  8.   returnval
  9. )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: help!help!help!
« Reply #9 on: March 10, 2014, 07:16:56 PM »
kerry,

What is this "(ai_aselect)" in second line ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help!help!help!
« Reply #10 on: March 10, 2014, 07:23:16 PM »
kerry,

What is this "(ai_aselect)" in second line ?

Bruce,
Supplied by AutoDesk.
From ..\support\en-us\ai_utils.lsp

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;;; (ai_aselect)
  3. ;;;
  4. ;;; Looks for a current selection set, and returns it if found,
  5. ;;; or throws user into interactive multiple object selection,
  6. ;;; and returns the resulting selection set if one was selected.
  7. ;;;
  8. ;;; Sets the value of ai_seltype to:
  9. ;;;
  10. ;;;    1 = resulting selection set was autoselected
  11. ;;;    2 = resulting selection set was prompted for.
  12. (defun ai_aselect ( / ss)
  13.   (cond
  14.     ((and (eq 1 (logand 1 (getvar "pickfirst")))
  15.                  (setq ss (ssget "_i")) )
  16.        (setq ss (ai_ssget ss))  ;; only if ss exists.
  17.        (setq ai_seltype 1)
  18.        (ai_return ss)
  19.     )
  20.     ((setq ss (ssget))
  21.       (if ss (setq ss (ai_ssget ss)))
  22.       (setq ai_seltype 2)
  23.       (ai_return ss)
  24.     )
  25.   )
  26. )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: help!help!help!
« Reply #11 on: March 10, 2014, 07:30:29 PM »
kerry,

What is this "(ai_aselect)" in second line ?

Bruce,
Supplied by AutoDesk.
From ..\support\en-us\ai_utils.lsp

Thanks

Q1241274614

  • Guest
Re: help!help!help!
« Reply #12 on: March 10, 2014, 08:19:47 PM »
thank

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help!help!help!
« Reply #13 on: March 10, 2014, 08:55:05 PM »
thank

Q1241274614,
could you please make the effort to clarify your requirements.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help!help!help!
« Reply #14 on: March 10, 2014, 10:08:07 PM »
I was waiting to see what you actually wanted, but in the mean-time , play with this :-

I imagine this could be optimised until it is indecipherable :)

Code - Auto/Visual Lisp: [Select]
  1. ;;; http://www.theswamp.org/index.php?topic=46514.0
  2.  
  3. ;;---------------------------------------------------------------------------------
  4. (defun collect_points (/           selection
  5.                        objectlist  pointlist
  6.                        obj         objname
  7.                        startpoint  endpoint
  8.                       )
  9.   (prompt "\nSelect lines and TEXT to evaluate")
  10.   (setq selection (ai_aselect))
  11.   (setq objectlist (kdub:ss->entlist selection)
  12.         pointlist  '()
  13.   )
  14.   (foreach ent objectlist
  15.     (setq obj     (entget ent)
  16.           objname (cdr (assoc 0 obj))
  17.     )
  18.     (if (= objname "LINE")
  19.       (progn (setq startpoint (cdr (assoc 10 obj))
  20.                    endpoint   (cdr (assoc 11 obj))
  21.              )
  22.              ;; is line horizontal to within a fuzz distance
  23.              (if (equal (cadr startpoint) (cadr endpoint) 0.0001)
  24.                ;; sort points with smaller X first
  25.                (if (< (car startpoint) (car endpoint))
  26.                  (setq
  27.                    pointlist (cons (list startpoint endpoint) pointlist)
  28.                  )
  29.                  ;; else
  30.                  (setq
  31.                    pointlist (cons (list endpoint startpoint) pointlist)
  32.                  )
  33.                )
  34.              )
  35.       )
  36.     )
  37.   )
  38.   pointlist
  39. )
  40.  
  41.  
  42. ;;---------------------------------------------------------------------------------
  43. ;;; get_closest()
  44. ;;; Select closest entity to point within limit
  45. ;;;
  46. (defun get_closest (pt enttype step limit / halfside ss)
  47.   (setq halfside step
  48.         ss nil
  49.   )
  50.   (while (and (not ss) (< halfside limit))
  51.     (setq ss       (ssget "_c"
  52.                           (v+v pt (list halfside (- halfside) 0))
  53.                           (v+v pt (list (- halfside) halfside 0))
  54.                           (list (cons 0 enttype))
  55.                    )
  56.           halfside (+ halfside step)
  57.     )
  58.   )
  59.   ss
  60. )
  61.  
  62. ;;---------------------------------------------------------------------------------
  63. ;;; v+v()
  64. ;;; Vector addition
  65. ;;; Arguments: v1, v2, lists of three real numbers.
  66. (defun v+v (v1 v2) (mapcar '+ v1 v2))
  67.  
  68. ;;---------------------------------------------------------------------------------
  69. ;;; get_textnodenames
  70. ;;;
  71. (defun get_textnodenames
  72.        (pts stepsize fencelimit / starttext endtext textlist)
  73.   (foreach pointset pts
  74.     (if (and (setq starttext (get_closest (car pointset)
  75.                                           "TEXT"
  76.                                           stepsize
  77.                                           fencelimit
  78.                              )
  79.              )
  80.              (setq endtext (get_closest (cadr pointset)
  81.                                         "TEXT"
  82.                                         stepsize
  83.                                         fencelimit
  84.                            )
  85.              )
  86.         )
  87.       (setq textlist
  88.              (cons
  89.                (list (cdr (assoc 1 (entget (ssname starttext 0))))
  90.                      (cdr (assoc 1 (entget (ssname endtext 0))))
  91.                )
  92.                textlist
  93.              )
  94.       )
  95.     )
  96.   )
  97.   (reverse textlist)
  98. )
  99. ;;---------------------------------------------------------------------------------
  100.  

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq sortedpoints
  3.        (vl-sort (collect_points)
  4.                 (function (lambda (a b) (< (caar a) (caar b))))
  5.        )
  6. )
  7.  
  8. (setq stepsize      2
  9.       fencelimit    50
  10.       textnodenames (get_textnodenames sortedpoints stepsize fencelimit)
  11. )
  12.  

Quote
(((473.704 553.807 0.0) (561.202 553.807 0.0))
  ((561.202 501.106 0.0) (644.977 501.106 0.0))
  ((644.977 599.729 0.0) (720.196 599.729 0.0))
  ((720.196 553.807 0.0) (778.612 553.807 0.0))
  ((778.612 599.729 0.0) (848.894 599.729 0.0))
  ((848.894 542.867 0.0) (904.572 542.867 0.0))
  ((904.572 663.203 0.0) (942.844 663.203 0.0))
)

(("A1" "A2")
 ("A3" "A4")
 ("A5" "A6")
 ("A7" "A8")
 ("A9" "A10")
 ("A11" "A12")
 ("A13" "A14")
)
« Last Edit: March 10, 2014, 10:31:37 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.