Author Topic: Successful If statement prompt  (Read 7298 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« on: March 18, 2005, 11:12:43 AM »
Code: [Select]
(if (findfile "C:/Program Files/AutoCAD Tools/acad.lsp")
(load "C:/Program Files/AutoCAD Tools/acad.lsp")
(princ "\n   <<Couldn't Load Any Lisp Routines or Set Variables>>")
)
(princ)


This is what I am using in my mnl file to load my lisp routines. The prompt works great if nothing is found....but how do I get it to prompt when it does load successfully?

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Successful If statement prompt
« Reply #1 on: March 18, 2005, 11:18:13 AM »
"Progn"
Code: [Select]

(if (eq a 1)
  (progn
    (alert "A is 1!")
    (setq a 0)
    )
  (alert "A isnt set")
  )


EDIT:
(sorry forgot the Code tags.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
Successful If statement prompt
« Reply #2 on: March 18, 2005, 11:20:08 AM »
Try either of these:
Code: [Select]
(if (findfile "C:/Program Files/AutoCAD Tools/acad.lsp")
(load "C:/Program Files/AutoCAD Tools/acad.lsp")
(princ "\n   <<Couldn't Load Any Lisp Routines or Set Variables>>")
)

Code: [Select]
(if (findfile "C:/Program Files/AutoCAD Tools/acad.lsp")
(load "C:/Program Files/AutoCAD Tools/acad.lsp" (princ "\n   <<Couldn't Load Any Lisp Routines or Set Variables>>"))
)


Check the help on load for that last one. I didn't try either of these though.

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #3 on: March 18, 2005, 11:25:55 AM »
Thanks Daron :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Successful If statement prompt
« Reply #4 on: March 18, 2005, 11:31:39 AM »
WHAT?!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #5 on: March 18, 2005, 11:37:19 AM »
Quote
WHAT?!


 :?:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

daron

  • Guest
Successful If statement prompt
« Reply #6 on: March 18, 2005, 11:38:52 AM »
Se7en, the only thing he had wrong was the ending princ, which exits quietly. It would've worked otherwise.

You're welcome.

sinc

  • Guest
Re: Successful If statement prompt
« Reply #7 on: March 18, 2005, 12:54:48 PM »
Quote from: ronjonp
Code: [Select]
(if (findfile "C:/Program Files/AutoCAD Tools/acad.lsp")
(load "C:/Program Files/AutoCAD Tools/acad.lsp")
(princ "\n   <<Couldn't Load Any Lisp Routines or Set Variables>>")
)
(princ)


This is what I am using in my mnl file to load my lisp routines. The prompt works great if nothing is found....but how do I get it to prompt when it does load successfully?


BTW, you really shouldn't explicitly load the acad.lsp file.  Autocad does it automatically.  You aren't hurting anything (I wouldn't think), but you shouldn't really be doing it.

Also, commands you want loaded into every drawing you open should really be loaded in your acaddoc.lsp file, not your acad.lsp file.

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #8 on: March 18, 2005, 01:59:40 PM »
Sorry Se7en....you were the one that helped me with this problem. I just read too fast and the last thing I saw was Daron.

Thanks for your help.:D

Hey Sinc...I force this load in my mnl because I have a program tries to kill all external startups??

Read here:

http://www.theswamp.org/phpBB2/viewtopic.php?p=47292#47292



Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

sinc

  • Guest
Successful If statement prompt
« Reply #9 on: March 18, 2005, 10:58:03 PM »
Quote from: ronjonp
Hey Sinc...I force this load in my mnl because I have a program tries to kill all external startups??

Read here:

http://www.theswamp.org/phpBB2/viewtopic.php?p=47292#47292


What do you mean by "startup suite"?  Do you mean something like this?

Code: [Select]
(defun-q MYSTARTUP ( )
  (load "MyRoutine")
  [i]...and so forth...[/i]
)
(setq S::STARTUP (append S::STARTUP MYSTARTUP))


It's possible that your addon is improperly defining something like this:

Code: [Select]
(defun-q S::STARTUP ( )
   ...custom startup code...
)


If so, you can always just create a "MyStartupSuite.lsp" file and call that from your .mnl file.  Explicitly running your acad.lsp file is technically not right, but it would fall into the category of "hack fix for a bug".  So if you want to keep it that way, that should probably be OK, just nonstandard.  Like I said, I don't think you're hurting anything having it in your acad.lsp file, it's just being run twice (once automatically when you start Autocad, and again when Autocad loads your menus).  You might not even notice that fact, though.

If this is what's going on, what exactly do you have in your "startup suite"?

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #10 on: March 19, 2005, 12:51:44 PM »
Sinc,

I don't have anything in my startup suite anymore. My menu.mnl loads everything. I don't think that it is running twice at startup since I have prompts to tell me that all loaded ok.

Code: [Select]
  <<VBA Layer Creator Loaded>>
   <<Grotes VBA Routines Loaded>>
   <<AutoCAD Tools Acad.lsp Found>>
   <<AutoCAD Tools Lisp Routines Loaded>>
   <<AutoCAD Tools Variables Set>>
  Layer Filters Deleted.....
  No nul text strings found.
  No nul blocks found. vbastmt
Command:
Expression: thisdrawing.purgeall


Wouldn't this show up twice if it were being loaded twice?

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Successful If statement prompt
« Reply #11 on: March 21, 2005, 07:50:36 PM »
ron
This is a little late but the LOAD will return a value if it fails {see the onfailure option}
so you can combine it with the IF test like this
Code: [Select]
(if (and (findfile "C:/Program Files/AutoCAD Tools/acad.lsp")
         (load "C:/Program Files/AutoCAD Tools/acad.lsp" nil) ; return nil if failed
    )
  (princ "\n   <<  acad.lsp Loaded  >>")
  (princ "\n   <<Couldn't Load Any Lisp Routines or Set Variables>>")
)


This is just an example as I agree with sinc.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

sinc

  • Guest
Successful If statement prompt
« Reply #12 on: March 22, 2005, 12:32:45 PM »
Quote from: ronjonp


Wouldn't this show up twice if it were being loaded twice?



I suspect you have a whole series of issues.  You may want to post your acad.lsp file and let people take a look at it, and give you some feedback on how things "should" be setup.  I think you have a whole bunch of stuff in the acad.lsp file that shouldn't be there.

The acad.lsp file is loaded at Autocad startup - BEFORE any drawings are loaded.  You should not have any commands in it that require an open drawing.  Things loaded in this file are handled specially, and are not automatically loaded into documents namespaces.  Unless you really know what you're doing, you should probably avoid the acad.lsp file altogether.

The acaddoc.lsp file is a good place for loading custom commands.  This file is executed every time a drawing is opened, but it happens before drawing initialization is complete.  Therefore, you can put things like "load" commands in here, but you can't put some other things in here (like "undefine").

Stuff that requires a fully-initialized drawing to execute is what should go into the startup suite.  Essentially, this means everything that won't work if it's executed in the acaddoc.lsp file.  Your startup suite itself should be created in the acaddoc.lsp file.

The menu.lsp file is for lisp specifically related to your custom menus.  It isn't really the appropriate place to be loading custom commands.  That should be done in acaddoc.lsp.  If you were attempting to setup your startup suite via lisp called from this file, that may be where your startup suite was getting screwed up - I'm not sure (and don't have time right now to test), but I think the menu.lsp file might be run after drawing initialization is complete.  In other words, setting up your  startup suite in the menu.lsp file may be TOO LATE in the startup sequence...

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #13 on: March 22, 2005, 08:02:51 PM »
Quote
I suspect you have a whole series of issues. You may want to post your acad.lsp file and let people take a look at it, and give you some feedback on how things "should" be setup. I think you have a whole bunch of stuff in the acad.lsp file that shouldn't be there.


So I did a test:

Took out the explicit acad.lsp load in the mnl...didn't load.
Named my acad.lsp to acaddoc.lsp......didn't load.

The sup path where my personal acad(doc).lsp resides is in the profile so it should find it right?.

Nothing in startup suite.....(trying to avoid it)

This is in my personal acad.lsp:

Code: [Select]
;======================================================
;BEGINNING OF LISP LOADER
;======================================================

(AUTOLOAD "a2c" '("a2c"))
(AUTOLOAD "abl" '("abl"))
(AUTOLOAD "acret" '("acret"))
(AUTOLOAD "add" '("add"))
(AUTOLOAD "af" '("af")).........

(Setvar 'backgroundplot 2)
(Setvar 'draworderctl 2)
(Setvar 'fieldeval 31)
(Setvar 'hpgaptol 1).........


Everything is working great this way.... I'm having trouble understanding what determines the "correct" way to load all my lisp routines and set the variables :?: What is wrong with pointing to a file to load when my menu loads whether it be named acad.lsp,acaddoc.lsp,acadron.lsp...?


Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Successful If statement prompt
« Reply #14 on: March 22, 2005, 08:28:19 PM »
Ron, as another quick test could you post the results of the following 2 lines?
Code: [Select]

(findfile "acad.lsp")
(findfile "acaddoc.lsp")

Just a hunch, but I think that you have multiple .lsp's........

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Successful If statement prompt
« Reply #15 on: March 22, 2005, 08:59:58 PM »
Quote from: sinc

The acad.lsp file is loaded at Autocad startup - BEFORE any drawings are loaded.  You should not have any commands in it that require an open drawing.  Things loaded in this file are handled specially, and are not automatically loaded into documents namespaces.  Unless you really know what you're doing, you should probably avoid the acad.lsp file altogether.

The acaddoc.lsp file is a good place for loading custom commands.  This file is executed every time a drawing is opened, but it happens before drawing initialization is complete.  Therefore, you can put things like "load" commands in here, but you can't put some other things in here (like "undefine").

sinc,
Although there is great advice here, I must advise ronjonp that it's not all exactly correct. The biggest thing is that acad.lsp does, in fact, affect the first opened drawing (provided ACADLSPASDOC is set to 0) only, so any drawing specific variables will only be good for that first drawing. However, if you add a (command "undefine" "whatever"), that command will get undefined for the entire editing session, no matter which drawing you are in. I used to have my system setup this way, prior to the MDI. However, I still agree with you that this is NOT the place for most things to be placed. About the ONLY thing that should be in here, IMHO, is (vl-load-com).

Next, I place ALL of my setup type & customization stuff in my own .lsp file that I call from mymenu.mnl. I do it this way so that when I upgrade or even just reinstall I know what I need to add to the new install to be back up and running in a minimal amount of time. All I have to do is menuload mymenu once and it will be loaded from then on out......plus I don't need to worry about the acad.lsp or acaddoc.lsp files being overwritten or duplicated by others.

And as I said in my reply to ronjonp in that other thread, I used to have problems with the StartUpSuite. More often than not I would not have my custom routines loaded. That was the big driving force for me to place all of my startup apps in the mnl file.....voila', no more problems ;)

For the record, "mymenu" was used for reference only and does not represent any real, or percieved to be real, menu file(s).

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Successful If statement prompt
« Reply #16 on: March 22, 2005, 09:30:54 PM »
Jeff
I too have my own AlansAutoload.lsp, which is called from ACADDOC.lsp as it loads
in every DWG.
Is your lsp file is mymenu.mnl called automatically or do you have a button to force it?
Is the MNL file loaded with each DWG opened and therefore runs the lsp in each DWG.
I am in the process of moving to 2004 but the many lisp, menus & buttons are scattered
so i am trying to consolidate them into my menu system. It is working for the most part
but the ICONS for the buttons are a PITA. The ones I created & named were copied to a new
name by ACAD2000 & I don't feel like changing them all back. I ended up just copying all
icons from ACAD2000 to the MyDocuments directory. This doesn't sit right with me as it
clutters that directory. I think they should be in there own directory. I see some people
gather them up in a DLL file but I'm not sure of the over head for added & editing the
icons.
I would be interested in how you manage your system if you have the time & interest in sharing
your thought on the subject.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #17 on: March 22, 2005, 10:23:44 PM »
CAB,

Quote
Is the MNL file loaded with each DWG opened and therefore runs the lsp in each DWG.


From my experience yes.
Quote

I too have my own AlansAutoload.lsp, which is called from ACADDOC.lsp as it loads
in every DWG.


I used to do it this way but if a menu is constantly loaded loaded in a profile and the menu.mnl file will send commands....it seemed easy to just use the mnl file to load what I needed. From Jeff's explanation...I can see now that it is better to name the lisp file being called something different that acad(doc).lsp to ensure you aren't interfering with anything AutoCAD loads normally. I was under the impression that acad(doc).lsp didn't exist unless the user created them.

I have all my icons in a dll file and love it. Initially it took a little time to compile them all (about 80) with reshacker...but maintaining them is a breeze. You can call a batch from the command line (windows) to automate this task if you have many to do...but it took a little brain work (not too much though :)). To add an icon is as simple as creating it in acad, save it somewhere and add resource by browsing to the saved bmp.

Thanks for your input Jeff. I will test out your previous post tomorrow when I get back to work.



Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

sinc

  • Guest
Successful If statement prompt
« Reply #18 on: March 23, 2005, 12:48:20 PM »
Quote from: Jeff_M

sinc,
Although there is great advice here, I must advise ronjonp that it's not all exactly correct. The biggest thing is that acad.lsp does, in fact, affect the first opened drawing (provided ACADLSPASDOC is set to 0) only, so any drawing specific variables will only be good for that first drawing. However, if you add a (command "undefine" "whatever"), that command will get undefined for the entire editing session, no matter which drawing you are in.


D'Oh!  You're right of course.  I was mixing up application namespaces with what I was saying.  That's what I get for doing a fast-and-dirty post on my way to a meeting...

Quote from: Jeff_M

Next, I place ALL of my setup type & customization stuff in my own .lsp file that I call from mymenu.mnl. I do it this way so that when I upgrade or even just reinstall I know what I need to add to the new install to be back up and running in a minimal amount of time. All I have to do is menuload mymenu once and it will be loaded from then on out......plus I don't need to worry about the acad.lsp or acaddoc.lsp files being overwritten or duplicated by others.

And as I said in my reply to ronjonp in that other thread, I used to have problems with the StartUpSuite. More often than not I would not have my custom routines loaded. That was the big driving force for me to place all of my startup apps in the mnl file.....voila', no more problems ;)


I see no real problem with this approach.  The only thing to keep in mind is that your custom routines will only be loaded with your special menu.  If this is the way you want it, then that's fine.  But if there are other users on your system, they will not be able use the custom commands unless they load your menu.  Putting "load" commands in acaddoc.lsp makes them available to all users on the system (depending on user path settings and which directory you place it in, of course).

Some Land Desktop, Civil, and Surveying commands (or at least portions of them) are loaded in mnl files.  These features are not available if you create a user profile that does not load the appropriate menu.  Careful thought here can help you if you want to create "special profiles" that don't load so much stuff on startup, but instead are tailored to specific tasks.  This is "customization overkill" for most people (IMHO), but very useful for some.  Something to keep in mind.

The only big thing (going back to what ronjump was talking about) is that if you create a custom setup lisp file like that and explicitely load it from your mnl file, it should have it's own name, and should not be called "acad.lsp" or "acaddoc.lsp".  These filenames are reserved for special use by Autocad, and Autocad automatically looks for and loads them if found.

As to why your startup suite wasn't working when called from acaddoc.lsp, there could be a number of reasons...  Answer is it SHOULD work, unless you are doing something wrong/inappropriately.  This initialization takes place BEFORE drawing initialization is complete.  Therefore you CANNOT do things like "undefine" here.  You should also not create or delete entities here.  Things that require a fullly-initialized drawing should be put in the STARTUP function as specified in the documentation.

I don't really feel your argument about loading in the MNL as protection against "bad users" holds any water.  If some other user is going to get on your system and screw up the configuration because they don't know what they're doing, well, there isn't a whole lot you can do about that...  A sufficiently-tenacious "bad user" can screw up pretty much anything.  However, loading your custom Lisp in your MNL file because you like it that way and it seems to work best for you, well, that's a valid reason.

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #19 on: March 23, 2005, 01:30:10 PM »
Jeff,

Here is the results:

Code: [Select]
Command: (findfile "acaddoc.lsp")
"C:\\Documents and Settings\\rperez\\Application Data\\Autodesk\\AutoCAD
2005\\R16.1\\enu\\support\\acaddoc.lsp"

Command: (findfile "acad.lsp")
"C:\\PROGRA~1\\CADET2~1\\acad.lsp"


I do have multiple acad.lsp files DOH!

I definitely agree with the loading/running custom lisp from the *.mnl file...it has been the easiest way for me so far.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CADaver

  • Guest
Successful If statement prompt
« Reply #20 on: March 23, 2005, 02:11:26 PM »
Quote from: ronjonp
I definitely agree with the loading/running custom lisp from the *.mnl file...it has been the easiest way for me so far.
Ron


Gotta agree with that, for us.  I customize several MNL's, One for the base menu (usually ACAD.mnl) to which I add a call to load a specific autoloader lisp function.  Then another MNL with the client specific menu to load client specific function.  Another with discipline specific menu and functions, finally a personal menu with it's own mnl.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Successful If statement prompt
« Reply #21 on: March 23, 2005, 02:17:34 PM »
Quote from: sinc

The only big thing (going back to what ronjump was talking about) is that if you create a custom setup lisp file like that and explicitely load it from your mnl file, it should have it's own name, and should not be called "acad.lsp" or "acaddoc.lsp".  These filenames are reserved for special use by Autocad, and Autocad automatically looks for and loads them if found.

As to why your startup suite wasn't working when called from acaddoc.lsp, there could be a number of reasons...  Answer is it SHOULD work, unless you are doing something wrong/inappropriately.  This initialization takes place BEFORE drawing initialization is complete.  Therefore you CANNOT do things like "undefine" here.  You should also not create or delete entities here.  Things that require a fullly-initialized drawing should be put in the STARTUP function as specified in the documentation.

Granted, acad.lsp and acaddoc.lsp are loaded if found, but they are not reserved for use by Autocad. On the other hand, acadxxxx.lsp and acadxxxxdoc.lsp are reserved. The former are for User's use, as shown in this Load Order table found in the help file:
    You can understand the effects that one file may have on another if you know the order in which files are loaded when you start the software. For example, you have defined a function in an AutoLISP® routine that is loaded from the acad.lsp file, but the function does not work when you start AutoCAD®. This occurs because the function has been redefined by the acaddoc.lsp file, which is loaded after acad.lsp.

    Solution

    Following is a list of AutoCAD, Express Tools, and user-defined files in the order they are loaded when you first start the program.

    File                   For use by:
     
    acad2000.lsp     AutoCAD
     
    acad.rx             User
     
    acad.lsp             User
     
    acad2000doc.lsp  AutoCAD
     
    acetutil.fas        Express Tools
     
    acaddoc.lsp       User
     
    mymenu.mnc    User
     
    mymenu.mnl     User
     
    acad.mnc          AutoCAD
     
    acad.mnl           AutoCAD
     
    acetmain.mnc    Express Tools
     
    acetmain.mnl     Express Tools
     
    s::startup          User
     [/list:u]

    I didn't say I was calling a startup suite from acaddoc.lsp.....it was things placed into the Startup Suite in the Appload function that didn't always load. That was why I made my own "startup" lisp that autoloads with my mnl. Oh, and my actual personalized menu only contains my custom toolbars. This way I can alter the stock Acad toolbars and not worry about acad overwriting those mods.

    And again, you CAN use "undefine" in the acad.lsp & acaddoc.lsp. I did it for years prior to converting over to the menu.mnl (and tested it yesterday to see if it still behaved this way).

ronjonp

  • Needs a day job
  • Posts: 7529
Successful If statement prompt
« Reply #22 on: March 23, 2005, 06:20:41 PM »
Quote
Gotta agree with that, for us


Cadaver,

You feelin alright? You agreed with me...  :lol:  :lol:

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC