Author Topic: Offset Recursion  (Read 2149 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Offset Recursion
« on: February 26, 2020, 02:34:04 PM »
Be kind :). I really struggle with wrapping my head around recursion and have been trying to get this function to return a list of the offset objects without success.  :-( Could someone steer me in the right direction?
Code - Auto/Visual Lisp: [Select]
  1. (defun _offin (o d / r)
  2.   (cond ((and (= 'list (type (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d)))))
  3.               (> (vlax-curve-getarea o) (vlax-curve-getarea (car r)))
  4.          )
  5.          (foreach x r (_offin x d))
  6.         )
  7.   )
  8. )
  9. (if (setq e (car (entsel)))
  10.   (_offin (vlax-ename->vla-object e) 0.3333)
  11. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Offset Recursion
« Reply #1 on: February 26, 2020, 02:43:03 PM »
Perhaps this?
Code - Auto/Visual Lisp: [Select]
  1. (defun _offin ( o d / r )
  2.     (if (not (vl-catch-all-error-p (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d)))))
  3.         (if (< (vlax-curve-getarea (car r)) (vlax-curve-getarea o))
  4.             (append r (apply 'append (mapcar '(lambda ( x ) (_offin x d)) r)))
  5.             r
  6.         )
  7.     )
  8. )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Offset Recursion
« Reply #2 on: February 26, 2020, 02:51:15 PM »
Perhaps this?
Code - Auto/Visual Lisp: [Select]
  1. (defun _offin ( o d / r )
  2.     (if (not (vl-catch-all-error-p (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d)))))
  3.         (if (< (vlax-curve-getarea (car r)) (vlax-curve-getarea o))
  4.             (append r (apply 'append (mapcar '(lambda ( x ) (_offin x d)) r)))
  5.             r
  6.         )
  7.     )
  8. )
That works nicely Lee :) .. now I need to wrap my head around it. Thanks a bunch!

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Offset Recursion
« Reply #3 on: February 26, 2020, 02:55:29 PM »
Good stuff - you're welcome Ron  :-)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Offset Recursion
« Reply #4 on: February 27, 2020, 04:10:11 AM »
Ron, out of curiosity - where would this sub be applicable?
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Offset Recursion
« Reply #5 on: February 27, 2020, 11:27:23 AM »
Ron, out of curiosity - where would this sub be applicable?
Mostly for fun and trying to stretch my brain a bit :) ... I have a very old staggered offset routine that does not work on areas like this:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC