Jump to content

Recommended Posts

Posted (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 by jda823
Posted
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.

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...