Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running a lisp on multiple drawings

32 REPLIES 32
SOLVED
Reply
Message 1 of 33
roland.r71
7514 Views, 32 Replies

Running a lisp on multiple drawings

Hi there,

 

For all those who would like to run a lisp routine, or some script code, or just a single command, on a selection of drawings: This here is my gift to you. The MultiFileTool v3.1

 

MFT-Main.png

You will need DOSlib to get it to run (which you can find here on the forum, amongst other places)

 

With this LISP routine you can do pretty much anything, to a selection of files and you can select them in as many ways as you can think of. (& you can integrate (parts of) it into your own functions.)

 

MFT-Fileselector.png

 

Explaining all it can do and how it all works would be way to much for this post.

So, i'll just add the list of options here, to get an idea of what it can do (for you)

 

Options:
 - Load a LISP file with each drawing
 - Execute user supplied commands/script/macro or even lisp code
 - Extensive options for file selection
 - Sort list of filenames
 - Save/load lists
 - Autosave & load (remember) list
 - Allow/prevent duplicate filenames
 - Supports custom made import functions to get lists from anywhere you like
 - Uses realtime checking for fileopen function
	 - Checks if the file really exists
	 - Checks if the file doesn't require a higher acad version
	 - Checks if the current file needs to, and can, be saved
	 - Ignores new-unsaved drawings (closed without saving)
	 - Open (& Close) writable files
	 - Open (& Close) Read-Only files
	 - Open (& Close) Open (other user:network) files. (read-only)
	 - Option to warn user about missing files (dialog closes after 10 sec.)
	 - Option to warn user about Read-Only & Open(network) files (incl. retry)
	 - Option to automatically skip Read-Only & Open(network) files
	 - Option to log files which where not processed.
	 - Option to ignore changes (no saving)

 

 

I just spent the last weekend writing you a manual to go with it, So, for all your questions: RTFM!

(which of course means: Please read my RichTextFormat.Manual 😛 )

Note: most of the info inside the manual can be found as comments inside the LiSP file too.

 

If you would like to help or contribute, you're Always welcome to come up with idea's or improvements, revise the code, test it on your ACAD version,  or just proof-read my manual.

Any help would be much appreciated.

It has currently been tested on 2014, 2016, 2018 & 2019 (each 64bit)

 

edit:

🤣of course RTF is the one format you can't upload... so i just converted it to docx. 

32 REPLIES 32
Message 2 of 33
pbejse
in reply to: roland.r71


@roland.r71 wrote:

Hi there,

This here is my gift to you. The MultiFileTool v3.1

 

Early Christmas . Yipee!

 

MFT.png

 

Thank you @roland.r71 

 

Message 3 of 33
roland.r71
in reply to: pbejse

😀Actually its my birthday today and its tradition over here to hand out cake amongst colleagues 😉

Message 4 of 33
pbejse
in reply to: roland.r71


@roland.r71 wrote:

😀Actually its my birthday today and its tradition over here to hand out cake amongst colleagues 😉


Another day  YEAR older ( wiser ), a change of decoration is in order then

 

bday.png

 

You have earn the right to name those five who will celebrate with you on this wonderful day.

 

Cheers buddy :party_popper:

 

 

Message 5 of 33
hak_vz
in reply to: roland.r71

Happy birthday @roland.r71 and thank you for your present!

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 6 of 33
roland.r71
in reply to: hak_vz

@pbejse& @hak_vz : Thnx, guys 😊

Message 7 of 33

Hi! I'm really grateful for this lisp, it is a great tool for me when trying to run a lisp on thousands of dwgs at once.

I've met some issues however. When selecting lots of drawings from an entire folder and all subfolders, some files are not found by this lisp. Then the program halts with a pop up window stating File not found, and the program waits until I click OK/press enter for each command in my lisp. Even if I uncheck all "Warn if file..." boxes this occurs. I've tried to load only one of these files separately, and then it works perfectly. But I guess when the lisp is handling hundreds or more drawgings somehow it won't find some files.

 

So I was wondering if anyone have any ideas why the program fails to find some files when selecting many files at once and how to resolve it.

 

Or, is there a way to edit the lisp code so that no error messages will pop up and halt the flow of the program? 

Message 8 of 33

Maybe this will help you - AutoRunLisp 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 9 of 33

Hi there,

It's a bit weird to read this thread after all this time, as I nearly died from a heart attack 3 days after posting it.

Luckily for us both I'm still around to have a look at it 😉

 

Anyway, at the moment I don't have a clue as to what's wrong. It shouldn't happen. If a file can't be found, it should still be able to continue, unless the checks somehow fail, or there's some other file not loading.

 

What version acad are you using?

What version are the files you are using?

Is it random, or always with the same files?

Are other files loaded, like a lisp or scr?

...and I might think of some more questions, but that's a start to see if I can reproduce the problem.

Message 10 of 33

Oh my, I'm sorry to hear that, hope you are doing well now. I can understand this post brings back memories...

 

