TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: AVCAD on September 26, 2008, 03:50:15 PM

Title: How can you run a Lisp routine in a Script file?
Post by: AVCAD on September 26, 2008, 03:50:15 PM
I have a 600 drawings I need to do a bunch of stuff too. I have a button that loads a simple lisp routine that I usually use but 600 drawings....each on at a time...I don't have time to do that. IS there any way I can load the lisp's in a SCRIPT files and then batch it using scriptpro?

here is what I did, I thought it would work but obviously it isnt.

Code: [Select]
;Sets Undo Control to Off
Undo control none
;
;
;Sets Viewres 10000
viewres
y
10000
;
;
fieldeval
31
;
;
;
LAYEREVAL
0
;
;
;
LAYERNOTIFY
0
;
;
;
visretain
1
;
;Enter new value for INSUNITS (0=unitless, 1=inches, 4=millimeter)
insunits
4
;
;
;
;
;Enter new value for INSUNITS (0=unitless, 1=inches, 4=millimeter)
insunitsdefsource
4
;
;
;
;
;Enter new value for INSUNITS (0=unitless, 1=inches, 4=millimeter)
insunitsdeftarget
4
;
;
(COMMAND "IMAGEFRAME" "0")
;
;
;
;
(load "C:/xxxx/lisp/XLAYER.LSP")
(XLAYER)
(load "C:/xxxx/lisp/clean.vlx")
(clean)
(load "C:/xxxx/lisp/PURGNEST.LSP")
(PURGNEST)
(load "C:/xxxx/lisp/xclean.lsp")
(xclean)
;
(COMMAND "DVIEW" "" "TWIST" "0" "")
(COMMAND "SNAPANG" "0")
(COMMAND "ZOOM" "E")
(COMMAND "LTSCALE" "1000")
;
;
;
;
;Sets Undo Control to On
Undo All
;
;
;
;
;Quick Saves
._qsave

