Author Topic: How can you run a Lisp routine in a Script file?  (Read 17670 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
How can you run a Lisp routine in a Script file?
« 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.

New Shooz

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #1 on: September 26, 2008, 03:53:44 PM »
is this of any use - X-Batch

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: How can you run a Lisp routine in a Script file?
« Reply #2 on: September 26, 2008, 03:58:46 PM »
Or >>this<<?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

AVCAD

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #3 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?

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: How can you run a Lisp routine in a Script file?
« Reply #4 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.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

New Shooz

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #5 on: September 26, 2008, 04:08:48 PM »
you mean something like:
Code: [Select]
(load "lispfilename" "\nlispfilename.lsp file not loaded.")

AVCAD

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #6 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.

deegeecees

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #7 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.

AVCAD

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #8 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?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: How can you run a Lisp routine in a Script file?
« Reply #9 on: September 26, 2008, 04:48:05 PM »
That should have ran the script on all the drawings in the directory you selected?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

deegeecees

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #10 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.

deegeecees

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #11 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))

AVCAD

  • Guest
Re: How can you run a Lisp routine in a Script file?
« Reply #12 on: September 26, 2008, 05:18:14 PM »
ya i did that too, it runs on 1 drawings and then stops

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How can you run a Lisp routine in a Script file?
« Reply #13 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.
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How can you run a Lisp routine in a Script file?
« Reply #14 on: September 26, 2008, 11:18:53 PM »
could you add something like:
Code: [Select]
(while (= (getvar "cmdactive") 0)
  (command "resume")
);while
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox