AVS801 Posted January 3, 2020 Posted January 3, 2020 Hi, I have the following task: There is a closed polyline. I need to do OFFSET outside by a certain distance. At the moment my Lisp code is the following, but it doesn't work properly if the original polyline has counter clock wise orientation (offset goes inside not outside). Has anyone faced such a task? (defun c:offsetout (/) (while t (setq offset (getreal "\nInput offset distance :")) (while (not(setq ent_point (entsel "\nSelect an object or press ESC :")))) (setq ent (nth 0 ent_point)) (setq vla_obj (vlax-ename->vla-object ent)) (setq offsetObj1 (vla-Offset vla_obj (* -1 offset))) ;(setq offsetObj2 (vla-Offset vla_obj (* 1 offset))) (setq vla_obj1 (vlax-ename->vla-object (car(offsetObj1)))) ; (vlax-dump-object vla_obj1) ); end while ); end defun Quote
Emmanuel Delay Posted January 7, 2020 Posted January 7, 2020 I found a clockwise/anti-clockwise detector. When it's clockwise the factor is -1, else it's 1. I rearranged your second while loop a bit, I think this is what you want. ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/polyline-direction-clockwise-or-counterclockwise/m-p/6051851#M339209 ; checking if pline drawn CW or CCW ; Writer Evgeniy Elpanov. ; Selection prompt and "clockwise/counter-clockwise" results added ; by Bill Gilliss ; Adapted by Emmanuel Delay, so as to have the object as a parameter, and the output as the return of the function. (defun isClockwise (lw / LW LST MAXP MINP clockwise) ;;(setq lw (vlax-ename->vla-object (car (entsel "\nSelect polyline: ")))) (vla-GetBoundingBox lw 'MinP 'MaxP) (setq minp (vlax-safearray->list minp) MaxP (vlax-safearray->list MaxP) lst (mapcar (function (lambda (x) (vlax-curve-getParamAtPoint lw (vlax-curve-getClosestPointTo lw x) ) ;_ vlax-curve-getParamAtPoint ) ;_ lambda ) ;_ function (list minp (list (car minp) (cadr MaxP)) MaxP (list (car MaxP) (cadr minp)) ) ;_ list ) ;_ mapcar ) ;_ setq (if (or (<= (car lst) (cadr lst) (caddr lst) (cadddr lst)) (<= (cadr lst) (caddr lst) (cadddr lst) (car lst)) (<= (caddr lst) (cadddr lst) (car lst) (cadr lst)) (<= (cadddr lst) (car lst) (cadr lst) (caddr lst)) ) ;_ or (setq clockwise T) (setq clockwise nil) ) ;_ if clockwise ) (defun c:offsetout ( / offset ent_point ent vla_obj offsetObj1 vla_obj1 fact) (while t (setq offset (getreal "\nInput offset distance : ")) (while (setq ent_point (entsel "\nSelect an object or press ESC :")) (setq ent (nth 0 ent_point)) (setq vla_obj (vlax-ename->vla-object ent)) (if (isClockwise vla_obj) (setq fact -1) (setq fact 1) ) (setq offsetObj1 (vla-Offset vla_obj (* fact offset))) ;;(setq vla_obj1 (vlax-ename->vla-object (car(offsetObj1)))) ) ; end while ); end while ); end defun Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.