I have a large amount of 2d autocad files in a folder. I need to find the length of each one. So far I have been doing each one individually using tlen (http://www.turvill.com/t2/free_stuff/tlen.lsp). Is there a way to write a script that would read in filenames, say from an excel document or text file, open the file, calculate the length of the lines, write that value out to the excel or text file, close the file and continue down the list? I imagine this has to be possible but I'm not sure how to go about it. I'm not looking for someone to write the code for me but if anyone has any advice or knows any resources that may help me with this, I would greatly appreciate it.
Thanks!
Solved! Go to Solution.
Solved by Gary_J_Orr. Go to Solution.
1) When I click your link, I get a message that "the file is not found on this server."
2) Are you wanting to get the length of EVERY line in each of these files? What about polylines?
If you want to read the list of files from a file, you'll need to use VBA. A script file will need a hard-coded list. A lisp routine COULD read the text file -- but the list wouldn't follow through to the next file.
Don Ireland
Engineering Design Technician
1. Sorry, it looks like the end parenthese and period get tacked on at the end. Hopefully this is better:
http://www.turvill.com/t2/free_stuff/tlen.lsp
2. Yes, every line including polylines.
I'm a decent programmer but I've only used VBA a little bit. I assume this requires the Autocad VBA Enabler? I will look into it more and ask more specific questions as they come up. Thanks.
@Jeffsg605 wrote:I have a large amount of 2d autocad files in a folder. I need to find the length of each one. So far I have been doing each one individually using tlen (http://www.turvill.com/t2/free_stuff/tlen.lsp). Is there a way to write a script that would read in filenames, say from an excel document or text file, open the file, calculate the length of the lines, write that value out to the excel or text file, close the file and continue down the list? I imagine this has to be possible but I'm not sure how to go about it. I'm not looking for someone to write the code for me but if anyone has any advice or knows any resources that may help me with this, I would greatly appreciate it.
Thanks!
To address the output portion of the task change a line of code in the routine that you posted to have it produce a comma delimited text file (which can then be opened in Excel to give you totals if you want)...
;GJO: change original code: ;;; (alert (strcat "Total length of selected objects is " (rtos tl))) ;to this (for logging to a comma delimiten text file): (setq logfile (strcat (getvar "DWGPrefix") "LineLengths.txt")) (setq resource (open logfile "a")) (write-line (strcat (getvar "DWGName") " ," (rtos tl)) resource) (close resource) (setq logfile nil resource nil) ;end modification
To address the rest: I have been working on a utility that processes a script or lisp routine on all of the files in a given folder (and even the subfolders thereof).
It's working pretty good so far and you're free to see if it will give you the "multi-file processing" part of the task.
Close all sessions of autocad, then launch a new session, load the function, then type in "GJO_FLA"
Pay close attention to the prompts, especially the dialog that prompts you to open the directory that you want to process and provide a log file name. . Feedback is appreciated on the function as it is still a work in progress.,
Happy Drafting,
Gary
@Jeffsg605 wrote:1. Sorry, it looks like the end parenthese and period get tacked on at the end. Hopefully this is better:
http://www.turvill.com/t2/free_stuff/tlen.lsp
2. Yes, every line including polylines.
I'm a decent programmer but I've only used VBA a little bit. I assume this requires the Autocad VBA Enabler? I will look into it more and ask more specific questions as they come up. Thanks.
On 64-bit AutoCAD using VBA is a pretty bad idea, it will have serious performance effects.
You do not necessarily need VBA. The problem is that AutoLISP has separate memory areas for each drawing, so a single AutoLISP program can't control work on separate drawings without some odd contortions.
So you need some external program to control AutoCAD, but it could be as well C#.NET, C++ or any outside system that can use ActiveX.
- I've done that using Common Lisp, and I've seen mentions in these forums of people using Delphi and even Fortran.
--
@Jeffsg605 wrote:I have a large amount of 2d autocad files in a folder. I need to find the length of each one. So far I have been doing each one individually using tlen (http://www.turvill.com/t2/free_stuff/tlen.lsp). Is there a way to write a script that would read in filenames, say from an excel document or text file, open the file, calculate the length of the lines, write that value out to the excel or text file, close the file and continue down the list? I imagine this has to be possible but I'm not sure how to go about it. I'm not looking for someone to write the code for me but if anyone has any advice or knows any resources that may help me with this, I would greatly appreciate it.
Thanks!
I haven't tested this, but I think one way of doing this could be creating a separate AutoCAD profile just for this, and have the work done using its acaddoc.lsp file.
Before running that, create a list of all file paths you want to operate on, and write it to a file with a known address.
Open the first file on the list using the special profile.(or even just an empty new drawing, if your calculations won't crash on that)
In the acaddoc.lsp:
- close any other drawings currently open [the previous drawing handled]
- do your calculations, and store the results in a file
- remove the current drawing's path from the file of paths to handle
- if the list of pending drawings is empty, summarize the results, else open the next drawing on the list.
If you have performance problems, you could try the "headless" AutoCAD Core Console.
--
Thanks Gary! That looks very promising. I haven't had much time the past couple days to work with it but I definitely intend to soon. One quick question though, where does the .log file get stored? In the directory of the cad files asked for in the beginning? I ran your script with that tlen function I linked to and no file was created. I've only had a few minutes to mess with it so I may have missed something obvious. In any case, thank you very much! I'll let you know how it goes.
The log files that my routine creates (success/fail for ability to complete whatever lisp/script is passed to it) goes in the directory that you open (the directory that is to be processed) and with the filename that you specify ...
The modified Tlen function should then generate log files in whatever directory is being processed at the time (the modification that I supplied you with gets the directory of the current file for the path.)
Did you modify the Tlen Function per my earlier post?
It should look something like the attached...
Gary
I used your attached code and it works very well. There is still no log file created though and I followed the prompts carefully. When it asks for the function name, "(C:TLEN_Log)" appears in the box. When I retype "TLEN_Log" and hit enter, it is replaced by "(C:TLEN_Log)". I don't know if this is a problem or not but no new documents are being created, including LineLengths.txt from the lsp routine you attached. I appreciate your help so far and I will work with it more. Thanks again!
My files are all .dxf's. Could that be causing the issue? I can't seem to open a .dxf using the command "-open PartNumber.dxf". I get a window that says "Cannot find the specified file". Maybe nothing is being opened?
Thats unfortunate for me. I figure I can use your modified TLEN_Log file and write a script that looks like this:
OPEN
C:\parts\729.dxf
TLEN_Log
all
OPEN
C:\parts\1218.dxf
TLEN_Log
all
...
It's a little tedious but it sure beats what I was doing before. I'm thinking I can write a C program to read a list of my files and spit out this script. I have literally thousands of parts to do. Thanks a lot for your advice, you've been a big help.
try these...
modified (quick and dirty so I may have missed something) GJO_FLA_RO will prompt for filetype (dwg or dxf) and will process as read-only so there are no issues with filetype when exiting.
Modified TLEN_Log to select everything (in current space when the file is opened, which should be modelspace with a dxf file I believe).
I ran your programs and this is what happened. When the TLEN_Log program is ran, I have to hit Ctrl+A to select all for each drawing. Then it continues on to the next one where I have to do the same thing and so on. Also, the processed.log file that is created only has the filenames of all the programs. I really appreciate your help so far and you don't need to keep going out of your way. I can probably figure it out from here. However if you do fix it, I will be happy to test it for you.
Thanks!
You, my friend, are a genius! I used the correct TLEN, I just looked at the wrong file. Huge help! Thank you so much!