As to your questions. I've tried MFT on AutoCAD 2018 several times and Civil 3D 2022 one time, and the same problem occured on both versions.

 

I'm trying to replicate the problem now on AutoCAD 2018, and I've found three examples of files that fail to be executed correctly when an entire folder is selected (and those files are of course part of that folder or a subfolder of it). But the strange part is the same three files work perfectly when those sames file are chosen separately (with the "Select file(s)" button instead of "Select Dir." and "Add all files" buttons as I did the first time when they failed) as the only three drawings to be selected by MFT. So somehow those files work perfectly when assumably a small number of files are chosen for MFT to perform, but when 95 files are loaded in total, those three files insists on failing every time I've tried.

 

I used a simple lisp that aimed to clean up each file, this is all the code in the lisp.file:

(command "-purge" "r" "*" "n")
(command "-purge" "a" "*" "n")
(command "-scalelistedit" "r" "y" "e")
(command "qsave")

No other lisp or scr is loaded, I unchecked a command that I couldn't seem to delete form the list of commands.

 

So MFT opens up a drawing, cleans it with this lisp, and the closes the drawing, and on to the next. However, when it fails I get a pop up window for each key press my lisp instructs AutoCAD to perform. So one pop up message saying "Cannot find the specified drawing file. Please verify that the file exists." after "-purge", another on after "r", another one after "*", and so on until "qsave" and "0" (is that zero because I don't have a (princ) command at the end of the lisp by the way???), then it moves on to the next drawing. However, after both the "*" commands the pop up message instead says "Invalid file name." but on all other commands it is the same pop up window as above.

 

Also, the csv file always seem to be empty, so I haven't found a way of finding these problematic files apart from reading what file is being processed in the command line.

 

I will attach a collecting of screenshots so you can see what boxes are checked and what not on MFT aswell as some of the pop up messages. I will also attach one of these files that is problematic. 

 

Now when I look at the command bar at those screenshots, without knowing the MFT program works, it seems that there are two different files trying to be opened at the same time? So for example, when it fails to perform my lisp on the file J:\2015\15U27114\M\Modell\Etapp 2 modell\old\m-31-p-201_20210201.dwg, for some reason it also seems to be typing the link of another file in the list of files being processed: J:\2015\15U27114\M\Modell\Etapp 2 modell\old\M-30-P-202_recover.dwg . But since I don't know the inner workings of MFT maybe I misunderstood this, just thought to let you know

 

Thank you for making this lisp! As my company has tens of thousands of files needed to be cleaned up this lisp will work wonders for us!

Message 11 of 33

Okay... I think I broke it now... 🤔

 

When I tried to select files separately, I got some sort of error message saying files were selected multiple times. And indeed files were on the list twice. So I tried to remove the duplicates. But from now on, every time I try to process any files, regardless of which files I select, the program refuses to run, saying this in the command line after pressing the Process button:

 

Command: mft
filename;reason;action
Error: bad argument type: streamp nil
Command:

 

Tried restarting autocad, but the same problem occurs again and again. How can I resolve this? 

 

EDIT: A simple rebooting of the computer did the trick, nevermind this post 🙂

Message 12 of 33

Based on the info, I wonder if the files processed before the 3 files which go wrong, have been processed properly. Possibly something went wrong there, but it doesn't show until it (tries to) open the next drawing.

 

It should not matter much, but the QSAVE in your code is obsolete and it might interfere with the MFT process.

It shouldn't, afaik, but the script checks if the file changed and save it if needed, or disregard them if desired or if the file is read-only. By adding the qsave to your commands, it will still choke on any read-only files.

 

It does sound like there is something going wrong with a (command ...) call, as it will keep asking for an answer not provided by the suplied arguments. like asking a filename: and the answer is "-purge", it will ask again, and the answer is "r", etc. until it is either cancelled or the next valid filename is supplied.

 

However, MFT checks if the file exists before trying to open them and warn you if not found or skip it automatically based on your settings. So the (original acad) message should not appear, at least not from anything MFT does.

 

edit:

I couldn't read the text on the image, until I just downloaded the image & this tells me something.

First of all, the files you 'think' are not processed (when using the list) are actually the last ones processed correctly.

 

At the prompt it askes for a filename, displaying the previous entry between <>. The name supplied is actually coming after that and it apears to be a  _recover file, which can totally screw up the process.

 

The wierd part is  that 'No _recover' is checked, so there should be no _recover files in the list. That apears to be pointing to a bug, so I'll have to check on that. (currently @Anonymous, with just Acad-LT, so i'll get back on that l8r)

Message 13 of 33
roland.r71
in reply to: roland.r71

Yep, there was indeed a bug with the recover files, as it didn't recognize the all caps version (_RECOVER) as present with your filenames. Not sure if that will resolve your problem, but at least it should properly remove the _RECOVER files from the list.

 

So, try this new version to see if that resolves the issue:

 

Message 14 of 33

Thanks, yes it works much better now 🙂 I think you are correct that it was the recover files that were the issue, thank you for changing the lisp to exclude them better.

 

