EEgal Posted October 12, 2012 Posted October 12, 2012 I will start off by saying that I started looking intocreating lisp files...yesterday. So please forgive me if my terminology is off or my question is simply silly, but I have not been able to find a similar solution elsewhere. I currently have a file that will run several routines (purge, zoom extents on all layouts, etc) for all dwgs in a specified folder. Since I am using AutoCAD Electrical, it would be more ideal if I could have the user select the .wdp file and have it batchprocess the dwgs called out in the file. Is there a way to search within the specified file for all"*.dwg" strings? If I had those, I could use the extension from the location of the wdp (since the path would be relative). Once I have the list(or array or whatever format it could be?) of the file names, I'd need to have my routine run through that list as opposed to every file in the directory using vl-directory-files. Is this even possible (or does my question make any sense)? Thanks for the feedback! Quote
pBe Posted October 13, 2012 Posted October 13, 2012 Welcome to CAD Tutor EEgal Here: Batch Find & Replace Text: Lee Mac It will save the list of files found with the target string, replace it even. Then you can use that list for your batchprocess. HTH Quote
Lee Mac Posted October 13, 2012 Posted October 13, 2012 Hi EEgal, Unfortunately I've never used AutoCAD Electrical and so haven't come across a .wdp file before - are you able to attach a sample file to your post so that we may see the data format? Lee Quote
EEgal Posted October 15, 2012 Author Posted October 15, 2012 Thanks for the welcome! I've found this forum to be the most helpful of any site as I search for answers to random questions, so I am happy to finally join. Thanks for the advice on the batch find. That is actually the first lisp file I used (thanks Lee Mac!) when I had no idea what AutoLISP was. I tried going through it to see if it could be useful to search the file I have, but I will dig into it some more. I attached a sample .wdp file (saved as a .txt to upload) for you to see. Basically, what I am interested in is the list of files at the end of the document (i.e., FILENAME-000.dwg). These are always relative to the location of the .wdp file (either in the same folder, or the path will be defined). Knowing that, I can know where these files are once the user selects the .wdp file. Perhaps this is not possible, but it seems to me like it should be easy enough. There are several batch applications that would be excellent if I could do them for the files defined in the .wdp as opposed to anything within a directory. (When using Electrical, you always have to work in a project (.wdp), so being able to batch with the already defined drawings would be great). Thanks again for your help! Sample.txt Quote
Lee Mac Posted October 15, 2012 Posted October 15, 2012 After a quick search I found the following reference for the WDP file format: http://wikihelp.autodesk.com/AutoCAD_Electrical/enu/2012/Help/0239-Project_239/0245-Overview245 Noting that the lines not relating to the project drawing list files are always prefixed with either ?[##] / *[##] / +[##], I quickly put together the following function: (defun wdp-filenames ( fn / fd fl ln ) (if (and (setq fn (findfile fn)) (setq fd (open fn "r")) ) (progn (while (setq ln (read-line fd)) (if (not (wcmatch ln "*[`?`+`*]`[*`]*")) (setq fl (cons ln fl)) ) ) (setq fd (close fd)) (reverse fl) ) ) ) Call the above with the filename of your WDP file, e.g.: (wdp-filenames "C:\\Folder1\\Folder2\\Sample.wdp") (Note the use of double-backslashes in the above filepath). The function will then return a list of filenames, or nil if the file could not be found or opened for reading, or if no filenames were found. Quote
EEgal Posted October 15, 2012 Author Posted October 15, 2012 I didn't consider searching for lines other than those starting with the special characters. That seems like it should work. Sometimes the more simple the better! I'll see if I can play with that and get it to work with the rest of my code. Thanks again! Quote
EEgal Posted October 15, 2012 Author Posted October 15, 2012 Beyond silly question: I have assigned my .wdp file path to project. If this file has been defined and searched, I want to assign it to files. Is this not the correct way to do that: (setq files (wdp-filenames project)) It seems like I'm getting nil for files with that line. Quote
Lee Mac Posted October 15, 2012 Posted October 15, 2012 Is this not the correct way to do that: (setq files (wdp-filenames project)) That is indeed the correct way to call the function. A few questions: What is the value of the 'project' variable? Are you using double-backslashes (or single forward slashes) as the delimiter for folders in the filepath? Can the file be found by AutoCAD, i.e. what is returned if you type (findfile project) at the console / command-line? Quote
EEgal Posted October 15, 2012 Author Posted October 15, 2012 I am defining 'project' via the user selecting the wdp file: (if (setq project (getfiled "Select the drawing directory:" "" "wdp" 0)) (setq dir (vl-filename-directory project))) I've tested printing the value of 'project' and 'dir,' which both work as expected. I even tried using the full path with the double-backslashes as opposed to the assigned variable. Quote
EEgal Posted October 15, 2012 Author Posted October 15, 2012 You know what... I tested it by resaving the wdp as a txt and it worked. It looks like it will not read the wdp file with that extension. Quote
Lee Mac Posted October 15, 2012 Posted October 15, 2012 I tend to use bit-flag 16 with the getfiled function when prompting for selection of an existing file, as this bit-flag will always return the full filepath of the selected file; though, with the inclusion of findfile in my above function, this difference shouldn't cause a problem. Quote
Lee Mac Posted October 15, 2012 Posted October 15, 2012 I tested it by resaving the wdp as a txt and it worked. It looks like it will not read the wdp file with that extension. I'm glad you solved the issue. Quote
EEgal Posted October 15, 2012 Author Posted October 15, 2012 Thanks for the advice with getfiled. I'll keep that in mind as I delve into more of these. For some reason in my testing my wdp was emptied? (oops)...so it looks like it does work by reading the project file after all! Quote
wishbonesr Posted October 16, 2012 Posted October 16, 2012 Check your code for a line that says (open var "w"). "w" will over-write the file. When I was learning, I did that once.... In a batch sequence on several hundred csv reports. Thank goodness for tape drives back then. Quote
EEgal Posted October 16, 2012 Author Posted October 16, 2012 Check your code for a line that says (open var "w"). "w" will over-write the file. You know what, I know I did have a line that had the "w" in there when I was testing out different messages. That will teach me to not play around with functions before I look up their parameters. Thanks for the valuable tip! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.