Author Topic: Multiple offset  (Read 222 times)

0 Members and 1 Guest are viewing this topic.

Romero

  • Newt
  • Posts: 23
Multiple offset
« on: March 20, 2020, 05:44:05 PM »
How are you. Greetings to all the members of this wonderful forum.
Once again here I ask for your help. Maybe someone can guide me.

I found a Lisp code that is very useful for me, but unfortunately I cannot adapt it to my needs.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:MOFF (/ ss tmp safe lst)
  2. (or *moff (setq *moff 10.0))
  3. (if (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE"))))
  4. (and (setq tmp (getdist (strcat "\nSpecify Offset <" (vl-princ-to-string *moff) "> : ")))
  5. (setq *moff tmp))
  6. (foreach var (mapcar (function (lambda (x) (vla-offset x *moff)))
  7. (mapcar 'vlax-ename->vla-object
  8. (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
  9.  
  10. (setq safe (vlax-variant-value var)) 1))
  11. (setq lst (cons (vlax-safearray->list safe) lst)))))
  12. (foreach Obj (setq lst (apply 'append lst))
  13. (lambda (x)
  14. (vlax-invoke obj 'IntersectWith x acExtendNone)))
  15. (vl-remove Obj lst))
  16. (vla-put-color Obj acred)))
  17.  

What does the current code do?
You have the possibility to create offset of multiple objects, (with an object filter). But I can only enter a distance.

What would I like to add?
To be able to append a cycle (While) to ask the user for more distances and to create multiple offset, but with the distances that the user enters.

Attachment dwg

Anticipating thanks. Any help is welcome.







BIGAL

  • Bull Frog
  • Posts: 425
  • 30 + years of using Autocad
Re: Multiple offset
« Reply #1 on: March 21, 2020, 02:00:56 AM »
Something not quite right but when you press enter for last offset will draw then code needs a reshuffle to draw at each offset.

Please test.

Code: [Select]
(defun c:MOFF (/ ss tmp safe lst *moff)
(vl-load-com)
(or *moff (setq *moff 0.0))
(setq doc (vla-get-ActiveDocument
(vlax-get-acad-object)))
(if (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE"))))
(princ)
(progn (alert "Objects not supported now exiting")(exit))
)
(initget 6)
(while (setq tmp (getdist (strcat "\nSpecify Offset <" (vl-princ-to-string *moff) "> : ")))
(setq *moff (+ *moff tmp))
(vla-StartUndoMark doc)
(setq lst '())
(foreach var (mapcar (function (lambda (x) (vla-offset x *moff)))
(mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
(cond ((<= 0 (vlax-safearray-get-u-bound
(setq safe (vlax-variant-value var)) 1))
(setq lst (cons (vlax-safearray->list safe) lst)))))
(foreach Obj (setq lst (apply 'append lst))
(if (vl-some
(function
(lambda (x)
(vlax-invoke obj 'IntersectWith x acExtendNone)))
(vl-remove Obj lst))
(vla-put-color Obj acred))
)
(vla-EndUndoMark doc)
)
(princ)
)
(c:moff)
A man who never made a mistake never made anything

CodeDing

  • Mosquito
  • Posts: 2
Re: Multiple offset
« Reply #2 on: March 21, 2020, 06:06:21 PM »
Romero,

Based on the example drawing you posted, will all of your future situations be similar? An always horizontal line? offsetting up or down?

If this is the case, why make this harder than necessary, when we can use copy and just keep copying the object down?

Code: [Select]
.....
(setq d 0.0 e (entsel "\nSelect object to copy: "))
(while (progn (initget 6) (setq newD (getreal "\nEnter additional incremental distance: ")))
  (setq d (+ d newD))
  (command "_.COPY" (car e) "" "_non" (cadr e) "_non" (strcat "@" (rtos d) "<270"))
);while
.....

Romero

  • Newt
  • Posts: 23
Re: Multiple offset
« Reply #3 on: March 23, 2020, 12:07:49 PM »
Something not quite right but when you press enter for last offset will draw then code needs a reshuffle to draw at each offset.

Please test.



Bigal, thank you very much for the help provided. The code works perfectly. Just what I needed
« Last Edit: March 23, 2020, 12:31:14 PM by Romero »

Romero

  • Newt
  • Posts: 23
Re: Multiple offset
« Reply #4 on: March 23, 2020, 01:01:19 PM »
Romero,
Based on the example drawing you posted,
CodeDing, thank you very much for the help provided.

will all of your future situations be similar?
In most cases I will use horizontal polylines; although sometimes I will use other objects

An always horizontal line?
no, sometimes I use rectangles; this is why the code should behave like an offset and not like a copy

offsetting up or down?
they will always be downward offsets in the case of horizontal polylines.

If this is the case, why make this harder than necessary, when we can use copy and just keep copying the object down?
However, I found your code interesting for when I use it with horizontal polylines. Unfortunately I ran into some inconveniences.

If I use "entsel" I can only select one object at a time, and that is not helpful for me because the idea is to save work selecting multiple lines / plines.

try changing to "ssget" with a selection filter, but the offset only affects the first object. How could I solve this problem?
I appreciate you.