TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: alanjt on October 04, 2011, 03:56:41 PM
-
Where are the variables determining the behavior of the offset command for Layer and Erase? Is it possible to set these without issuing the command?
OFFSET
Current settings: Erase source=No Layer=Source OFFSETGAPTYPE=0
-
I've been unable to locate these settings. They revert to No & Source for each session, which tells me they are global variables active only during a session. But they are not listed in the atoms-family, that I could find.
-
Thanks Jeff. I guess I'll just do it the hard way...
Offset to current layer:
(defun c:OL (/ *error* cmd od)
;; Offset to current Layer
;; Alan J. Thompson, 10.04.11
(vl-load-com)
(defun *error* (msg)
(or cmd (setq cmd (getvar 'CMDECHO)))
(setvar 'CMDECHO 0)
(vl-cmdf "_.offset" "_E" "_N" "_L" "_S" "" "_E")
(setvar 'CMDECHO cmd)
(and *AcadDoc* (vla-endundomark *AcadDoc*))
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
(princ (strcat "\nError: " msg))
)
)
(vla-startundomark
(cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
)
)
(setq cmd (getvar 'CMDECHO))
(setvar 'CMDECHO 0)
(vl-cmdf "_.offset" "_E" "_N" "_L" "_C" "" "_E")
(initget 6 "Through")
(vl-cmdf
"_.offset"
(cond ((getdist
(strcat "\nCurrent settings: Erase source=No Layer=Current OFFSETGAPTYPE="
(itoa (getvar 'OFFSETGAPTYPE))
"\nSpecify offset distance or [Through] <"
(if (minusp (setq od (getvar 'OFFSETDIST)))
(setq od "Through")
(rtos od)
)
">: "
)
)
)
(od)
)
)
(princ "\nSelect object to offset or [Exit/Undo] <Exit>: ")
(setvar 'CMDECHO 1)
(while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf PAUSE))
(*error* nil)
(princ)
)
Offset and erase source:
(defun c:OE (/ *error* cmd od)
;; Offset and Erase source
;; Alan J. Thompson, 10.04.11
(vl-load-com)
(defun *error* (msg)
(or cmd (setq cmd (getvar 'CMDECHO)))
(setvar 'CMDECHO 0)
(vl-cmdf "_.offset" "_E" "_N" "_L" "_S" "" "_E")
(setvar 'CMDECHO cmd)
(and *AcadDoc* (vla-endundomark *AcadDoc*))
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
(princ (strcat "\nError: " msg))
)
)
(vla-startundomark
(cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
)
)
(setq cmd (getvar 'CMDECHO))
(setvar 'CMDECHO 0)
(vl-cmdf "_.offset" "_E" "_Y" "_L" "_S" "" "_E")
(initget 6 "Through")
(vl-cmdf
"_.offset"
(cond ((getdist
(strcat "\nCurrent settings: Erase source=Yes Layer=Source OFFSETGAPTYPE="
(itoa (getvar 'OFFSETGAPTYPE))
"\nSpecify offset distance or [Through] <"
(if (minusp (setq od (getvar 'OFFSETDIST)))
(setq od "Through")
(rtos od)
)
">: "
)
)
)
(od)
)
)
(princ "\nSelect object to offset or [Exit/Undo] <Exit>: ")
(setvar 'CMDECHO 1)
(while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf PAUSE))
(*error* nil)
(princ)
)
-
Here is an old one I use:
;;=============================================================
;; OffSet_CMD.lsp by Charles Alan Butler
;; Copyright 2004
;; by Precision Drafting & Design All Rights Reserved.
;; Contact TheSwamp.org
;;
;; Version 1.0 July 29,2004
;; Version 1.1 July 30,2004
;; Version 1.2 April 10,2008
;; Version 1.4 June 28, 2011 added pickfirst code
;;
;; This is a replacement of the Offset command
;; 'ofs' offsets to the objects layer
;; option to place the new object on current layer
;; osmode is forced on for the distance pick and
;; turned off for the side pick
;;
;; Thanks to sinc -richards.64879 for the "Through" coding
;; I blended that idea with my old offset routine
;;=============================================================
(defun c:ofs ( / prv:dist usrcmd prm dist $dist ent pt clayer loop *error*)
(defun *error* (msg)
(if (not
(member msg '("console break" "Function cancelled" "quit / exit abort" "")))
(princ (strcat "\nError: " msg))
) ; if
(and usercmd (setvar "CMDECHO" usercmd))
(and useros (setvar "osmode" useros))
(and clayer (setvar "clayer" clayer))
(princ)
) ; end error function
;; variable L:flg is global:
;; When True, offset to current Layer
;; When nil, offset to objects layer
;; comment out the next line to retain settings else
(setq L:Flg nil) ; default offset to objects layer
(setq usrcmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq useros (getvar "osmode"))
(setvar "osmode" 175) ; my favorite setting
(setq clayer (getvar "clayer"))
(setq prv:dist (getvar "offsetdist"))
(if (> prv:dist 0); < 0 is "Through"
(setq dist (rtos prv:dist))
(setq prv:dist "Through"
dist prv:dist)
)
(setq $dist dist)
(while ; stay in loop while user toggles Layer
(or (initget (+ 4 64) "Through Layer") ; 2D positive number only
(= "Layer" (setq dist (getdist
(strcat "\nDistance to offset or [Through] <"
$dist "> or Toggle [Layer] is to "
(if L:flg "current" "original")": ")))))
;; L was pressed, so toggle flag
(setq L:flg (null L:flg))
) ; while
;; Pressing ENTER uses the previous value
(or dist (setq dist prv:dist))
(if (= 'real (type dist))
(setq prm "\nSelect side to offset:")
(setq prm "\nSelect through point:")
)
;; disable osnaps, same as [F3]
(if(<= (getvar "osmode") 15359)
(setvar "osmode" (boole 6 (getvar "osmode") 16384)))
(setvar "ERRNO" 0) ; reset to 0, so that the loop below works.
(while
(progn
;(and
;(null ; always True
(or (setq ss (cadr (ssgetfirst)))
(while ; loop until picked object or ENTER pressed
(and (null (setq ent (entsel "\nSelect object to offset or <exit>:")))
(= (getvar "errno") 7)
)
(prompt "\nMissed, Try again.")
) ; while
)
;) ; null always True
(if (and (or ss
(and ent ; something selected
(null (redraw (car ent) 3)) ; highlite ent
)
)
(setq pt (getpoint "\nSpecify point on side to offset:"))
)
(null ; always True, stay in loop
(and (null
(if ss
(command "_.offset" dist pt "")
(command "_.offset" dist ent pt "")
)) ; always True
L:flg ; if True continue
(command "._CHANGE" "L" "" "P" "LA" Clayer "")
))
;; ENTER pressed, we are done
) ; endif
) ; and
) ; end while
(*error* "")
(princ)
) ; defun
(prompt "\nOffset Loaded. Enter OFS to run.")
(princ)
-
Here is an old one I use:
Cool idea!
TBH, I just feel it easier to have separate commands for each - less prompts.
O - normal offset
OL - offset to current layer
OE - offset and erase source
I would consider checking to see if a new item was actually created before issuing the "CHANGE" command - select a 3dpolyline.
-
Oh another revision? :-) :-)
-
Oh another revision? :-) :-)
:lol: 4 revisions in 7 years is pretty good.
-
Still testing this one but seems to work. 8-)
;;=============================================================
;; OffSet_CMD.lsp by Charles Alan Butler
;; Copyright 2004-2011
;; by Precision Drafting & Design All Rights Reserved.
;; Contact at TheSwamp.org
;;
;; Version 1.0 July 29,2004
;; Version 1.1 July 30,2004
;; Version 1.2 April 10,2008
;; Version 1.4 June 28, 2011 added pickfirst code
;; Version 1.5bata Oct 5, 2011 command line entry options
;;
;; This is a replacement of the Offset command
;; 'ofs' offsets to the objects layer
;; option to place the new object on current layer
;; osmode is forced on for the distance pick and
;; turned off for the side pick
;;
;; Thanks to sinc -richards.64879 for the "Through" coding
;; I blended that idea with my old offset routine
;;=============================================================
(defun c:ofs () (ofs nil nil)) ; normal offset
(defun c:ol () (ofs t nil)) ; OL - offset to current layer
(defun c:oe () (ofs nil t)) ; OE - offset and erase source
(defun ofs (2Layer EraseSource / ss prv:dist usrcmd prm dist $dist ent pt clayer loop *error*)
(defun *error* (msg)
(if (not
(member msg '("console break" "Function cancelled" "quit / exit abort" "")))
(princ (strcat "\nError: " msg))
) ; if
(and usercmd (setvar "CMDECHO" usercmd))
(and useros (setvar "osmode" useros))
(and clayer (setvar "clayer" clayer))
(princ)
) ; end error function
;; variable L:flg is global:
;; When True, offset to current Layer
;; When nil, offset to objects layer
;; comment out the next line to retain settings else
(setq L:Flg 2Layer) ; flag offset to objects layer
(setq usrcmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq useros (getvar "osmode"))
(setvar "osmode" 175) ; my favorite setting
(setq clayer (getvar "clayer"))
(setq prv:dist (getvar "offsetdist"))
(if (> prv:dist 0); < 0 is "Through"
(setq dist (rtos prv:dist))
(setq prv:dist "Through"
dist prv:dist)
)
(setq $dist dist)
(while ; stay in loop while user toggles Layer
(or (initget (+ 4 64) "Through Layer") ; 2D positive number only
(= "Layer" (setq dist (getdist
(strcat "\nDistance to offset or [Through] <"
$dist "> or Toggle [Layer] to "
(if L:flg "current" "original")": ")))))
;; L was pressed, so toggle flag
(setq L:flg (null L:flg))
) ; while
;; Pressing ENTER uses the previous value
(or dist (setq dist prv:dist))
(if (= 'real (type dist))
(setq prm (strcat "\n" (if EraseSource "[Erase Source] " "") "Select side to offset:"))
(setq prm (strcat "\n" (if EraseSource "[Erase Source] " "") "Select through point:"))
)
;; disable osnaps, same as [F3]
(if(<= (getvar "osmode") 15359)
(setvar "osmode" (boole 6 (getvar "osmode") 16384)))
(setvar "ERRNO" 0) ; reset to 0, so that the loop below works.
(while
(progn
;(and
;(null ; always True
(or (setq ss (cadr (ssgetfirst)))
(while ; loop until picked object or ENTER pressed
(and (null (setq ent (car (entsel "\nSelect object to offset or <exit>:"))))
(= (getvar "errno") 7)
)
(prompt "\nMissed, Try again.")
) ; while
)
;) ; null always True
(if (and (or (and ss (setq ent (ssname ss 0)))
(and ent ; something selected
(null (redraw ent 3)) ; highlite ent
)
)
(setq pt (getpoint (strcat "\n" (if EraseSource "[Erase Source] " "")
"Specify point on side to offset:")))
)
;; New v1.5
(progn ; always True, stay in loop
(command "_.offset" dist ent pt "")
(if (not (eq ent (entlast)))
(progn
(if L:flg (command "._CHANGE" "L" "" "P" "LA" Clayer ""))
(if EraseSource (entdel ent))
)
)
t
)
;; ENTER pressed, we are done
) ; endif
) ; and
) ; end while
(*error* "")
(princ)
) ; defun
(prompt "\nOffset Loaded. Enter OFS to run.")
(princ)
-
Excellent idea Alan!
Here's mine modded...
(defun c:OLE nil (_Offset T T) (princ))
(defun c:OL nil (_Offset T nil) (princ))
(defun c:OE nil (_Offset nil T) (princ))
(defun c:OP nil (_Offset "PIZZA" nil) (princ))
(defun c:O nil (_Offset nil nil) (princ))
(defun _Offset (layer erase / *error* cmd od ent)
;; Offset with options
;; layer - T for current layer, nil for source or desired layer name
;; erase - T to erase source, nil to not
;; Alan J. Thompson, 10.05.11
(vl-load-com)
(defun *error* (msg)
(or cmd (setq cmd (getvar 'CMDECHO)))
(setvar 'CMDECHO 0)
(vl-cmdf "_.offset" "_E" "_N" "_L" "_S" "" "_E")
(setvar 'CMDECHO cmd)
(and *AcadDoc* (vla-endundomark *AcadDoc*))
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
(princ (strcat "\nError: " msg))
)
)
(vla-startundomark
(cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
)
)
(setq ent (entlast)
cmd (getvar 'CMDECHO)
)
(setvar 'CMDECHO 0)
(if erase
(vl-cmdf "_.offset" "_E" "_Y" "_L" "_S" "" "_E")
(vl-cmdf "_.offset" "_E" "_N" "_L" "_S" "" "_E")
)
(initget 6 "Through")
(vl-cmdf
"_.offset"
(cond
((getdist
(strcat "\nCurrent settings: Erase source="
(if erase
"Yes"
"No"
)
" Layer="
(cond ((not layer) "Source")
((and (eq (type layer) 'STR) (not (snvalid layer))) (setq layer nil) "Source")
((or (eq layer T) (eq (strcase layer) (strcase (getvar 'CLAYER)))) "Current")
(layer)
)
" OFFSETGAPTYPE="
(itoa (getvar 'OFFSETGAPTYPE))
"\nSpecify offset distance or [Through] <"
(if (minusp (setq od (getvar 'OFFSETDIST)))
(setq od "Through")
(rtos od)
)
">: "
)
)
)
(od)
)
)
(princ "\nSelect object to offset or [Exit/Undo] <Exit>: ")
(setvar 'CMDECHO 1)
(vl-cmdf PAUSE)
(while (eq (logand 1 (getvar 'CMDACTIVE)) 1)
(vl-cmdf PAUSE)
(if (and layer (not (equal ent (setq ent (entlast)))))
(entupd (cdr (assoc -1
(entmod (subst (cons 8
(if (eq layer T)
(getvar 'CLAYER)
layer
)
)
(assoc 8 (entget ent))
(entget ent)
)
)
)
)
)
)
)
(*error* nil)
(princ)
)
-
Nice idea for the layer name. 8-)
-
Nice idea for the layer name. 8-)
8-)
-
Updated to allow for offsetting of nested objects...
Find code here. (http://www.theswamp.org/index.php?topic=39665.new#new)
Do you think there's an issue with using (vlax-method-applicable-p <Object> 'Offset) for selection filtering?