Author Topic: Rename files to attribute within title block  (Read 2657 times)

0 Members and 1 Guest are viewing this topic.

shollinger

  • Guest
Rename files to attribute within title block
« on: December 11, 2007, 05:33:07 PM »
I am looking for a script or something similar to rename several files to the dwg. no. attribute with-in the title block.  Currently file names are piping line numbers but upon submission to client they have to be renamed to client specific file names.(drawing numbers).  Any ideas?

Stephen
shollinger@rdcon.com

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Rename files to attribute within title block
« Reply #1 on: December 11, 2007, 05:45:38 PM »
You'll need to provide a sample drawing or the attribute tag names
if you want more than a confirmation it can be done
and generic description of how to do it.

.. doing a Save-as rather than a rename may be more expedient.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Rename files to attribute within title block
« Reply #2 on: December 11, 2007, 07:06:02 PM »
This should get you going...not heavily tested:

To use call (batchrename "nameofblock" "tagname")

Have fun  :-)

Code: [Select]
(defun rjp-dir (message / sh folder result)
  (setq sh (vla-getInterfaceObject
     (vlax-get-acad-object)
     "Shell.Application"
   )
  )
  (setq folder
(vlax-invoke-method
   sh 'BrowseForFolder 0 message 0)
  )
  (vlax-release-object sh)
  (if folder
    (progn
      (setq result
     (vlax-get-property
       (vlax-get-property folder 'Self)
       'Path
     )
      )
      (if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result
      )
    )
  )
)

(defun batchrename
       (BLKNAME TAG / ATTS DIR DOC FILES ODBX RENAME VNUM X)
  (setq dir   (rjp-dir "Select a folder to process drawings")
files (mapcar '(lambda (x)
(strcat dir x)
       )
      (vl-directory-files dir "*.dwg" 0)
      )
vnum  (substr (getvar 'acadver) 1 2)
doc   (vlax-get-acad-object)
odbx  (if (< vnum "16")
(vla-GetInterfaceObject doc "ObjectDBX.AxDbDocument")
(vla-GetInterfaceObject
  doc
  (strcat "ObjectDBX.AxDbDocument." vnum)
)
      )
  )
  (if files
    (foreach dwg files
      (if (vl-catch-all-error-p
    (vl-catch-all-apply 'vla-open (list odbx dwg))
  )
(prompt (strcat "\nCould not open DWG - " dwg))
(progn
  (prompt (strcat "\nProcessing - " dwg))
  (vlax-for l (vla-get-layouts odbx)
    (vlax-for ent (vla-get-block l)
      (if (and (eq (vla-get-objectname ent)
   "AcDbBlockReference"
       )
       (eq (strcase (vla-get-name ent))
   (strcase BLKNAME)
       )
  )
(progn
  (foreach att (vlax-invoke ent 'getattributes)
    (if (eq (vla-get-tagstring att)
    (strcase TAG)
)
      (setq rename (strcat dir
   (vla-get-textstring att)
   ".dwg"
   )
      )
    )
  )
)
      )
    )
  )
  (if (not rename)
    (setq rename (vla-get-name odbx))
  )
  (vl-catch-all-error-p
    (vl-catch-all-apply
      'vla-saveas
      (list odbx rename)
    )
  )
  (setq rename nil)
)
      )
    )
  )
  (princ)
)

(batchrename "RUB_ISO_BORDER" "DWGNO")
« Last Edit: December 12, 2007, 10:16:24 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

shollinger

  • Guest
Re: Rename files to attribute within title block
« Reply #3 on: December 12, 2007, 08:27:32 AM »
Ron,
Trying to use your code.  Looks like this would be the best route for us here.  I can get it to process the drawings but to no avail will it rename them to the correct value.  Do I need to substitute my block name and tag value in here.  Besides at the call command.
(batchrename "RUB_ISO_BORDER" "DWGNO")

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Rename files to attribute within title block
« Reply #4 on: December 12, 2007, 10:03:27 AM »
If you post a sample drawing (as Kerry mentioned) this would be much easier to troubleshoot.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

shollinger

  • Guest
Re: Rename files to attribute within title block
« Reply #5 on: December 12, 2007, 10:06:20 AM »
Thanks again

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Rename files to attribute within title block
« Reply #6 on: December 12, 2007, 10:17:15 AM »
I updated the code above...ran this (batchrename "RUB_ISO_BORDER" "DWGNO") and it worked over here. Let me know if it works for you. Keep in mind that this routine does not process subdirectories.

Ron
« Last Edit: December 12, 2007, 10:23:08 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

shollinger

  • Guest
Re: Rename files to attribute within title block
« Reply #7 on: December 12, 2007, 10:24:13 AM »
so the change was
(if (not rename)      near the end. 
I have only worked with lisp in the past.  I need to get into this vba.  Much better for the things I need to do around here.  Have any suggestions on tutorials to get me started. 


ronjonp

  • Needs a day job
  • Posts: 7531
Re: Rename files to attribute within title block
« Reply #8 on: December 12, 2007, 10:46:15 AM »
Shollinger,

This is lisp\vlisp not VBA. I loop through the drawings and check to see if the block with the correct tagname exists...if it does the value from the att is extracted and put into the rename variable. If the variable is not set (not rename) then set rename to the original name of the drawing. As far as resources.....right where you're at does not get much better :)

So I assume this worked for you?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

shollinger

  • Guest
Re: Rename files to attribute within title block
« Reply #9 on: December 12, 2007, 10:52:25 AM »
Ran on a test folder and work perfectly.  I will be able to set this up for multiple departments and there individual needs.   I will look into the links for some vlisp help and get into this.  I will be able to go to owners with ROI.  Thanks again for all your help.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Rename files to attribute within title block
« Reply #10 on: December 12, 2007, 11:03:59 AM »
Glad it worked for you... :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC