Author Topic: During Loading and Closing a DWG  (Read 5470 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
During Loading and Closing a DWG
« on: October 04, 2013, 08:42:43 AM »
Does anyone know how to setup Autocad Once an individual drawing opens in Autocad it will perform a command. (I have a lisp that will Display Plot Styles which I would like to turn on). But when I close a drawing (It will run the command to turn off Display Plot Styles). hopefully that makes some sense.
Thanks for your thoughts!
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #1 on: October 04, 2013, 09:00:55 AM »
Without using reactors, I'd think it would be as simple as this:
Code: [Select]


(if (wcmatch (strcase (getenv "username")) "*")
  (progn (command "_.undefine" "_.close")
(defun c:close nil (yourfunctiontoresetplotstyles) (command "_.close"))
  )
)
« Last Edit: October 04, 2013, 09:23:40 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: During Loading and Closing a DWG
« Reply #2 on: October 04, 2013, 09:15:21 AM »
Ok. I am going to play dumb again. Curious; how does this work and where would i place this?
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #3 on: October 04, 2013, 09:21:57 AM »
I'd put it wherever you are loading your lisp routines from (acad.lsp *.mnl .. etc.).
As far as how it works, all it does is redefine the close command to run your routine before the "close" command.  ;D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: During Loading and Closing a DWG
« Reply #4 on: October 04, 2013, 09:45:56 AM »
lol you will like this; i usually appload it.
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #5 on: October 04, 2013, 09:48:28 AM »
Why don't you post the code you're using and we can get this sorted.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: During Loading and Closing a DWG
« Reply #6 on: October 04, 2013, 11:47:41 AM »
Please see the below code.

Code: [Select]
(defun DPS_Post ()
  (setvar "cmdecho" 0)
  (command "_.regenall")
  (setvar "cmdecho" 1)
  (princ)
)
;-------------------------------------------------------
(defun c:DPSON ()
  (rm:displayplotstyles t nil)
  (BGWhite)
  (DPS_Post)
)
;-------------------------------------------------------
(defun c:DPSONALL ()
  (rm:displayplotstyles t t)
  (BGWhite)
  (DPS_Post)
)
;-------------------------------------------------------
(defun c:DPSOFF ()
  (rm:displayplotstyles nil nil)
  (BGBlack)
  (DPS_Post)
)
;-------------------------------------------------------
(defun c:DPSOFFALL ()
  (rm:displayplotstyles nil t)
  (BGBlack)
  (DPS_Post)
)
;-------------------------------------------------------
;
;
(defun rm:displayplotstyles (bshow ball / acapp acdoc layouts layout bvshow)
(princ "\n...Display plotstyles ")
(vl-load-com)
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))

(setq layouts (vla-get-layouts acdoc))
(setq bvshow (if bshow :vlax-true :vlax-false))
(princ (if bshow "ON" "OFF"))
(cond
(ball
(vlax-for layout layouts
(if (/= (vla-get-name layout) "Model")
(vla-put-ShowPlotStyles layout bvshow))
)
(princ " in all layouts.\n")
)
(T (setq layout (vla-get-ActiveLayout acdoc))
(vla-put-ShowPlotStyles layout bvshow)
(princ " in current layout.\n")
)
)
(prin1)
)


; Set the background in model and paper space to white
(defun BGWhite ()
  (vl-load-com)
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (vla-put-GraphicsWinLayoutBackgrndColor disp 16777215)
)

; Set the background in model and paper space to black
(defun BGBlack  ()
  (vl-load-com)
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (vla-put-GraphicsWinLayoutBackgrndColor disp 0)
)
;---------------------------------------------- ---------
(princ (strcat "\n...DisplayPlotStyles is loaded || DPSON, DPSONALL, DPSOFF, DPSOFFALL...\n"))
(prin1)
;--------------------------------------------- ----------

