Author Topic: Successful If statement prompt  (Read 7297 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........