jda823 Posted March 7, 2012 Posted March 7, 2012 (edited) I have a large set of drawings that I would like to do the following to: Save drawings as a new file name Rename some layers in each drawing Update the drawing name that is located as plain text in the drawing. I have a .csv that has the following (with a list of all the affected drawings): OLDFILENAME NEWFILENAME OLDLAYERNAME NEWLAYERNAME This is what I have so far, am I on the right track? How do I go about using the csv data to find/replace the text/in the drawing and save it as the new file name. I would like to do this as a batch processes if possible. ;;-----------------------=={ Read CSV }==---------------------;; ;; ;; ;; Parses a CSV file into a matrix list of cell values. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2012 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; filename - filename of CSV file to read ;; ;;------------------------------------------------------------;; ;; Returns: List of lists - sublist is row of cell values ;; ;;------------------------------------------------------------;; ;;-------------------------------------------------------------------------------;; (defun LM:ReadCSV ( filename / _replacequotes _csv->lst file line lst ) (defun _replacequotes ( str / pos ) (setq pos 0) (while (setq pos (vl-string-search "\"\"" str pos)) (setq str (vl-string-subst "\"" "\"\"" str pos) pos (1+ pos) ) ) str ) (defun _csv->lst ( str pos / s ) (cond ( (null (setq pos (vl-string-position 44 str pos))) (if (wcmatch str "\"*\"") (list (_replacequotes (substr str 2 (- (strlen str) 2)))) (list str) ) ) ( (wcmatch (setq s (substr str 1 pos)) "\"*\"") (cons (_replacequotes (substr str 2 (- pos 2))) (_csv->lst (substr str (+ pos 2)) 0) ) ) ( (wcmatch s "\"*[~\"]") (_csv->lst str (+ pos 2)) ) ( (cons s (_csv->lst (substr str (+ pos 2)) 0))) ) ) (if (setq file (open filename "r")) (progn (while (setq line (read-line file)) (setq lst (cons (_csv->lst line 0) lst)) ) (close file) ) ) (reverse lst) ) ;;-------------------------------------------------------------------------------;; (defun c:updatedwgs ( fromfilename tofilename fromlayername tolayername / data file ) (if (and (setq file (getfiled "Select CSV File" "" "csv" 16)) (setq data (LM:ReadCSV file)) ) (progn (princ "\n(") (foreach line data (progn (princ "\n ") (prin1 line) (setq fromfilename (car line) tofilename (cadr line) fromlayername (caddr line) tolayername (cadddr line) ) ) (if (tblsearch "LAYER" fromlayername) ; found the layer (progn (command "-layer" "U" fromlayername "") (command "rename" "layer" fromlayername tolayername) ) ) ) ) (princ "\n)") ) (princ) ) ;;-------------------------------------------------------------------------------;; Edited March 8, 2012 by jda823 Quote
Lee Mac Posted March 8, 2012 Posted March 8, 2012 Why have you removed the header from my code? Quote
jda823 Posted March 8, 2012 Author Posted March 8, 2012 Why have you removed the header from my code? sorry about that, it was towards the end of the day and i just wanted to copy and paste the main part of what i was working with to get an idea of if i was going in the right direction. I am new to this and will keep it in mind next time. Quote
Lee Mac Posted March 8, 2012 Posted March 8, 2012 Here is the source: http://lee-mac.com/readcsv.html Please adjust your post and also read my Terms of Use. Quote
BIGAL Posted March 9, 2012 Posted March 9, 2012 Look into using a script possibly easier and don't need lots of coding experience open dwg1 rename la 1 2 saveas dwg1x close n open dwg2 rename la 1 2 saveas dwg2x close n open dwg3 rename la 1 2 saveas dwg3x close n As a start try this Start bottom corner CMD change to the directory you want eg K: cd\project52 Dir *.dwg >dirlst.txt /b rename la 1 2 saveas open drlst.txt in notepad etc copy paste I use word to do search and replace of end of line ^p to code the relevant bits like "open" then "rename la 1 2 saveas" and copy column alt&mouse etc post if you need help. To do example heaps of drawings 1-2mins I am pretty sure Lee, if you have not offended him to much has a script writer for this type of task. 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.