TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MSTG007 on July 14, 2016, 09:30:22 AM

Title: Run a lisp without "C:Command"?
Post by: MSTG007 on July 14, 2016, 09:30:22 AM
Is there a way I can run a lisp without needing to type in a command to execute it? More like, drag and drop in AutoCAD and it runs?

Code: [Select]
(defun C:TEST ()
 (if (findfile "C:/path/yourscript.scr")
 (command "_script" "C:/path/yourscript.scr")
 ); end if
 ); end function

Thanks for the input.
Title: Re: Run a lisp without "C:Command"?
Post by: gile on July 14, 2016, 09:40:14 AM
Hi,

If you save the following code as runscript.lsp and you drag and drop this file from the explorer into the AutoCAD window the expression will evaluate.

Code - Auto/Visual Lisp: [Select]
  1. (if (findfile "C:/path/yourscript.scr")
  2.   (command "_script" "C:/path/yourscript.scr")
  3. )
Title: Re: Run a lisp without "C:Command"?
Post by: MSTG007 on July 14, 2016, 09:42:52 AM
Just that simple? No need to for a defun:? Sweet.
Title: Re: Run a lisp without "C:Command"?
Post by: MSTG007 on July 14, 2016, 09:58:29 AM
Just wanted to share alittle more on this. If you take this LSP and email it to a co-worker or so; drag the lisp from the email to a desktop, then to the AutoCAD window. It will automatically run.
Title: Re: Run a lisp without "C:Command"?
Post by: squirreldip on July 15, 2016, 11:47:20 PM
You can also copy all the text (^C) then paste (^V) in the command line.

I do this all the time when testing code snippets.
Title: Re: Run a lisp without "C:Command"?
Post by: mailmaverick on July 19, 2016, 08:35:55 AM
Instead of dragging and dropping the LISP file which in turn calls the script file, it is simplest to drag and drop the Script File directly.

Drag and Drop of script file runs it directly.

Title: Re: Run a lisp without "C:Command"?
Post by: MSTG007 on July 19, 2016, 08:45:06 AM
You are correct. Do you know of a way to email a script file? I have tried and it gets blocked once sent...
Title: Re: Run a lisp without "C:Command"?
Post by: ronjonp on July 19, 2016, 08:59:54 AM
You are correct. Do you know of a way to email a script file? I have tried and it gets blocked once sent...
Change the extension. (myscript.notscr)
Title: Re: Run a lisp without "C:Command"?
Post by: MSTG007 on July 19, 2016, 09:12:07 AM
I could email someone a script file with a (script-name.notscr) extension. Then request that they drag the file to their desktop, rename the extension to (script-name.scr). Finally, drag into AutoCAD and be done. Is that to many steps for a user? (Just doing the email thing).
Title: Re: Run a lisp without "C:Command"?
Post by: dgorsman on July 19, 2016, 10:08:58 AM
Consider what they are using AutoCAD for - unless they are a literal "CAD monkey" they should be capable of doing simple things like that.
Title: Re: Run a lisp without "C:Command"?
Post by: squirreldip on July 19, 2016, 12:44:18 PM
For attachments in emails I will often use 7-Zip and create .7z which most email servers will pass.  Other than that I +1 to the renaming the extension.
Title: Re: Run a lisp without "C:Command"?
Post by: ChrisCarlson on July 19, 2016, 01:29:43 PM
Will they ever run this routine again? If yes, deploy a network wide CUIx file with the routine auto-loading.
Title: Re: Run a lisp without "C:Command"?
Post by: MSTG007 on July 19, 2016, 01:36:33 PM
I also agree with the Network thing, but there might be times that they do not have any network access.
Title: Re: Run a lisp without "C:Command"?
Post by: Andrea on July 19, 2016, 02:22:36 PM
you can also create a new shortcut with /b switch parameter allowing to execute script file.

see:
http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-8E54B6EC-5B52-4F62-B7FC-0D4E1EDF093A
for more detail
Title: Re: Run a lisp without "C:Command"?
Post by: trogg on July 19, 2016, 11:26:43 PM
Is there a way I can run a lisp without needing to type in a command to execute it? More like, drag and drop in AutoCAD and it runs?

As a CAD Admin, I have needed this approach as well. Here is what I do:
You simply need to only add the defined command after the closing parenthesis as shown below.
Make sure that the command is enclosed in its own parentheses)

~Greg

Edit: Make sure that the 'C:' is included as the prefix to the defun.
Thanks Kdub
Title: Re: Run a lisp without "C:Command"?
Post by: kdub_nz on July 20, 2016, 12:03:12 AM

Hi Trogg

The final line would need to be  (C:CPR), surely ?
Title: Re: Run a lisp without "C:Command"?
Post by: trogg on July 20, 2016, 03:04:24 PM

Hi Trogg

The final line would need to be  (C:CPR), surely ?

I'm sorry, I should have made that more clear.

Don't remove the defined command at the top of the lisp. Leave that alone.
The only thing that I change in the routine is adding the command wrapped in parentheses at the end of the routine.

Updated in 2023...
I totally missed kerry's point with my response. Yes. The C: is included before the command as Kerry pointed out.
I have updated the image to be correct (after all these years...)

~Greg
Title: Re: Run a lisp without "C:Command"?
Post by: ahsattarian on March 10, 2023, 09:29:54 AM
Hi,

If you save the following code as runscript.lsp and you drag and drop this file from the explorer into the AutoCAD window the expression will evaluate.

Code - Auto/Visual Lisp: [Select]
  1. (if (findfile "C:/path/yourscript.scr")
  2.   (command "_script" "C:/path/yourscript.scr")
  3. )

I've Checked other file names and can say that every file name acts the same as     runscript   .

Every lisp file acts when drag and droped in AutoCAD.