Author Topic: Coding -={ Challenge }=- : Draw Pline at center of circles  (Read 4718 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Coding -={ Challenge }=- : Draw Pline at center of circles
« Reply #15 on: December 22, 2014, 08:37:20 PM »
To be honest, I'm not sure where that came from  .. probably one of the code geniuses here on TheSwamp  :) . If you're interested in elevation, try this out as an alternative.

Code - Auto/Visual Lisp: [Select]
  1. (defun _addlwpolyline (layer width ptlst 0or1)
  2.          (list (list '(0 . "LWPOLYLINE")
  3.                 (cons 100 "AcDbEntity")
  4.                 (cons 8 layer)
  5.                 (cons 100 "AcDbPolyline")
  6.                 (cons 90 (length ptlst))
  7.                 (cons 43 width)
  8.                 (cons 38
  9.                  (if (caddar ptlst)
  10.                    (caddar ptlst)
  11.                    (getvar 'elevation)
  12.                  )
  13.                 )
  14.                 (cons 70 0or1)
  15.           )
  16.           (mapcar '(lambda (x) (list 10 (car x) (cadr x))) ptlst)
  17.           (list (cons 210 (trans '(0. 0. 1.) 1 0)))
  18.          )
  19.        )
  20.   )
  21. )
« Last Edit: December 22, 2014, 08:55:35 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BazzaCAD

  • Guest
Re: Coding -={ Challenge }=- : Draw Pline at center of circles
« Reply #16 on: December 23, 2014, 07:13:39 PM »
Thank you both.
I'm using ronjonp's code for my more basic shapes & Kerry's for the more complicated ones...
Kerry I added some grdraw code to draw the Pline as you go instead of doing the highlighting, as suggested.


Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:doit (/)
  3.    (defun mouse-moved (mousepoint)
  4.       (if (setq cenPt (osnap mousepoint "_cen"))
  5.          (cond
  6.             ((= 1 (length ptlist))
  7.              ;; we haven't left the first circle
  8.              (if (not
  9.                     (equal cenPt firstCircleCen 1e-8)
  10.                  )
  11.                (progn
  12.                  (setq ptlist (cons cenPt ptlist))
  13.                  (if *oldPt*
  14.                    (grdraw *oldPt* cenPt 1 1)
  15.                  )               
  16.                  (setq *oldPt* cenPt)
  17.                )
  18.              )
  19.             )
  20.             ((not (vl-position cenPt ptlist))
  21.              (setq ptlist (cons cenPt ptlist))
  22.              (if *oldPt*
  23.                (grdraw *oldPt* cenPt 1 1)
  24.              )
  25.              (setq *oldPt* cenPt)
  26.             )
  27.             ;;
  28.             ((equal cenPt firstCircleCen 1e-8)
  29.  
  30.              (setq looping nil)
  31.              (redraw)
  32.  
  33.             )
  34.          )
  35.       )
  36.    )
  37.  
  38.    (defun space-bar () (setq looping nil) (princ))
  39.    ;;
  40.    ;; Main entry
  41.    ;;
  42.    (setq looping t
  43.          ptlist '()
  44.          firstCircleCen nil
  45.          *oldPt* nil
  46.    )
  47.  
  48.    (if
  49.       (setq cenPt (osnap (cadr (entsel "Select First Circle : ")) "_cen"))
  50.         (setq firstCircleCen cenPt
  51.               ptlist (cons cenPt ptlist)
  52.               *oldPt* cenPt
  53.         )
  54.         (exit)
  55.    )
  56.    (princ (strcat "\nPass mouse over next circle and subsequent circles"
  57.                   "\nFinishing at first circle.\nPress Space bar for emergency exit"
  58.           )
  59.    )
  60.  
  61.    (while looping
  62.       (setq code (grread t 8)
  63.             key  (car code)
  64.             data (cadr code)
  65.       )
  66.       (cond ((and (= key 5) (listp data)) (mouse-moved data))
  67.             ((equal code '(2 32)) (space-bar))
  68.       )
  69.    )
  70.  
  71.    (kbub:EntmakePlineInUCS ptlist "LAYERNAME" 1)
  72.    (princ "\nThanks for the fish")
  73.    (princ)
  74. )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Coding -={ Challenge }=- : Draw Pline at center of circles
« Reply #17 on: December 23, 2014, 07:40:41 PM »
Hi Barry,

Your first piccy is a perfect example of where I thought the GRRead option may be needed.

Sometimes you just can't satisfy all the possible rules when automating stuff ... or even think of all the possible permutations.

I'm happy to see that the problem has a resolution.

Stay well.
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.