Thanks in advance.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: New Shooz on September 26, 2008, 03:53:44 PM
is this of any use - X-Batch (http://www.theswamp.org/index.php?topic=25128)
Title: Re: How can you run a Lisp routine in a Script file?
Post by: Matt__W on September 26, 2008, 03:58:46 PM
Or >>this (http://www.theswamp.org/index.php?topic=21412.msg259520#msg259520)<<?
Title: Re: How can you run a Lisp routine in a Script file?
Post by: AVCAD on September 26, 2008, 04:04:17 PM
no sorry neither are those are what I am looking for.

All I need to do is load and run my LSP files from a SCR file.

Is that possible, and how?
Title: Re: How can you run a Lisp routine in a Script file?
Post by: Matt__W on September 26, 2008, 04:07:25 PM
You can do that with what I posted a link to.

The following will load a LSP called 'My-Layers'

Code: [Select]
(write-line (strcat "(load " (chr 34) "My-Layers" (chr 34) ")") scrfile)
It's the same as typing (load"my-layers") at the command line.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: New Shooz on September 26, 2008, 04:08:48 PM
you mean something like:
Code: [Select]
(load "lispfilename" "\nlispfilename.lsp file not loaded.")
Title: Re: How can you run a Lisp routine in a Script file?
Post by: AVCAD on September 26, 2008, 04:17:47 PM
I dont know. I cant anything you guys are posting to work. my SCR file just wont run the commands from my LISP file.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: deegeecees on September 26, 2008, 04:22:56 PM
Make a Lisp file with all those things you want to do, and then change the highlighted in red line to what you called your Lisp file, and run this from within a drawing.

Code: [Select]
;batch_anything.lsp
;Created XXXXXXXX
;Date:   Sept of 2002
;Description:   Batch Process
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start prog

(DEFUN C:batch_anything ()

;;;;;;;;;;;;;;;;;;;;;;;;;Select directory to be processed

   (setq dfil (getfiled "Select A File In The Directory You Want To Batch Process" "p:/" "dwg" 0))
   (setq wutdir (vl-filename-directory dfil))
   (setq wutfiles (vl-directory-files wutdir "*.dwg"))

   (setq scrfile (open "c:\\scrfile.scr" "w"))
   (close scrfile)
   (setq scrfile (open "c:\\scrfile.scr" "a"))

(foreach n wutfiles
   (setq n2 (strcat "\""wutdir "\\" n "\""))
   (setq n2 (vl-string-translate "\\" "\\" n2))
   (setq scrline (strcat "open" " " n2 " " "(load\"[color=red]YOURLISP[/color]\")" " " "[color=red]YOURLISP[/color]" " " "qsave" " " "close"));;;;;;;COMMANDS FOR BATCH GO HERE
   (write-line scrline scrfile)
   (princ)
)

   (close scrfile)
(command "script" "c:\\scrfile")

(princ "\n***Batch complete.***")
(princ)


);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEFUN


This basically goes the opposite direction you are trying to go. It creates, and runs a script from a Lsip, instead of running a Lisp from a Script. That's why I created it, to do just what you are talking about, batch process a whole crapload of dwg's.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: AVCAD on September 26, 2008, 04:35:57 PM
I did what you said and it runs the LISP files now but how do I get it to run on multiple drawings?
Title: Re: How can you run a Lisp routine in a Script file?
Post by: ronjonp on September 26, 2008, 04:48:05 PM
That should have ran the script on all the drawings in the directory you selected?
Title: Re: How can you run a Lisp routine in a Script file?
Post by: deegeecees on September 26, 2008, 04:49:50 PM
I did what you said and it runs the LISP files now but how do I get it to run on multiple drawings?

Load the batch_anything lisp and run it, then select a folder that contains the drawings to be processed.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: deegeecees on September 26, 2008, 04:51:02 PM
Oh, and change the drive letter too:

(setq dfil (getfiled "Select A File In The Directory You Want To Batch Process" "p:/" "dwg" 0))
Title: Re: How can you run a Lisp routine in a Script file?
Post by: AVCAD on September 26, 2008, 05:18:14 PM
ya i did that too, it runs on 1 drawings and then stops
Title: Re: How can you run a Lisp routine in a Script file?
Post by: CAB on September 26, 2008, 09:10:55 PM
An error will stop a script.

I forget but there is a way to resume from some errors.

But you need to manually step through the process and find the error.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: alanjt on September 26, 2008, 11:18:53 PM
could you add something like:
Code: [Select]
(while (= (getvar "cmdactive") 0)
  (command "resume")
);while
Title: Re: How can you run a Lisp routine in a Script file?
Post by: CAB on September 27, 2008, 07:12:57 AM
I found it.
http://www.theswamp.org/index.php?topic=10539.msg133920#msg133920
Title: Re: How can you run a Lisp routine in a Script file?
Post by: deegeecees on September 29, 2008, 12:14:00 PM
ya i did that too, it runs on 1 drawings and then stops

Not sure what the problem is. If you still need help, I'll try and test some things when I get a chance.
Title: Re: How can you run a Lisp routine in a Script file?
Post by: Andrea on September 30, 2008, 12:48:47 PM
or -> this (http://www.caddepot.com/cgi-bin/cfiles/cfiles.cgi?0,0,0,0,21,2537)
Title: Re: How can you run a Lisp routine in a Script file?
Post by: Rooster on November 14, 2008, 08:13:07 AM
I am making one of my first tentative forays into LISP writing. All I want to do at the moment is to create a LISP to run an existing script of mine.

Here's what it consists of at the moment:

(DEFUN C:LDS200-0 ()
(command "script" "K:\\\\_LDS JOB DATA\\RE_FILES\\DRAWING SCRIPTS\\0_LAYER PROPERTIES.scr")
)

The script is stored on a network drive (hence the additional \\'s). When I run this, I just get an error saying invalid file name. Obviously, I've checked that the path is correct and that everything is spelt right. If I copy the script onto my C drive and change the path in the LISP accordingly, it all works fine. So how can I get my LISP to browse to the script on the network drive??
Title: Re: How can you run a Lisp routine in a Script file?
Post by: CAB on November 14, 2008, 08:54:24 AM
I guess you'er sure about the double \\?

Have you tried this:
(command "script" "K://_LDS JOB DATA/RE_FILES/DRAWING SCRIPTS/0_LAYER PROPERTIES.scr")
or this:
(command "script" "K:\\/_LDS JOB DATA\\RE_FILES\\DRAWING SCRIPTS\\0_LAYER PROPERTIES.scr")
Title: Re: How can you run a Lisp routine in a Script file?
Post by: Rooster on November 14, 2008, 08:58:28 AM
Thanks for the reply Alan, but both those lines result in the same error message as before (invalid file name)
Title: Re: How can you run a Lisp routine in a Script file?
Post by: CAB on November 14, 2008, 09:00:50 AM
BTW welcome to the Swamp.

Just for grins would you try these too.
(command "script" "K:/_LDS JOB DATA/RE_FILES/DRAWING SCRIPTS/0_LAYER PROPERTIES.scr")
or this:
(command "script" "K:\\_LDS JOB DATA\\RE_FILES\\DRAWING SCRIPTS\\0_LAYER PROPERTIES.scr")
Title: Re: How can you run a Lisp routine in a Script file?
Post by: Rooster on November 14, 2008, 09:16:06 AM
BTW welcome to the Swamp.

Thanks!

And thanks for the other two suggestions - they both worked! Now I have the quandary of which one to use!!
Title: Re: How can you run a Lisp routine in a Script file?
Post by: CAB on November 14, 2008, 09:40:28 AM
That's a good problem to have. 8-)