Command offset multiple times on same side

Command offset multiple times on same side

Anonymous
Not applicable
3,647 Views
12 Replies
Message 1 of 13

Command offset multiple times on same side

Anonymous
Not applicable

I have created a lisp where you select a line, choose a point to offset on, and multiple lines are created.

 

 (if
   (and (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
        (setq p (getpoint "\nSpecify point:"))
   )
    (progn
      
      (command "_.offset" 0.5 ss "_non" p "")
      (command "_.offset" 0.625 (ENTLAST) "_non" p "")
      (command "_.offset" 5.5 (ENTLAST) "_non" p "")
...

If the point chosen is passed by the multiple lines created, the the lines would offset going the opposite direction (back towards the point). I know this is how it is supposed to work, but I am wondering if there is a way to make all the lines offset going in the same direction. Any help would be greatly appreciated. Thanks!

0 Likes
Accepted solutions (1)
3,648 Views
12 Replies
Replies (12)
Message 2 of 13

dlanorh
Advisor
Advisor

It would probably be better putting it in a loop and pass in a list of distances

 

(if
   (and (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
        (setq p (getpoint "\nSpecify point:") dst 0)
   )
    (progn
      (setq lst (list 0.5 0.625 5.5))
     (foreach d lst
        (setq dst (+ d dst))
        (command "_.offset" dst ss "_non" p "")
     );end_foreach
   );end_progn
);end_if

I am not one of the robots you're looking for

Message 3 of 13

Anonymous
Not applicable

Hi dlanorh. Your code works well and can do what I was asking. However, I don't think I can use the loop because I am using command chprop to change the layer of the lines inbetween each offset command. Do you know a way without using a lisp, if that would be possible.

Thanks so much for helping me though. I will be using your code to see if it works with what I have.

0 Likes
Message 4 of 13

dlanorh
Advisor
Advisor
You can change the layer property of each line within the loop if that is required. Do the offset distances correspond to layers i.e. if the offset is 0.5 will the layer name of that line alway be the same? If not, it is possible to collect the distances and corresponding layers prior to execution.

It is also possible, if required, to offset both sides without having to select a side.

I am not one of the robots you're looking for

Message 5 of 13

Anonymous
Not applicable

No, the offset distances do not correspond to layers. I was thinking of doing what you suggested, creating a list of layer names as well, but I am not sure how to code it. 

What I was thinking with the for loop could be doable in other languages 

dist = [1,2,3,4]
layer=[a,b,c,d]

for i in range (0,4,1):
 offset dist[i] ...
 chprop layer[i] ...

Obviously this code is not correct, but I was wondering if there was a way to use the index in a list instead of the actual value.

 

 

 

0 Likes
Message 6 of 13

CodeDing
Advisor
Advisor

@Anonymous ,

 

Here is a way to offset both sides

(if (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
  (progn
    (setq dLst '((0.5 . "LyrA") (1.125 . "LyrB") (6.625 . "LyrC")))
    (repeat (setq cnt (sslength ss))
      (setq e (ssname ss (setq cnt (1- cnt))))
      (foreach d dLst
	(vla-offset (vlax-ename->vla-object e) (car d))
	(setq el1 (entlast))
	(vla-offset (vlax-ename->vla-object e) (- (car d)))
	(setq el2 (entlast))
	(if (setq lyr (tblobjname "LAYER" (cdr d)))
	  (progn
	    (setpropertyvalue el1 "LayerID" lyr)
	    (setpropertyvalue el2 "LayerID" lyr)
	  );progn
	  (prompt (strcat "\n...Layer \"" (cdr d) "\" not found."))
	);if
      );foreach
    );repeat
  );progn
);if

Hope that helps

~DD

0 Likes
Message 7 of 13

Anonymous
Not applicable

Codeding I am not trying to offset on both sides. I want to be able to make it so that the side a line is offsetted on is the same for all the lines. Thanks though.

0 Likes
Message 8 of 13

Kent1Cooper
Consultant
Consultant

How about just Offsetting the same original  each time, but summing up the distances for each one?  The point will always be on the right side, even when the result overshoots it.

 

      (command "_.offset" 0.5 ss "_non" p "")
      (command "_.offset" 1.125 ss "_non" p "")
      (command "_.offset" 6.625 ss "_non" p "")

 

Kent Cooper, AIA
Message 9 of 13

dlanorh
Advisor
Advisor
Accepted solution

Two way to achieve what you require using 2 lists and a list of lists. There is a purely vl lisp way of doing it as well

 

(defun c:o1 ( / ss p o_lst l_lst cnt dst lyr)
(if
   (and (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
        (setq p (getpoint "\nSpecify point:") dst 0)
   )
    (progn
      (setq o_lst (list 0.5 0.625 5.5)
            l_lst (list "1" "2" "3")
            cnt 0
      )
     
     (while (< cnt (length o_lst))
        (setq dst (+ (nth cnt o_lst) dst)
              lyr (nth cnt l_lst)
        )
        (command "_.offset" dst ss "_non" p "")
        (vlax-put-property (vlax-ename->vla-object (entlast)) 'layer lyr)
        (setq cnt (1+ cnt))
     );end_foreach
   );end_progn
);end_if
)

(vl-load-com)

(defun c:o2 ( / ss p o_lst dst lyr)
(if
   (and (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
        (setq p (getpoint "\nSpecify point:") dst 0)
   )
    (progn
      (setq o_lst (list (list 0.5 "1") (list 0.625 "2") (list 5.5 "3"))
      )
     
     (foreach d o_lst
        (setq dst (+ (car d) dst)
              lyr (cadr d)
        )
        (command "_.offset" dst ss "_non" p "")
        (vlax-put-property (vlax-ename->vla-object (entlast)) 'layer lyr)
     );end_foreach
   );end_progn
);end_if
)

I am not one of the robots you're looking for

Message 10 of 13

CodeDing
Advisor
Advisor

hahaha

 

@Kent1Cooper , that is where my mind was, but I was going down a rabbit hole!!! Was trying to incorporate vla-offset, but could not FOR THE LIFE OF ME figure out how to handle clockwise/counterclockwise polylines. UGHH.

 

K.I.S.S.

~DD

 

My painful rabbit hole accomplished nothing:

(defun off-test (e p / p2 ang)
(setq p2 (vlax-curve-getclosestpointto e p t)
      ang (angle p2 p))
 (if (< pi ang (* pi 2)) t nil)
);defun
(if (and (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
	 (setq p (getpoint "\nSpecify point: ")))
  (progn
    (setq dLst '((0.5 . "LyrA") (1.125 . "LyrB") (6.625 . "LyrC")))
    (repeat (setq cnt (sslength ss))
      (setq e (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (foreach d dLst
	(if (off-test e p) (setq d (cons (- (car d)) (cdr d))))
	(vla-offset e (car d))
	(setq el (entlast))
	(if (setq lyr (tblobjname "LAYER" (cdr d)))
	  (setpropertyvalue el "LayerID" lyr)
	  (prompt (strcat "\n...Layer \"" (cdr d) "\" not found."))
	);if
      );foreach
    );repeat
  );progn
);if
0 Likes
Message 11 of 13

Anonymous
Not applicable

Thanks dlanorh. I used your first solution and it worked very well. Thanks to everybody else for helping as well.

0 Likes
Message 12 of 13

Sea-Haven
Mentor
Mentor

Just my $0.05 a multi offset done previously works by just entering text with multiple offsets -ve values mean go left.

 

eg input 2,3,4,-2,-3,-4 would do offsets both sides. at 2, 3, 4.

 

Trying to find it possibly posted at Cadtutor. Could add like current layer plus offset as name.

 

 

0 Likes
Message 13 of 13

kibitotato
Advocate
Advocate

This thing is what exactly I need to save tons of time right now... but I´m not able to make it works...

Autocad said it to me

 

Precise distancia de desfase o [punto a Atravesar/Borrar/Capa] <0.5000>: 0.5
Designe objeto a desplazar o [Salir/Deshacer] <Salir>:
Precise punto en lado de desplazamiento o [Salir/Múltiple/Deshacer] <Salir>: _non
Designe objeto a desplazar o [Salir/Deshacer] <Salir>:
Comando: ; error: Error de automatización. Clave no encontrada

 

translate

 

Specify offset distance or [point to Traverse/Delete/Layer] <0.5000>: 0.5
Specify object to move or [Exit/Undo] <Exit>:
Precise point on offset side or [Exit/Multiple/Undo] <Exit>: _non
Designate object to move or [Exit/Undo/Exit] <Exit>:
Command: ; error: Automation error. Key not found

 

some help please? whats wrong???

0 Likes