Tweaking current buffer autolisp

Tweaking current buffer autolisp

sazurich
Participant Participant
430 Views
2 Replies
Message 1 of 3

Tweaking current buffer autolisp

sazurich
Participant
Participant

Hi,

I've got autolisp that makes buffer around polyline at set distance. got it from somewhere i dont know how to write one myself.

But i would like to make few tweaks to it, if its possible.

Lisp goes like this right now: run command, set distance of buffer (for one side, so its doubled at the end), and then i need to manually click 1 polyline at the time, then the buffer is created in same layer as that polyline is.

So my question is:

Is it possible to tweak lisp so that it goes like this: first i select all polylines that i want buffer created around(even the double polynes; on top of each other), then run command, set distance, choose layer in which said buffer will be created, and thats it. buffers are created around all selected polylines.

Here is the current code: Offest both sides join (name) OBSJ

 

;; OffsetBothSidesJoin.lsp [command name: OBSJ]
;; To Offset the same object to Both Sides at the same distance, and
;; if open-ended, Join the resulting objects with PEDIT.
;; On first use, offers regular Offset command's default distance,
;; but only if numerical [not "Through"].
;; Remembers specified offset distance, separately from regular
;; Offset command's default, and offers as default on later use.
;; Kent Cooper, 21 March 2014
;
(defun C:OBSJ (/ osd disttemp obj); = Offset to Both Sides
;
(setq osd (getvar 'offsetdist))
(setvar 'peditaccept 1)
;
(if *obsjdist (initget 6) (initget 7))
; no 0, no negative, no Enter on first use
(setq
disttemp
(getdist
(strcat
"\nBoth-sides-offset distance"
(strcat
(if (or *obsjdist (> osd 0))
(strcat ; then - construct default
" <"
(if *obsjdist
(rtos *obsjdist)
(rtos osd)
); end if
">"
); end strcat
"" ; else - no default offered on first use if Offset's is Through
); end if
); end strcat
": "
); end strcat
); end getdist
*obsjdist
(cond
(disttemp); User specified something other than Enter - use it
(*obsjdist); Enter with prior value set - use that
((> osd 0) osd)
; Enter on first use with non-Through Offset default - use that
); end cond & *obsjdist
); end setq
;
(while T
(if
(setq obj
(vlax-ename->vla-object
(car (entsel "\nSelect object to Offset to Both Sides [Esc to exit]: "))
); end vlax-...
); end setq
(progn
(vla-offset obj *obsjdist)
(setq ent1 (entlast))
(vla-offset obj (- *obsjdist))
(if (not (vlax-curve-isClosed obj)); e.g. Line, Arc, open Polyline
(command "_.pedit" "_m" ent1 (entlast) "" "_j" "_j" "_b" (* *obsjdist 2.5) "")
); if
); end progn
); end if
); end while
;
(princ)
); end defun
(prompt "Type OBSJ to Offset to Both Sides by the same distance and Join if possible.")

 

Code is not mine, credit to who ever made it 😄

 

Thank in advance

 

 

0 Likes
Accepted solutions (1)
431 Views
2 Replies
Replies (2)
Message 2 of 3

komondormrex
Mentor
Mentor
Accepted solution

hey,

(defun C:OBSJ (/ osd disttemp obj); = Offset to Both Sides
;
(setq objects_list (mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp
(mapcar 'cadr
(ssnamex (ssget '((0 . "*line,arc"))))
)
)
)
)
(setq osd (getvar 'offsetdist))
(setvar 'peditaccept 1)
;
(if *obsjdist (initget 6) (initget 7))
; no 0, no negative, no Enter on first use
(setq
disttemp
(getdist
(strcat
"\nBoth-sides-offset distance"
(strcat
(if (or *obsjdist (> osd 0))
(strcat ; then - construct default
" <"
(if *obsjdist
(rtos *obsjdist)
(rtos osd)
); end if
">"
); end strcat
"" ; else - no default offered on first use if Offset's is Through
); end if
); end strcat
": "
); end strcat
); end getdist
*obsjdist
(cond
(disttemp); User specified something other than Enter - use it
(*obsjdist); Enter with prior value set - use that
((> osd 0) osd)
; Enter on first use with non-Through Offset default - use that
); end cond & *obsjdist
); end setq
;
(command "_-layer" "?" "*" "_s" pause "")
(foreach obj objects_list
(vla-offset obj *obsjdist)
(setq ent1 (entlast))
(entmod (subst (cons 8 (getvar 'clayer)) (assoc 8 (entget ent1)) (entget ent1)))
(vla-offset obj (- *obsjdist))
(if (not (vlax-curve-isClosed obj)); e.g. Line, Arc, open Polyline
(command "_.pedit" "_m" ent1 (entlast) "" "_j" "_j" "_b" (* *obsjdist 2.5) "")
)
(entmod (subst (cons 8 (getvar 'clayer)) (assoc 8 (entget (entlast))) (entget (entlast))))
)
;
(princ)
); end defun
(prompt "Type OBSJ to Offset to Both Sides by the same distance and Join if possible.")

0 Likes
Message 3 of 3

sazurich
Participant
Participant

thanks thats it. for what i tried works perfectly

0 Likes