Originally Posted by
g.johnston222936339
... there's two additions I'd like to make, but have no clue how to go about it.
1. I would like the offset distance to be remembered, such as it does with the normal offset command (just hit enter when asked for the distance to accept the previous value)
2. Ask if I would like to keep the selected line or not (Y=yes to keep, N=no to delete)
Can anyone help me add these options?
When dealing with settings there's two general directions one can go... Temporary or Persistent settings.
The former would generally be considered 'global variables' in LISP, and only exist within the drawing that they were given a value.
The latter allow for your settings to exist beyond closing of a given Document. This can be done either by internally saving to the Document via Dictionary, or XRecord, Custom Property, etc. (which may not be accessible to other Documents), or by storing to an external location, such as to File, or most commonly to Registry.
For the purposes of this example, we'll save to a simple pair of global variables... Written quickly, I believe that this will get you started:
Code:
(vl-load-com)
(defun c:OF+ () (c:OffsetPlus))
(defun c:OffsetPlus (/ *error* _OffsetPlus:Settings _OffsetPlus:Distance
sel dist v acDoc
)
(defun *error* (msg)
(if acDoc
(vla-endundomark acDoc)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(defun _OffsetPlus:Settings (/ erase)
(initget "No Yes")
(or (setq erase
(getkword
(strcat "\nErase selection [No/Yes]"
(if *OffsetPlus_Erase*
" <Yes>: "
": "
)
)
)
)
(setq erase *OffsetPlus_Erase*)
)
(setq *OffsetPlus_Erase*
(if (= "No" erase)
nil
T
)
)
(c:OffsetPlus)
)
(defun _OffsetPlus:Distance (sel / dist)
(not (initget (+ 32 128)))
(or (setq dist
(getdist
(cadr sel)
(strcat "\nSpecify offset distance"
(if *OffsetPlus_Distance*
(strcat " <" (rtos *OffsetPlus_Distance*) ">: ")
": "
)
)
)
)
(setq dist *OffsetPlus_Distance*)
)
(setq *OffsetPlus_Distance* dist)
)
(if
(and
(or
(setq sel
(entsel "\nSelect object to offset, <Enter> for Settings: "
)
)
(_OffsetPlus:Settings)
)
(_OffsetPlus:Distance sel)
(setq v (vlax-ename->vla-object (car sel)))
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(foreach d (list (abs *OffsetPlus_Distance*)
(* -1.0 *OffsetPlus_Distance*)
)
(vla-offset v d)
)
(if *OffsetPlus_Erase*
(vla-delete v)
(progn
(if (not (tblsearch "ltype" "center"))
(vla-load (vla-get-linetypes acDoc) "center" "ACAD.LIN")
)
(vla-put-linetype v "center")
)
)
)
)
(*error* nil)
)
** Edit to add - I've also included 'undo' functionality, FWIW.
HTH