Help with Offset in AutoLISP

Help with Offset in AutoLISP

justin6NFXF
Observer Observer
839 Views
6 Replies
Message 1 of 7

Help with Offset in AutoLISP

justin6NFXF
Observer
Observer

Hi, 

 

I am working on several different AutoLISP scripts and all of them have an offset in them but it keeps hanging up on the offset command and cancelling the command. Here is the command line output where it fails

Select polyline to offset:
Offset distance: 3.5
_.OFFSET
Current settings: Erase source=No Layer=Source OFFSETGAPTYPE=0
Specify offset distance or [Through/Erase/Layer] <Through>:
Requires numeric distance, two points, or option keyword.
; error: Function cancelled

 

This is the code that I am working with

(defun c:offset_polyline (/ pline offset)
  (setq pline (car (entsel "\nSelect polyline to offset: ")))
  (setq offset (getreal "\nOffset distance: "))
  (command "_.OFFSET" pline "" offset "L" "")
  (command "_.OFFSET" pline "" offset "R" "")
)

Where am I going wrong?

0 Likes
840 Views
6 Replies
Replies (6)
Message 2 of 7

devitg
Advisor
Advisor

@justin6NFXF As far as I know , neither L or R are option for OFFSET 

 

You can use OFFSET value + or - 

But not always it will work as you think 

One way is to check the offset'd poly LENGTH to the original poly   

 

 

 

 

 

0 Likes
Message 3 of 7

justin6NFXF
Observer
Observer

Okay, so what I am trying to do is select a polyline and have it offset in both directions by an distance that I input. Even simplifying the LISP to 

 

(defun c:offset_polyline (/ pline offset)
  (setq pline (car (entsel "\nSelect polyline to offset: ")))
  (setq offset (getreal "\nOffset distance: "))
  (command "_.OFFSET" pline "" offset "" "")
)

 

it returns the same error and keeps the offset command active. Am I missing a command or something? I can't even get it to offset a polyline.

0 Likes
Message 4 of 7

pbejse
Mentor
Mentor

What is "L" and "R"? does that represent direction "Left" and "Right" ?

(command "_.OFFSET" pline "" offset "L" "")
(command "_.OFFSET" pline "" offset "R" "")

If you read what is shown on the command line during offset command, the first prompt is for distance or options for either mode for Erase, keep layer as same as source or use current layer and an option to select distance by picking a point on screen.

Specify offset distance or [Through/Erase/Layer] <1.0000>:

So order should be 

(command "_.OFFSET" offset pline )

Which prompts the user to select which side to offset, but there's no "L" or "R" to choose from.

 

The way you had is right now is almost as if you're using the native offset command. What is the goal here? to offset  on both sides of multiple polylines?

 

 

0 Likes
Message 5 of 7

pbejse
Mentor
Mentor

Something similar to this

 

(defun c:offset_polyline (/ plines pline offset)
  (princ "\nSelect polyline(s) to offset: ")
(if  (and
       (setq plines  (ssget "_:L" '(( 0 . "LWPOLYLINE"))))
       (setq offset (getdist "\nOffset distance: "))
       )
  (repeat (Setq i (sslength plines))
    (setq pline (ssname plines (setq i (1- i))))
    (foreach v (list offset (- offset))
	 (vl-catch-all-error-p
		    (vl-catch-all-apply
		      'vla-offset
		      (list (vlax-ename->vla-object pline) v)
		      )
		    )
	  )
    )
  )
(princ)
)

 

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@justin6NFXF wrote:

I am working on several different AutoLISP scripts....

... what I am trying to do is select a polyline and have it offset in both directions by an distance that I input. ....


There are numerous routines out there to do this, for example two of them [a link and an attachment] >here<.

 

[And -- a pet peeve of mine -- an AutoLisp routine is not a script.  The word "Script" has a specific, and different (though related), meaning in AutoCAD.]

Kent Cooper, AIA
0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

A crude answer will do multiples enter 3.5 and -3.5 when asked. But note based on direction of the plines.

 

 

(defun c:moffs ( / obj lst n)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick pline "))))
(setq lst '())
(while (setq offnew (getreal "\nEnter a offset -ve for left Enter to exit "))
  (setq lst (cons offnew lst))
)

(foreach n lst
  (vl-catch-all-apply 'vlax-invoke (list obj 'offset n))
)
(princ)
)

; n is offset value note - is ok

 

 

0 Likes