Author Topic: Load / Unload a lisp by routine  (Read 4483 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Load / Unload a lisp by routine
« on: August 29, 2006, 05:07:52 PM »
So I was search'n the database and found the 'Call a lisp from within a lisp', and I was a wonder'n if it could be taken one step further.
I am interested in calling a lisp from within a lisp, but I want to load a lisp that is not currently loaded.
So, you run lisp 'A', and it will call lisp 'B', and if it is not loaded, load it then run it.

I'm think'n this has been discussed before, but I haven't come across it yet.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #1 on: August 29, 2006, 05:14:46 PM »
something like
Code: [Select]
(IF (NOT (VL-SYMBOL-VALUE 'kg:build))
    (LOAD "KDUB_BaseLibrary" "Unable to LOAD 'KDUB_BaseLibrary.VLX' ")
    (PRINC)
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Load / Unload a lisp by routine
« Reply #2 on: August 29, 2006, 06:41:32 PM »
Yeah Kerry, someth'n like that.  Essept ... I don't wanna "Unable to LOAD ..."  :|  I wanna "able to LOAD ..."
And what is the 'kg:build ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #3 on: August 29, 2006, 07:06:51 PM »
'kg:build is a global variable representing the build date of the file, it is set when 'KDUB_BaseLibrary.VLX' is loaded.

I think you mis-understand the LOAD function.
The "Unable to LOAD 'KDUB_BaseLibrary.VLX' " string is the message to display IF the LOAD routine fails .. ie if the file can't be found or is spacoid.
The LOAD routine is evaluated only if the variable is not set, ie if the file in question is not loaded.

 You can also test for the existance of one of the functions in memory defined in your file using the same methodology.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Load / Unload a lisp by routine
« Reply #4 on: August 29, 2006, 08:42:20 PM »
Quote
'kg:build is a global variable representing the build date of the file, it is set when 'KDUB_BaseLibrary.VLX' is loaded.

I think you mis-understand the LOAD function.
The "Unable to LOAD 'KDUB_BaseLibrary.VLX' " string is the message to display IF the LOAD routine fails .. ie if the file can't be found or is spacoid.
The LOAD routine is evaluated only if the variable is not set, ie if the file in question is not loaded.

Aaaaa ...  makes sense.  Ok, then I need a 'VL-SYMBOL-VALUE' to search for my program, then, IF NOT found, to LOAD it.
How can I find out a VL-SYMBOL-VALUE like the kg:build ??  Where would I go to find that and what am I looking for (i.e.: date, serial #, etc) ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #5 on: August 29, 2006, 09:39:46 PM »
In the file in question I have something like this at the end ..
which is equivalent to SETQ'ing a variable as the file loads.
Code: [Select]
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(kdub:defineconstant 'KG:build "20060521")

(prompt (strcat "\nKDUB_BaseLibrary V1.25.60521 [Build:" KG:build "]"))
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
for completeness, this is my kdub:defineconstant routine ..
Code: [Select]
(defun KDUB:defineconstant (symbolname symbolvalue)
  (pragma '((unprotect-assign symbolname)))
  (set symbolname symbolvalue)
  (pragma '((protect-assign symbolname)))
  (princ)
);;;------------------------------------------------------------------
;;;------------------------------------------------------------------
« Last Edit: August 29, 2006, 09:51:14 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Tramber

  • Guest
Re: Load / Unload a lisp by routine
« Reply #6 on: August 30, 2006, 02:26:24 AM »
What does "pragma" mean ?

just curious

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #7 on: August 30, 2006, 04:06:36 AM »
Try this ..

http://groups.google.com/group/autodesk.autocad.customization/browse_thread/thread/2b84c3fa5862e7a0/43e03593a0577ac1?lnk=st&q=pragma+lisp&rnum=2&hl=en#43e03593a0577ac1


and, if memory serves, I think the use of pragma has been discussed a couple of times here.

added:
yep, just feed pragma to the site search engine ....
« Last Edit: August 30, 2006, 04:11:16 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Tramber

  • Guest
Re: Load / Unload a lisp by routine
« Reply #8 on: August 30, 2006, 05:10:40 AM »
and, if memory serves, I think the use of pragma has been discussed a couple of times here.

I know, but a very few times and with no explanation at all.

But you gave us a real good link and I finally understood.
That makes me think about a issue : I was wondering how we make our functions to turn blue, that is a way. But that's an other topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #9 on: August 30, 2006, 05:54:17 AM »
Bert,
The code I posted will make the SymbolName protected, and therefore display Blue in the IDE,
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Tramber

  • Guest
Re: Load / Unload a lisp by routine
« Reply #10 on: August 30, 2006, 05:59:42 AM »
Yes, sure, I wanted to say :
Well, here is a way, is there another one ?  :roll:

Another question : is the quantity of functions we would like to protect critical ? According to U.
« Last Edit: August 30, 2006, 06:01:24 AM by Call me Bert' »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #11 on: August 30, 2006, 06:06:30 AM »
.. and try something like this ..
Code: [Select]
(pragma '((unprotect-assign adderupper)))
;;
(DEFUN adderupper (var1 var2 /)
  (IF (AND NUMBERP var1)
    (AND NUMBERP var2)
  )
  (+ var1 var2)
)
;;
(pragma '((protect-assign adderupper)))

Piccy after loading the code :-)
« Last Edit: August 30, 2006, 06:07:49 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Load / Unload a lisp by routine
« Reply #12 on: August 30, 2006, 06:12:11 AM »
Ahhh words and meanings .. :-)
You probably know this Bert, but for others ..
protect in this case just means that the editor will warn you if an attempt is made to redefine the function .. nothing to do with security, despite the name ..

I Pragma protect ALL my library routine names and constant Global variable ... old habit I guess ... but not critical I believe.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Load / Unload a lisp by routine
« Reply #13 on: August 30, 2006, 08:49:13 AM »
About pragma ...



Cheers.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Load / Unload a lisp by routine
« Reply #14 on: October 09, 2006, 10:02:19 PM »
*hum* Interesting topic.

Why don't you create the lisp on the fly and set it equal to a var then you could just eval the var and or destroy it.

I wrote a routine for my previous company that would allow me to control the users enviroment based on their department (It would read a list of names every time autocad started up...). But the first time the program was run it rewrote itself and did some other fancy stuff. But i used on the fly lisps in quite a bit of that program. It was quite slick. The only way i could ensure that i got a consistent result was to build a master program that once deployed it would re-write itself based on that users group (So an Electrical guy would have a diff program then a Mech an so on.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org