Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Hatch to back" reactor

12 REPLIES 12
Reply
Message 1 of 13
kieren.aubrey
1705 Views, 12 Replies

"Hatch to back" reactor

Hi all!
Does anyone have a reactor or something that ensures all hatch is "sent to back"?
If so, is there any chance of sharing please??

I know nothing of reactors. I do have a routine to send all hatch to back on demand, but would really like something that does it automatically.

Many thanks in advance
HOLLY Message was edited by: Holly
Attrocious spelling!
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: kieren.aubrey

... are you aware of the system variable HPDRAWORDER ? This variable has 5
options, one of which forces all new hatches to the back.

But of course if you are looking at changing existing hatches in existing
drawings... ignore the above!

Ian



wrote in message news:5193269@discussion.autodesk.com...
Hi all!
Does anyone have a reactor or something that ensures all hatch is "sent to
back"?
If so, is there any chance of sharing please??

I know nothing of reactors. I do have a routine to send all hatch to back on
demand, but would really like something that does it automatically.

Many thanks in advance
HOLLY

Message was edited by: Holly
Attrocious spelling!
Message 3 of 13

Hi Ian,
Wasn't aware of HPDRAWORDER - ansd so it seems neither is my version of AutoCAD!!! 2004.0.0

Copy of command line below:
-----------------------------------------------------------------------
Command: hpdraworder
Unknown command "HPDRAWORDER". Press F1 for help.
Command: setvar
Enter variable name or [?] : hpdraworder
Unknown variable name. Type SETVAR ? for a list of variables.
-----------------------------------------------------------------------

Cheers,
HOLLY
Message 4 of 13
Anonymous
in reply to: kieren.aubrey

> I know nothing of reactors. I do have a routine to send all hatch to back
> on demand, but would really like something that does it automatically.

In real time or when you do a specific action ? In real time, on all hatchs
of a drawing, I'm septic that it's possible.

Bruno Toniutti
(sorry for my english level)
Message 5 of 13
Anonymous
in reply to: kieren.aubrey

Give this a shot.

