Author Topic: (code) run and/or load then run from custom menu files  (Read 1968 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(code) run and/or load then run from custom menu files
« on: April 01, 2004, 12:07:20 PM »
In an attempt to find another way to run/load run programs from an .mnl file, I came up with this. The following (defun r0l) is loaded in my custom menu file and called from my custom .mns file like so;
Code: [Select]

[Attach Note to Object]^C^C(r0l "c:atn" "AttachNote")

Code: [Select]

(defun r0l (at fn / ckf run)
  (defun ckf (fn)
    (cond ((findfile (strcat fn ".lsp")) T)
          ((findfile (strcat fn ".fas")) T)
          ((findfile (strcat fn ".vlx")) T)
          )
    )
  (setq run (atoms-family 0 (list at)))
  (cond ((= (car run) (read at)) (eval run))
        ((= (car run) nil)
         (cond ((= (ckf fn) T)(load fn)(r0l at fn))
               ((= (ckf fn) nil) (princ "\n error on load -> File not Found"))
               )
         )
        )
  )
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (code) run and/or load then run from custom menu files
« Reply #1 on: March 17, 2010, 08:51:06 AM »
Thanks Mark, never though I would need this but you never know do you. 8-)
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.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: (code) run and/or load then run from custom menu files
« Reply #2 on: March 17, 2010, 09:06:27 AM »
Nice Mark  :-)

Just a petty perfectionistic comment from me, you don't need the explicit 'T's in your code - as anything non-nil is T, so just for elegance;

Code: [Select]
(defun r0l (at fn / ckf run)
 
  (defun ckf (fn)
    (cond ((findfile (strcat fn ".lsp")))
          ((findfile (strcat fn ".fas")))
          ((findfile (strcat fn ".vlx")))))
 
  (setq run (atoms-family 0 (list at)))
  (cond ((= (car run) (read at)) (eval run))
        ((cond ((ckf fn) (load fn) (r0l at fn))
               ((princ "\n error on load -> File not Found"))))))

Excuse my dodgy end-of-line formatting...   :angel:

Aerdvark

  • Guest
Re: (code) run and/or load then run from custom menu files
« Reply #3 on: March 17, 2010, 10:10:48 AM »
I would like to understand the codes, please help me with that.

Code: [Select]
[Attach Note to Object]^C^C(r0l "c:atn" "AttachNote")This part: (r0l "c:atn" "AttachNote") is what I do not understand...
After the 2 escapes, the command "r0l" is given which fires up the routine as given.
Am I correct to say that the whole command is "r0l" with given variables (global) "c:atn" and "AttachNote" ??
Here I am a bit confused., because c:atn looks like a command to me.
I must say that creating routines with this start I am familiar with:
Code: [Select]
(defun c:test ( / local variables)
(....
); end defun

When using this:
Code: [Select]
(defun ( ....); global variables??
); end of defun

I understand that there are variables preovided with the command..?
As you can see I am a bit confused. I thought (defun ... ( / ) was all about global or local variables (I mean before or after the "/")
Have read about it but I can't understand it.
Sometinmes this is due to the translation english -> dutch...

WHen having this explained, I hope I can understand the second part too, the lisp routine/
I would be thankful if you'd share some explaining ont that too.

As always, thanks in advance!

ps: am I the only one having trouble posting on this forum? The textbox where I type my text keeps scrooling upwards so I can't see what I am writing.
This edit box however works good.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: (code) run and/or load then run from custom menu files
« Reply #4 on: March 17, 2010, 10:20:22 AM »
Marco,

If you read the help file on the defun function you will notice that all symbols that appear before the "/" character are taken as arguments for the function.

Notice that the subfunction is also recursive (meaning that it calls itself from within itself) - the recursive call must also supply the necessary arguments.

The "c:atn" is a string, and is checked using the atoms-family function to determine whether it is defined, if it is, it is evaluated, else an attempt is made to load the LISP/FAS/VLX file and the function is recursively called to test the symbol after the load.

Hopefully others can embellish on this.

Lee
« Last Edit: March 17, 2010, 10:28:16 AM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (code) run and/or load then run from custom menu files
« Reply #5 on: March 17, 2010, 01:46:54 PM »

This part: (r0l "c:atn" "AttachNote") is what I do not understand...

Code: [Select]
(defun c:test ( / local variables)
(....
); end defun

When using this:
Code: [Select]
(defun ( ....); global variables??
); end of defun

ps: am I the only one having trouble posting on this forum? The textbox where I type my text keeps scrooling upwards so I can't see what I am writing.
This edit box however works good.

As Lee said the (r0l "string1" "string2") is a call to a lisp using 2 arguments.
The 2 arguments are strings in this case.

(defun r0l (at fn / ckf run) is looking for argument 1 & stores it in variable name at AND
argument 2 which it stores it in variable name fn. They are both string type variables.
 ckf & run are indeed local variables. Any variable not declared is a global variable.


No problem with posting for me.
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.