draw a polyline, then offset it 7 cm, then erase the first polyline

draw a polyline, then offset it 7 cm, then erase the first polyline

Anonymous
Not applicable
2,149 Views
14 Replies
Message 1 of 15

draw a polyline, then offset it 7 cm, then erase the first polyline

Anonymous
Not applicable

i am new at autolisp

i tried to write the lisp by myself but i failed

it suppose to be easy for all you guys

thanx

0 Likes
Accepted solutions (2)
2,150 Views
14 Replies
Replies (14)
Message 2 of 15

dlanorh
Advisor
Advisor
Use the Offset command. If the drawing is in metres then offset distance is 0.07. If it is in millimetres the distance is 70.
Or is something else involved?

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

0 Likes
Message 3 of 15

Anonymous
Not applicable

thanks for reply.

but distance is not the point.

i need a lisp that can draw a polyline with my selected points, and then offsets it,and then erase the first polyline

0 Likes
Message 4 of 15

CodeDing
Advisor
Advisor

@Anonymous,

I believe this is what you're looking for. Double-check the units, and you will have to select which side to offset..

 

(defun c:OPL ( / ent)
;;Offset PolyLine

(command-s "_.PLINE")
(setq ent (entlast))
(prompt "\nSelect side to Offset...")

;;vvvvvvv Make sure units are correct vvvvvvvvv (70 is mm)
(command "_.OFFSET" 70 ent pause "")

(entdel ent)
(prompt "\nOPL Complete.")
(princ);finish quietly
);defun

 

Best,

~DD

0 Likes
Message 5 of 15

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous,

 

Correction.. Offset has a built-in erase function..

 

(defun c:OPL ()
;;Offset PolyLine
(command-s "_.PLINE")
;;vvvvvvv Make sure units are correct vvvvvvvvv (70 is mm)
(command "_.OFFSET" "e" "y" 70 (entlast) pause "")
(prompt "\nOPL Complete.")
(princ);finish quietly
);defun

 

Best,

~DD

Message 6 of 15

Anonymous
Not applicable

thank you CodeDing

i coppied all codes to visual lisp editor and loaded

then entered "opl" command

it only draws polyline nothing else..

what am i doing wrong?

0 Likes
Message 7 of 15

dlanorh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

thank you CodeDing

i coppied all codes to visual lisp editor and loaded

then entered "opl" command

it only draws polyline nothing else..

what am i doing wrong?


Try this modified version of @CodeDing's code. Once the offset has happened you will need to end the Offset command with a right mouse button click or enter.

(defun c:OPL ( / of_dist pl)
  (setq of_dist (getvar 'offsetdist))
  ;;Draw PolyLine
  (command "_.PLINE")
  (while (= (logand (getvar "cmdactive") 1) 1) 
    (command pause)
  )   
  ;;vvvvvvv Make sure units are correct vvvvvvvvv (70 is mm)
  (setvar 'offsetdist 70)
(setq pl (entlast));get last entity (command "_OFFSET" "" pl) (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (command "_erase" pl "");erase initial polyline (prompt "\nOPL Complete.") (setvar 'offsetdist of_dist) (princ);finish quietly );defun

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

Message 8 of 15

dlanorh
Advisor
Advisor
You should credit @CodeDing for the original code

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

Message 9 of 15

Anonymous
Not applicable

YES! EXACTLY

IT WORKS PERFECT

thank you dlanorh.

I hope someday I can help you too.thanx 🙂

0 Likes
Message 10 of 15

Anonymous
Not applicable

thanx dude.it is really helpful

0 Likes
Message 11 of 15

scottividal
Contributor
Contributor

Hello, I have been reading this thread and others that I found. Although I understood some things, I can't get a routine to work for me. I'm trying to create a routine that selects all the objects from a specific layer, rectangles, circles, or polylines, and applies an offset to them with a distance of D to the outside. But I can't get the offset to be created. Here is a portion of the code to see if you can help me:

 

(setvar "OFFSETGAPTYPE" 0)
  
(setq DISTANCIA 0.025)
  
(command "_.-layer" "_s" "LAYER1" "")
      
(setq N (sslength ELEMENT))
(setq I 0)
 
  (while (< I N)
    (setq ENAME (ssname ELEMENT I)) 
 
    (if (and (eq (cdr (assoc 0 (entget ENAME))) "LWPOLYLINE")
             (eq (cdr (assoc 8 (entget ENAME))) "LAYER1"))
        (command "_.OFFSET" "e" "y" DISTANCIA ENAME pause "")
    )
 
    (setq I (1+ I))
  ) 
ASV
0 Likes
Message 12 of 15

Kent1Cooper
Consultant
Consultant

@scottividal wrote:

.... I can't get the offset to be created. Here is a portion of the code ...:

....

        (command "_.OFFSET" "e" "y" DISTANCIA ENAME pause "")
.... 

Watch the command line:

 

Select object to offset or [Exit/Undo] <Exit>: {code feeds in your ENAME variable here}
*Invalid selection*
Expects a point or Exit

 

You can't give OFFSET just an entity name.  But giving it just a point can be dangerous, since the command could "see" something else that passes through the same point.  But you can combine an entity name with a determinable point, like what is returned by (entsel), and it will see only that entity at that point.  Try this:

 

        (command "_.OFFSET" "e" "y" DISTANCIA (list ENAME (vlax-curve-getStartPoint ENAME)) pause "")

Kent Cooper, AIA
0 Likes
Message 13 of 15

scottividal
Contributor
Contributor

Thank you for the prompt response.

It still doesn't work.
If I only apply (command "_.OFFSET" "e" "y" DISTANCE (list ENAME (vlax-curve-getStartPoint ENAME)) pause ""), it asks me to indicate an interior or exterior point of the object. And when I do that, it creates the offset by deleting the original object.
I need two things: a) to make it work without having to indicate a point for each object. b) to not delete the original object.

ASV
0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@scottividal wrote:

.... when I do that, it creates the offset by deleting the original object.

I need two things: a) to make it work without having to indicate a point for each object. b) to not delete the original object.


The deleting is because of the  "e" "y" part you have in there.  You can have that behave differently -- run the command manually to be sure of the prompts and the necessary answers.

 

The indicate-a-point part is also in your original [the pause is for that].  If you always want it outboard, you could try [simple, but in very limited circumstances could go wrong]:

        (command "_.OFFSET" "e" "n" DISTANCIA (list ENAME (vlax-curve-getStartPoint ENAME)) (getvar 'extmax) "")

Kent Cooper, AIA
0 Likes
Message 15 of 15

scottividal
Contributor
Contributor

Dear: Thank you very much, now it works. You have been very helpful!

ASV
0 Likes