; - Initialize ActiveX support
;(vl-load-com)
;
; - Reactors ------------------------------------------------------------------
;
; - If not set, initialize DocManager-Reactor
(or Me:ReaDma
(setq Me:ReaDma (VLR-DocManager-Reactor
nil
'(
(:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
)
)
)
)
; - If not set, initialize Command-Reactor
(or Me:ReaCom
(setq Me:ReaCom (VLR-Command-Reactor
nil
'(
(:VLR-commandEnded . MeCommandEndedCallbacks)
)
)
)
)
;
; - Notifications -------------------------------------------------------------
;
; - CommandEnded notifications
(defun MeCommandEndedCallbacks (Rea Arg)
(MeDoCmdEndedStuff Arg)
(princ)
)
; - DocToBeDestroyed notifications
(defun MeDocToBeDestroyedCallbacks (Rea Arg)
(MeDoCloseStuff)
(princ)
)
;
; - Subs ----------------------------------------------------------------------
;
; - Command ended function
(defun MeDoCmdEndedStuff (Arg / CurCmd ObjNme TmpObj)
(setq CurCmd (strcase (car Arg)))
(cond
((vl-position CurCmd '("BHATCH" "HATCH" "IMAGEATTACH" "SOLID"))
(setq TmpObj (vlax-ename->vla-object (entlast))
ObjNme (vla-get-ObjectName TmpObj)
)
(if (vl-position ObjNme '("AcDbHatch" "AcDbRasterImage" "AcDbSolid"))
(MeSetDrawOrder (list TmpObj) nil 'MoveToBottom)
)
)
;;; other command ended dependent functions
)
(princ)
)
; - Reactor cleanup function
(defun MeDoCloseStuff ( / VarLst)
(setq VarLst (MeGetReaVars))
(mapcar 'VLR-remove (mapcar 'eval VarLst))
(mapcar '(lambda (l) (set l nil)) VarLst)
(princ)
)
; - Collect global reactor variables
(defun MeGetReaVars ( / RetVal)
(foreach memb (atoms-family 1)
(if (wcmatch (strcase memb) "ME:REA*")
(setq RetVal (cons memb RetVal))
)
)
(mapcar 'read RetVal)
)
; - Set object draw order
(defun MeSetDrawOrder (Obl Tob Mde / AcaDoc ExtDic SreTbl)
(setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
ExtDic (vla-GetExtensionDictionary (vla-get-ModelSpace AcaDoc))
)
(if (vl-catch-all-error-p
(setq SreTbl (vl-catch-all-apply
'vla-Item (list ExtDic "ACAD_SORTENTS")
)
)
)
(setq SreTbl (vla-AddObject ExtDic "ACAD_SORTENTS" "AcDbSortentsTable"))
)
(cond
((vl-position Mde '(MoveToTop MoveToBottom))
(not (vlax-Invoke SreTbl Mde Obl))
)
(Tob
(not (vlax-Invoke SreTbl Mde Obl Tob))
)
)
)
; - Set hatch/image draw order on startup
(defun MeSendRasterAndImageToBottom ( / CurEnt CurSet ObjLst)
(if (setq CurSet (ssget "X" '((0 . "HATCH"))))
(progn
(while (setq CurEnt (ssname CurSet 0))
(setq ObjLst (cons (vlax-ename->vla-object CurEnt) ObjLst))
(ssdel CurEnt CurSet)
)
(MeSetDrawOrder ObjLst nil 'MoveToBottom)
)
)
(setq ObjLst '())
(if (setq CurSet (ssget "X" '((0 . "SOLID"))))
(progn
(while (setq CurEnt (ssname CurSet 0))
(setq ObjLst (cons (vlax-ename->vla-object CurEnt) ObjLst))
(ssdel CurEnt CurSet)
)
(MeSetDrawOrder ObjLst nil 'MoveToBottom)
)
)
(setq ObjLst '())
(if (setq CurSet (ssget "X" '((0 . "IMAGE"))))
(progn
(while (setq CurEnt (ssname CurSet 0))
(setq ObjLst (cons (vlax-ename->vla-object CurEnt) ObjLst))
(ssdel CurEnt CurSet)
)
(MeSetDrawOrder ObjLst nil 'MoveToBottom)
)
)
(princ)
)
;
; - Startup functions ---------------------------------------------------------
;
;(MeSendRasterAndImageToBottom)
;
; == Copyright - Note (May be never deleted) ==================================
;
; ©2005 MENZI ENGINEERING GmbH, Switzerland
; -----------------------------------------------------------------------------
;


And here's a little something to force all hatch that isn't already, to the back.

(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)
)

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
Message 6 of 13

Thanks Matt,
That works a dream!
I already had a lisp routine that moves all existing hatch to back, but this reactor thingy(!) does just what I want - puts hatch to back straight away when hatching.

Cheers guys, thanks for the help.
HOLLY

ps. I think you need to keep a closer eye on Grandma by the sounds of things!
Message 7 of 13
msarqui
in reply to: Anonymous

(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!

Message 8 of 13
Kent1Cooper
in reply to: msarqui


@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)
)

Kent Cooper, AIA
Message 9 of 13
msarqui
in reply to: Kent1Cooper

Thanks for the reply Kent.

 

It is not working. My AutoCAD stops...

 

 

Message 10 of 13
Kent1Cooper
in reply to: msarqui


@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?

Kent Cooper, AIA
Message 11 of 13
pbejse
in reply to: msarqui


@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)
  )

 

Message 12 of 13
msarqui
in reply to: pbejse

It works like a charm.

 

Thanks pbejse!

Message 13 of 13
pbejse
in reply to: msarqui


@msarqui wrote:

It works like a charm.

 

Thanks @pbejse!


Glad it works for you msarqui

 

Cheers

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost