Jump to content

Recommended Posts

Posted

I want to reset the value of a registry key whenever a user exits AutoCAD completely so I thought I'd redefine the QUIT command in my acaddoc.lsp to accomplish my goal as such:

 

(command ".undefine" "quit")

(defun c:quit ( )
   (setenv "CSC:START" "YES")
   (command ".quit")
   (princ)
)

 

 

This actually does the job I want but there is one side effect which occurs when AutoCAD starts with a blank drawing and then executes any command. During testing of this code, I would open and close AutoCAD repeatedly and as long as I don't pan, zoom or do anything that changes DBMOD to something other than 0, when I would exit AutoCAD it would do so just fine.

 

However one time I inadvertently zoomed in with my middle mouse button as I was moving it across the screen and when I went to exit, instead of seeing the normal alert from AutoCAD saying

acadexit2.JPG

 

the following was printed on the command line (with no alert):

 

acadexit1.JPG

 

I've been looking all morning and I can't find any reason why this is happening and though it isn't a huge deal, I would still like to know why adding the code above changes AutoCAD's notification upon exiting a modified unsaved drawing. Thanks.

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

  • lfe011969

    18

  • Lee Mac

    13

  • BlackBox

    7

  • ReMark

    3

Top Posters In This Topic

Posted Images

Posted

Stab in the dark but, try adding an initdia in the code before the quit.

Posted

Good idea Lee but it didn't work.

 

I just tried the "CLOSE" command instead of "QUIT" or "EXIT" and I get the normal save drawing alert so I'm sure it has something to do with the whole undefine process. Thanks.

Posted

You could use a reactor to set your registry setting if need be, perhaps vlr-editor-reactor

Posted

Awwww don't say reactors...lol

 

I was at my wits end trying to get a reactor to work when a new drawing was started when you turned me on to using the registry. Now you're sending me back down that path?? :cry:

 

Seriously I will (begrudgingly) take a look at it again tomorrow.

Posted
I was at my wits end trying to get a reactor to work when a new drawing was started when you turned me on to using the registry. Now you're sending me back down that path?? :cry:

 

It was the best I could think of... but yes, I do try to avoid them where possible :ouch:

Posted

An update to my original post...

 

Apparently this condition is not limited to unsaved drawings as the same behavior is exhibited on an existing drawing that has been modified when exiting AutoCAD. Instead of the nomal save drawing alert, I am only prompted at the command-line do I really want to discard my changes.

 

I'm writing my code for a reactor right now, wish me luck :unsure:

Posted

"I want to reset the value of a registry key whenever a user exits AutoCAD completely..."

 

If I may be so bold as to ask, which Registry key are you resetting and why? I'm just curious. Thanks.

Posted
If I may be so bold as to ask, which Registry key are you resetting and why? I'm just curious. Thanks.

 

If I'm correct, a custom registry key set using setenv to this location:

 

(strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\FixedProfile\\General")

Lee

Posted

Correct Lee.

 

ReMark, with Lee's encouragement here, I started working with custom registry settings to set a condition that a certain lisp would be activated only upon creating a new drawing via a specific lisp. Now I'm just trying to figure out different ways to use registry settings to accomplish different tasks. I'm kind of in an R&D mode right now :idea: and right now I was thinking of seeing what I could come up with to display an alert or a dialog the first time AutoCAD is started every day. I was thinking of something along the lines of having a tip of the day show up each time AutoCAD is started.

Posted
ReMark, with Lee's encouragement here, I started working with custom registry settings to set a condition that a certain lisp would be activated only upon creating a new drawing via a specific lisp. Now I'm just trying to figure out different ways to use registry settings to accomplish different tasks. I'm kind of in an R&D mode right now :idea: and right now I was thinking of seeing what I could come up with to display an alert or a dialog the first time AutoCAD is started every day. I was thinking of something along the lines of having a tip of the day show up each time AutoCAD is started.

 

Lonnie,

 

I would clarify that I wouldn't "encourage" setting registry keys - I would only use that option if it was the only feasible solution for the problem. You don't really want to bloat the registry unnecessarily.

 

With regard to your "Tip of the Day", note that the ACAD.lsp, unlike the ACADDOC.lsp, will load everytime AutoCAD is started, but not everytime a new drawing is started - but I'm not sure whether it is a good idea to have dialogs popping up during loading of AutoCAD - I say 'not sure' because I have never gone down that road - I'll leave others to offer their opinion on that issue.

 

Should you want to only run the program once a day - then yes, a registry key may be necessary (or some other storage method such as a temporary file). Perhaps set the LISP to check the Julian Day, and store it in the registry (or elsewhere), then, should the day be the same as that stored in the registry, it won't run.

 

Also, you might like to take a look at this :)

 

Lee

Posted
note that the ACAD.lsp, unlike the ACADDOC.lsp, will load everytime AutoCAD is started, but not everytime a new drawing is started

 

I did not know that so thanks for the tip.

 

Also, you might like to take a look at this :)

 

Lee

 

Another great piece of code Lee. From now on instead of asking if you have written code for a specific situation, I will just assume you have and say "Hey Lee, give me your code for ______________________. Thanks!" :D

Posted

Lonnie,

 

With regard to my ideas for a program to run once a day, this is the structure I was pertaining to:

 

(defun IWillOnlyRunOnceADay nil

 (alert "This is all you'll hear from me today")
 (princ)
)


(if
 (not
   (and
     (setq date (getenv "LMAC_OnceADay"))
     (= (fix (getvar 'DATE)) (atoi date))
   )
 )
 (progn
   (IWillOnlyRunOnceADay)
   (setenv "LMAC_OnceADay" (itoa (fix (getvar 'DATE))))
 )
)
(princ)

 

It would sit in the ACADDOC.lsp

 

Lee

Posted
another great piece of code lee. From now on instead of asking if you have written code for a specific situation, i will just assume you have and say "hey lee, give me your code for ______________________. Thanks!" :D

 

:)

 

0000000000

Posted
Lonnie,

 

With regard to my ideas for a program to run once a day, this is the structure I was pertaining to:

 

(defun IWillOnlyRunOnceADay nil

(alert "This is all you'll hear from me today")
(princ)
)


(if
(not
(and
(setq date (getenv "LMAC_OnceADay"))
(= (fix (getvar 'DATE)) (atoi date))
)
)
(progn
(IWillOnlyRunOnceADay)
(setenv "LMAC_OnceADay" (itoa (fix (getvar 'DATE))))
)
)
(princ)

 

It would sit in the ACADDOC.lsp

 

Lee

 

Thanks for the code! I will have to add this to my toolbox as well. While it took you all of 2 minutes to come up with this code below is the reactor code I came up with to handle the same thing and it only took me a couple of hours, lol:

 

 

(vlr-command-reactor nil '((:vlr-commandWillStart . DoOnExit)))

(defun DoOnExit ( Caller CmdSet )
 (if (member (car CmdSet) '("END" "EXIT" "QUIT"))
   (setenv "CSC:OnceADay" "YES")
 )
)

 

 

The only thing I'm not sure about is clearing the reactor. The other reactors I was working with were contained in their own lisp and was called like you would call any lisp. However since this is in my ACADDOC.lsp I had to strip out the command reactor from it's defun statement and then since I'm not assigning a variable to the reactor I don't know how to clear it (or if it even matters in this case). I mean typically you would clear the reactor as such:

 

 

(defun clear_myExitReact ()
 (if (and (myExitReact (vlr-added-p myExitReact))
   (vlr-remove myExitReact)
 )
)

 

 

I also tried the vlr-commandEnded reactor but couldn't get this to work. Since I'm using the vlr-commandWillStart reactor the registry gets changed as soon as the command is invoked so if the user cancels AutoCAD from exiting then opens a new drawing, the tip of the day gets displayed again.

Posted

Once the novelty of the "Tip of the Day" wears off will there be any provision for killing it? I ask based on experience with another program I used to run that had a similar feature. After a while it got to be a major PITA. It was bad enough sitting through multiple splash screens when loading the program in the first place but then to have to view the tip too literally put me over the edge. No offense meant but you do have to look at this from the users point of view.

Posted
Once the novelty of the "Tip of the Day" wears off will there be any provision for killing it? I ask based on experience with another program I used to run that had a similar feature. After a while it got to be a major PITA. It was bad enough sitting through multiple splash screens when loading the program in the first place but then to have to view the tip too literally put me over the edge. No offense meant but you do have to look at this from the users point of view.

 

You bring up a good argument and since you've actually seen the real world results of such an effort I will definitely heed your advice and either figure out a way to disable it permanently or perhaps for a predetermined length of time. That is of course if I actually implement this into our office. Right now I am trying to learn different concepts and was intrigued by doing something like this. I may use this concept to alert users of new developments or new enhancements to our AutoCAD suite. Thanks for the suggestion!

Posted

Rather than disable for a predetermined length of time could a timing element be included in the code that would display the alert/announcment at a predetermined day/time of the week (ex. - 9 a.m. Monday morning)?

Posted

I would think so. Maybe if we set a variable to the date of the first Monday of the year then set the tip to display if (getvar "CDATE") equals the Monday variable plus a mulitple of 7. Now I'm really intrigued so I will have to mete out some code (if Lee doesn't beat me to it, lol).

Posted
I would think so. Maybe if we set a variable to the date of the first Monday of the year then set the tip to display if (getvar "CDATE") equals the Monday variable plus a mulitple of 7. Now I'm really intrigued so I will have to mete out some code (if Lee doesn't beat me to it, lol).

 

I'm an idiot :oops:

 

The CDATE variable returns the date as YYYYMMDD.SSSSSS.... so adding a multiple of 7 to some arbitrary date won't work. I guess we could store the date of every Monday in a list then compare the value of CDATE with the list then have the tip code activated if CDATE is a member of the list as such (kind of ugly code):

 

(setq mondays (list "20110103" "20110110" "20110117" ..... "20111226"))
(setq today_date (rtos (getvar "CDATE") 2 0))
(if (member today_date mondays)
 (doOncePerWeek)
)

 

Untested and you would have to reset the list every year. I'm sure there's a better way.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...