There was however one occurance of the same problem, but now someone in my organization had renamed the recover file to ..._recover1.dwg. I'm pretty sure this is very rare, and problaby not a big issue. I'm new at lisp and have only limited understanding of the code but I'm curious and interested to learn, so I want to find out what happened. So, if you don't mind me asking, this is the part of the code that checks for recover files, right? And basically the program checks if the last 8 characters of the file name are equal to "_recover". If that cdondition is true, MFT assumes the file is a recover file and is excluded from the list (if you have that box checked). Why is it needed to the check if the file name is more than 12 characters? Or did I misunderstand the first part of the if statement?

(if (and add (= noRecover "1"))
            (progn
               (setq len (strlen file))
               (if (and (> len 12)(= (strcase (substr file (- len 11) 😎 T) "_recover"))
                  (setq add nil rcvr (1+ rcvr))
               )
            )
         )

 What if instead of looking at the last 8 characters and see if they match "_recover" MFT would instead scan the file name for "_recover" regardless of where in the file name that substring exists, would this have solved the issue with my file "..._recover1" above? Hope you don't mind me asking!

Message 15 of 33
diagodose2009
in reply to: roland.r71

Why do you use doslib.arx?

I saw the source, and you call all function/s form doslib.arx, only with DirectoryAPI,

Doslib.arx is very good, but for more features, I put this question

==Can you avoid doslibx64.arx?

fruit.jpg

Message 16 of 33

Correct.

The check for the length is only there because smaller names can't contain "_recover.dwg" = 12 chars.

...but it could do without. I chose to check the last characters as that where it's supposed to be. Mostly to avoid excluding files containing "_recover" in their name.

 

If you where to change that to a check if it contains the string, then yes, that would solve your "_recover1" problem.

Message 17 of 33
roland.r71
in reply to: diagodose2009

Why?

Because I have to. There's a lot going on which requires doslib. I checked several times if I could do without, but I can't. Some of it could be done differently, without doslib, but not all of it.

 

So, no, I can't avoid it.

 

Here's a list of the doslib functions used, get me an alternative for ALL and I'll use them instead of doslib.

(note: I already know alternatives for some, but I need ALL these functions replaced, to avoid using doslib)

 

DOS_DIR : Returns list with filenames "file.ext"
DOS_DIRP : Checks if directory exists
DOS_DIRTREE : Returns list with directory tree from given starting directory
DOS_EDITBOX : Dialog to edit multiline text string (can import ascii file), returns new string
DOS_EDITLIST : Dialog to edit list items (add, delete, change order), returns new list
DOS_FILE : Returns list with file attributes. Read-Only, Archive, Hidden etc. nil on error
DOS_FILEP : Checks if file exists. Returns T when found
DOS_GETDIR : Dialog to select directory. Returns path "D:\path\"
DOS_GETFILED : Allows user to browse for a file. Returns path&filename "Drive:\path\to\file.ext"
DOS_GETINI : Returns value from a INI file
DOS_GETPROGRESS : Create & adjust progress indication bar
DOS_MKDIR : MaKe directory
DOS_MSGBOX : Creates and displays a custom dialog, with 6 button pre-sets & optional timer
DOS_MSGBOXEX : Creates and displays a custom dialog, with custom buttons
DOS_OPENP : Checks if file open. Returns T if so.
DOS_PWDIR : Returns Programs Working Directory
DOS_SETINI : Writes value to a INI file
DOS_SHELLEXE : Starts an executable and loads a file
DOS_UNCPATH : Returns UNC path name : (DOS_UNCPATH "P:\\Drawing1.dwg") returns "\\\\cadserver\\projects\\drawings\\drawing1.dwg"
DOS_VERSION : Returns the DOSlib version number
DOS_WAITCURSOR : Changes mouse cursor into sandclock (& back)
Message 18 of 33
roland.r71
in reply to: roland.r71

Attached are my latest version, 3.2 & manual.

edit:

Changelog:
- Fixed a bug with the up, down, ... buttons (reported by martti.halminen)
- Fixed a bug with ignoring _recover files (when written in all caps (_RECOVER))
- A few minor changes to the code and comments
- ends with blank/new drawing (again) instead of last in list

Message 19 of 33
dblouse
in reply to: roland.r71

Just adding this because it might help someone someday.

If you need a list of dwg files to batch process with a lisp program, either from a DOS command window or using the  shell command in AutoCAD run

DIR drive:\path\*.dwg /s /b>drive:\path\filename.txt

 

DIR is the dos directory command

The switch /s tells the DIR command to include the files in the specified folder and all subfolders

(use only if you want the files in the subfolders)

The switch /b tells the DIR command to display the bare format.

> is a redirection symbol (so instead of displaying the output on the screen it is saved in the text file)

 

With your lisp program you can open the text file and read it into a list variable in your program

 

Message 20 of 33
Sea-Haven
in reply to: roland.r71

Yep people like me IBM XT pc 1980 knew all about this. 

 

Did you know you can make scripts from the txt file using Word or Notepad++ looking for end of line and replace. Very fast when you know how. Again 1980+

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report