(defun C:HATCHBACK ( / hss cmd)
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq hss (ssget "X" (list (cons 0 "HATCH"))))
(command "_.draworder" "p" "" "back")
(setvar "cmdecho" 1)
(princ)
)
It is possible to do this in model and paper space at the same time? Like in on shot?
Thanks!
@msarqui wrote:(defun C:HATCHBACK ( / hss cmd)
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq hss (ssget "X" (list (cons 0 "HATCH"))))
(command "_.draworder" "p" "" "back")
(setvar "cmdecho" 1)
(princ)
)
It is possible to do this in model and paper space at the same time? Like in on shot?....
Commands that use object selection, even when used in AutoLISP (command) functions, only "see" objects in the current space. I looked for something in objects' entity data or VLA Properties or extended data that changed when I sent them to the back, but I didn't find anything, so I'm not sure what it does to them that might be done by way of (entmod) or (vla-put...) or something, so that you could do it even to things not in the current space.
If there isn't a way like that, you can always resort to changing the space you're in to do each one [untested]:
(defun C:HATCHBACK (/ cmd curtab)
(setq
cmd (getvar 'cmdecho)
curtab (getvar 'ctab); save starting space
); setq
(setvar 'cmdecho 0)
(foreach h (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "HATCH")))))
; list of Hatch entity names
(setvar 'ctab (cdr (assoc 410 (entget h)))); move to its space
(command "_.draworder" h "" "back")
); foreach
(setvar 'cmdecho 1)
(setvar 'ctab curtab); restore starting space
(princ)
)
@msarqui wrote:Thanks for the reply Kent.
It is not working. My AutoCAD stops...
It works for me, though in very limited testing. Try commenting out the turning off of the CMDECHO System Variable, and see whether you can tell what's not working. Also, I'm still way back in 2004 -- if you're not, might the command prompt sequence have changed in a newer version?
@msarqui wrote:
It is possible to do this in model and paper space at the same time? Like in on shot?
Thanks!
Not one shot but sorta 🙂
(defun c:HatchBack (/ HatchColl Dict sorttable) (vlax-for layout (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (setq HatchColl nil Dict (vla-getextensiondictionary layout)) (if (vl-catch-all-error-p (setq sorttable (vl-catch-all-apply 'vla-item (list dict "ACAD_SORTENTS")))) (setq sorttable (vla-addObject dict "ACAD_SORTENTS" "AcDbSortentsTable"))) (vlax-for itm layout (if (eq (vla-get-objectname itm) "AcDbHatch") (setq HatchColl (cons itm HatchColl)))) (and HatchColl (vlax-invoke sorttable 'MoveToBottom HatchColl) ) )(princ) )