TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ronjonp on February 26, 2020, 02:34:04 PM

Title: Offset Recursion
Post by: ronjonp 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. )
Title: Re: Offset Recursion
Post by: Lee Mac 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. )
Title: Re: Offset Recursion
Post by: ronjonp 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!
Title: Re: Offset Recursion
Post by: Lee Mac on February 26, 2020, 02:55:29 PM
Good stuff - you're welcome Ron  :-)
Title: Re: Offset Recursion
Post by: Grrr1337 on February 27, 2020, 04:10:11 AM
Ron, out of curiosity - where would this sub be applicable?
Title: Re: Offset Recursion
Post by: ronjonp 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: