Author Topic: Send all hatch/images to background prior to printing  (Read 3646 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Send all hatch/images to background prior to printing
« on: December 07, 2012, 09:00:45 AM »
I'm looking for a reactor that would send all hatch/images to the background prior to printing and/or publishing from sheet set manager.
Anyone have anything they could share??  :)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Send all hatch/images to background prior to printing
« Reply #1 on: December 07, 2012, 11:48:22 AM »
Okay, so I've decided to go another route with this and send all hatch to the back just prior to saving.  I've been messing around with some reactor code and can't seem to figure out why it's not working.  Here's what I've got...

Code: [Select]
(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)

If I manually run the HATCH2BACK command, it works, but not when the command is issued in AutoCAD but I don't know where I'm going wrong with this.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Send all hatch/images to background prior to printing
« Reply #2 on: December 07, 2012, 12:23:00 PM »
You can't have command calls in reactors.

Perhaps this:

Code: [Select]
(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))
)
« Last Edit: December 07, 2012, 12:45:18 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Send all hatch/images to background prior to printing
« Reply #3 on: December 07, 2012, 01:06:40 PM »
Thanks!  I'll give it a go!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Send all hatch/images to background prior to printing
« Reply #4 on: December 07, 2012, 02:45:07 PM »
These functions may help - they should be compatible for use in Reactor callback functions.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Send all hatch/images to background prior to printing
« Reply #5 on: October 30, 2013, 03:14:09 PM »
So.... I'm revisiting this and have made some additions but it's not working.  I want to send all hatches to the background THEN send all images to the background so they will end up being behind the hatches.  I've copied some of the code and changed it to recognize raster images but it's not working.  It only sends the hatch to the back.  Where did I go wrong?  I get the following error message.

 error: bad argument type: VLA-OBJECT nil

Code: [Select]
(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) ) ))
)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Send all hatch/images to background prior to printing
« Reply #6 on: October 30, 2013, 04:23:01 PM »
Looks like this:
Code: [Select]
(and images (vlax-invoke sorttbl2 'movetobottom images))
should actually be

Code: [Select]
(and images (vlax-invoke sorttbl3 'movetobottom images))

hmspe

  • Bull Frog
  • Posts: 362
Re: Send all hatch/images to background prior to printing
« Reply #7 on: October 30, 2013, 07:03:44 PM »
I can't speak to anything related to the sheet set manager, but I wonder why a reactor would be needed for printing.  I have a routine to automatically updates the date on my engineering seal before printing.  The function is named 'c:update_seal' and is in the on_doc_load lisp file.  To call it I changed the command for the print button on the toolbar to '^C^Cupdate_seal;print'.  I intentionally left the drop-down menu entry for printing unchanged so that I have a readily available option that updates and one that does not.  For a function that ran for every plot I would probably redefine the print command to run 'c:update_seal' then call '._print'.  Seems far easier and less prone to issues than a reactor. 
"Science is the belief in the ignorance of experts." - Richard Feynman

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Send all hatch/images to background prior to printing
« Reply #8 on: October 30, 2013, 07:32:05 PM »
This might be a little more efficient Matt:
Code - Auto/Visual Lisp: [Select]
  1. (defun setdraworder ( / exd ls1 ls2 obn sor spc )
  2.               exd (vla-getextensiondictionary spc)
  3.               sor (cond ((catchapply 'vla-getobject (list exd "acad_sortents")))
  4.                         ((catchapply 'vla-addobject (list exd "acad_sortents" "acdbsortentstable")))
  5.                   )
  6.         )
  7.         (progn
  8.             (vlax-for obj spc
  9.                 (cond
  10.                     (   (= "AcDbHatch" (setq obn (vla-get-objectname obj)))
  11.                         (setq ls1 (cons obj ls1))
  12.                     )
  13.                     (   (= "AcDbRasterImage" obn)
  14.                         (setq ls2 (cons obj ls2))
  15.                     )
  16.                 )
  17.             )
  18.             (if ls1 (vlax-invoke sor 'movetobottom ls1))
  19.             (if ls2 (vlax-invoke sor 'movetobottom ls2))
  20.         )
  21.         (princ "\nUnable to retrieve Sortents Table.")
  22.     )
  23.     (princ)
  24. )
  25. (defun catchapply ( fun arg / rtn )
  26.     (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply fun arg)))) rtn)
  27. )
  28. (defun draworder:callback ( obj arg )
  29.     (if (wcmatch (strcase (car arg)) "SAVE,QSAVE,SAVEAS,PLOT")
  30.         (setdraworder)
  31.     )
  32.     (princ)
  33. )
  34. (if (null draworder:reactor)
  35.     (setq draworder:reactor (vlr-command-reactor nil '((:vlr-commandwillstart . draworder:callback))))
  36. )

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Send all hatch/images to background prior to printing
« Reply #9 on: October 31, 2013, 08:40:22 AM »
That works really well, Lee.  Thanks!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Send all hatch/images to background prior to printing
« Reply #10 on: October 31, 2013, 09:00:43 AM »
That works really well, Lee.  Thanks!

You're welcome Matt  8-)