(defun Hatch2Back ( / ss)
(if (setq ss (ssget "x" '((0 . "HATCH"))))
(command "_.draworder" ss "")
)
(princ)
)
(defun VLR_COMMAND-IT ()
(vl-load-com)
(vlr-command-reactor nil '((:vlr-commandWillStart . startCommand)))
(vlr-command-reactor nil '((:vlr-commandEnded . endCommand)))
(vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand)))
)
(defun startCommand (calling-reactor startcommandInfo / thecommandstart)
(cond
((= thecommandstart "SAVE") (Hatch2Back))
((= thecommandstart "QSAVE") (Hatch2Back))
((= thecommandstart "SAVEAS")(Hatch2Back))
)
)
(defun endCommand (calling-reactor endcommandInfo / thecommandend)
;;; Do something here....
)
(defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel)
;;; Do something here...
)
(VLR_COMMAND-IT) ; Auto-load the reactors
(princ)
(defun hatch2back (/ doc exd hatches ms sorttbl)
;; Sends modelspace hatches to back
(setq ms (vla-get-modelspace (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
(setq exd (vla-getextensiondictionary ms))
(if (vl-catch-all-error-p
(setq sorttbl (vl-catch-all-apply 'vla-getobject (list exd "acad_sortents")))
)
(setq sorttbl (vla-addobject exd "acad_sortents" "acdbsortentstable"))
)
(vlax-for o ms
(if (= "AcDbHatch" (vla-get-objectname o))
(setq hatches (cons o hatches))
)
)
(and hatches (vlax-invoke sorttbl 'movetobottom hatches))
;;(vla-regen doc acallviewports)
(princ)
)
(or *startcommandreactor*
(setq *startcommandreactor* (vlr-command-reactor nil '((:vlr-commandwillstart . strtcmd))))
)
(defun strtcmd (calling-reactor strtcmdinfo)
(and (wcmatch (car strtcmdinfo) "SAVE,QSAVE,SAVEAS") (hatch2back))
)
(defun hatch2back (/ doc exd hatches ms sorttbl)
;; Sends modelspace hatches to back
(setq ms (vla-get-modelspace (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
(setq exd (vla-getextensiondictionary ms))
(if (vl-catch-all-error-p
(setq sorttbl (vl-catch-all-apply 'vla-getobject (list exd "acad_sortents")))
)
(setq sorttbl (vla-addobject exd "acad_sortents" "acdbsortentstable"))
)
(vlax-for o ms
(if (= "AcDbHatch" (vla-get-objectname o))
(setq hatches (cons o hatches))
)
)
(and hatches (vlax-invoke sorttbl 'movetobottom hatches))
;;(vla-regen doc acallviewports)
(princ)
)
(defun images2back (/ doc3 exd3 images ms3 sorttbl3)
;; Sends modelspace hatches to back
(setq ms3 (vla-get-modelspace (setq doc3 (vla-get-activedocument (vlax-get-acad-object)))))
(setq exd3 (vla-getextensiondictionary ms3))
(if (vl-catch-all-error-p
(setq sorttbl3 (vl-catch-all-apply 'vla-getobject (list exd3 "acad_sortents")))
)
(setq sorttbl3 (vla-addobject exd3 "acad_sortents" "acdbsortentstable"))
)
(vlax-for o ms3
(if (= "AcDbRasterImage" (vla-get-objectname o))
(setq images (cons o images))
)
)
(and images (vlax-invoke sorttbl2 'movetobottom images))
;;(vla-regen doc acallviewports)
(princ)
)
(or *startcommandreactor*
(setq *startcommandreactor* (vlr-command-reactor nil '((:vlr-commandwillstart . strtcmd))))
)
(defun strtcmd (calling-reactor strtcmdinfo)
(and (wcmatch (car strtcmdinfo) "SAVE,QSAVE,SAVEAS,PLOT") (progn (hatch2back) (images2back) ) ))
)
(and images (vlax-invoke sorttbl2 'movetobottom images))
(and images (vlax-invoke sorttbl3 'movetobottom images))
That works really well, Lee. Thanks!