Would like to have the Display plot Styles on at Start of Drawing. Then Do Not Show Display plot Styles when I exit a Drawing.
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #7 on: October 07, 2013, 09:53:54 AM »
Give this a try. I consolidated some of your previous code .. hope you don't mind :) .

Code: [Select]
(defun c:dpson () (rm:displayplotstyles t nil))
(defun c:dpsonall () (rm:displayplotstyles t t))
(defun c:dpsoff () (rm:displayplotstyles nil nil))
(defun c:dpsoffall () (rm:displayplotstyles nil t))


(defun rm:displayplotstyles (bshow ball / acdoc bvshow disp layout layouts)
  (princ "\n...Display plotstyles ")
  (vl-load-com)
  (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq layouts (vla-get-layouts acdoc))
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (setq   bvshow (if bshow
       :vlax-true
       :vlax-false
          )
  )
  (princ (if bshow
      (progn (or *editor-reactor-close*
            (setq *editor-reactor-close*
              (vlr-editor-reactor nil '((:vlr-beginclose . resetplotstyles)))
            )
        )
        (defun resetplotstyles (a b) (alert "foo") (rm:displayplotstyles nil t) (princ))
        (vla-put-graphicswinlayoutbackgrndcolor disp 16777215)
        "ON"
      )
      (progn (vla-put-graphicswinlayoutbackgrndcolor disp 0) "OFF")
    )
  )
  (if ball
    (progn (vlax-for layout layouts
        (if (/= (vla-get-name layout) "Model")
          (vla-put-showplotstyles layout bvshow)
        )
      )
      (princ " in all layouts.\n")
    )
    (progn (vla-put-showplotstyles (vla-get-activelayout acdoc) bvshow)
      (princ " in current layout.\n")
    )
  )
  (vla-regen acdoc acallviewports)
  (prin1)
)
(princ (strcat "\n...DisplayPlotStyles is loaded || DPSON, DPSONALL, DPSOFF, DPSOFFALL...\n"))
(prin1)
« Last Edit: October 07, 2013, 10:30:52 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: During Loading and Closing a DWG
« Reply #8 on: October 07, 2013, 10:08:49 AM »
I like what you did; its clean and makes sense. But my mind is not working properly for monday. :ugly:, I have Civil3D 2013 X64; where do i place this code? lol
Civil3D 2020

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: During Loading and Closing a DWG
« Reply #9 on: October 07, 2013, 10:10:11 AM »
Trying to run LISP while drawings are closing is tricky, especially if it takes some time (e.g. regeneration is called).  LISP doesn't stop the drawing from trying to close, but since there is something still happening AutoCAD throws an error.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #10 on: October 07, 2013, 10:12:35 AM »
I like what you did; its clean and makes sense. But my mind is not working properly for monday. :ugly: , I have Civil3D 2013 X64; where do i place this code? lol


Just load it how you were loading it before.
« Last Edit: October 07, 2013, 10:24:16 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: During Loading and Closing a DWG
« Reply #11 on: October 07, 2013, 10:20:40 AM »
lol you will like this; i usually appload it.

I have loaded it in my AppLoad.

I opened a drawing with the Plot Styles Display On.

I closed the drawing and saved it;

Reopened the drawing and Plot Styles Display On is still on.

Or If i trun it off manually it and reopen it; the drawing still has it turned off.

Again, i wonder if i am doing something wrong. Which I could be. (I am good at that).
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #12 on: October 07, 2013, 10:25:08 AM »
I'm getting mixed results with the reactor. IMO .. a simpler approach to reset the plotstyles would be to run (c:dpsoffall) on drawing startup.

Copy the code above again and give it a try. I just forced all the layouts to reset and it seems to be working.
« Last Edit: October 07, 2013, 10:28:11 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: During Loading and Closing a DWG
« Reply #13 on: October 07, 2013, 10:31:39 AM »
Which would mean? Sorry.
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7533
Re: During Loading and Closing a DWG
« Reply #14 on: October 07, 2013, 10:55:17 AM »
Which would mean? Sorry.


I'm not sure what you mean ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC