Author Topic: Offset command - Layer and Erase options stored  (Read 4820 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Offset command - Layer and Erase options stored
« 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

Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff_M

  • King Gator
  • Posts: 4040
  • C3D user & customizer
Re: Offset command - Layer and Erase options stored
« Reply #1 on: October 04, 2011, 07:57:16 PM »
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.

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Offset command - Layer and Erase options stored
« Reply #2 on: October 04, 2011, 10:50:17 PM »
Thanks Jeff. I guess I'll just do it the hard way...

Offset to current layer:
Code: [Select]
(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:
Code: [Select]
(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)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10399
Re: Offset command - Layer and Erase options stored
« Reply #3 on: October 04, 2011, 11:27:38 PM »
Here is an old one I use:
Code: [Select]
;;=============================================================
;;     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)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Offset command - Layer and Erase options stored
« Reply #4 on: October 05, 2011, 11:45:40 AM »
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.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10399
Re: Offset command - Layer and Erase options stored
« Reply #5 on: October 05, 2011, 01:05:06 PM »
Oh another revision?  :-) :-)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Offset command - Layer and Erase options stored
« Reply #6 on: October 05, 2011, 01:10:54 PM »
Oh another revision?  :-) :-)
:lol: 4 revisions in 7 years is pretty good.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10399
Re: Offset command - Layer and Erase options stored
« Reply #7 on: October 05, 2011, 05:46:51 PM »
Still testing this one but seems to work.  8-)
Code: [Select]
;;=============================================================
;;     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)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Offset command - Layer and Erase options stored
« Reply #8 on: October 05, 2011, 10:59:17 PM »
Excellent idea Alan!

Here's mine modded...

Code: [Select]
(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)
)
« Last Edit: October 06, 2011, 12:20:13 AM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10399
Re: Offset command - Layer and Erase options stored
« Reply #9 on: October 05, 2011, 11:49:00 PM »
Nice idea for the layer name.  8-)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Offset command - Layer and Erase options stored
« Reply #10 on: October 06, 2011, 12:20:37 AM »
Nice idea for the layer name.  8-)
8-)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Offset command - Layer and Erase options stored
« Reply #11 on: October 06, 2011, 01:37:32 AM »
Updated to allow for offsetting of nested objects...


Find code here.


Do you think there's an issue with using (vlax-method-applicable-p <Object> 'Offset) for selection filtering?
« Last Edit: October 06, 2011, 02:48:22 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox