Author Topic: Extract Attribute Values and add to file name, and Save a copy?  (Read 2319 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Extract Attribute Values and add to file name, and Save a copy?
« on: November 12, 2014, 09:36:20 AM »
Does any one know of a way I can extract three attribute values from a block we use as our title block, Drawing-Title-Line1, Drawing-Title-Line2 and Drawing-Title-Line3 and have AutoCAD append it to the drawing filename and save a copy to a Folder Called "Issued" in the same directory as the drawing?

I have a client who want this added to every file, every time we issue drawings, as we have over 500 drawings, It will be a pain in the butt.
I also can't rename our files to what he wants, as our document control restricts file characters to set parameters, and the file names would push our file paths beyone the allowable character file limit is we add the titles.

There is no way I fancy having to type this in every time we issue, but he's not budging on this one.

**edit**
Oh, and I need to add a space after Title Line 1 and Title line 2, so the file name remains readable.
« Last Edit: November 12, 2014, 09:51:16 AM by hudster »
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Extract Attribute Values and add to file name, and Save a copy?
« Reply #1 on: November 12, 2014, 11:00:30 AM »
Here's something to get you started.  :)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _getattributevalue b f nf t1 t2 t3)
  2.   (defun _getattributevalue (block tag / att out)
  3.     (foreach att (vlax-invoke block 'getattributes)
  4.       (if (eq (strcase tag) (strcase (vla-get-tagstring att)))
  5.         (setq out (vla-get-textstring att))
  6.       )
  7.     )
  8.     out
  9.   )
  10.   (if (and (setq b (ssget "_x" (list (cons 2 "nameofyourtitleblock") '(66 . 1))))
  11.            (setq b (vlax-ename->vla-object (ssname b 0)))
  12.            (setq t1 (_getattributevalue b "Drawing-Title-Line1"))
  13.            (setq t2 (_getattributevalue b "Drawing-Title-Line2"))
  14.            (setq t3 (_getattributevalue b "Drawing-Title-Line3"))
  15.       )
  16.     (progn (setq f (strcat (getvar 'dwgprefix) "Issued\\"))
  17.            (setq nf (strcat f (vl-filename-base (getvar 'dwgname)) "_" t1 "_" t2 "_" t3 ".dwg"))
  18.            (vl-mkdir f)
  19.            (and (findfile nf) (vl-file-delete nf))
  20.            (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname)) nf)
  21.     )
  22.   )
  23.   (princ)
  24. )
« Last Edit: November 13, 2014, 08:51:47 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Extract Attribute Values and add to file name, and Save a copy?
« Reply #2 on: November 12, 2014, 11:21:09 PM »
@ ronjonp , I guess there won't be any evaluation after the quote function that you used for the block name .  ;-)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Extract Attribute Values and add to file name, and Save a copy?
« Reply #3 on: November 13, 2014, 12:58:42 AM »
@ ronjonp , I guess there won't be any evaluation after the quote function that you used for the block name .  ;)

Ah yes the ' over list ... I'll fix in the morning. Should not post code I don't test  :oops:


*FIXED
« Last Edit: November 13, 2014, 08:52:13 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hudster

  • Gator
  • Posts: 2848
Re: Extract Attribute Values and add to file name, and Save a copy?
« Reply #4 on: November 13, 2014, 11:24:14 AM »
Thanks, That works perfectly.

I won't tell the client just yet, I'll let him think I had to do it manually  ;-)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Extract Attribute Values and add to file name, and Save a copy?
« Reply #5 on: November 13, 2014, 11:37:58 AM »
Thanks, That works perfectly.

I won't tell the client just yet, I'll let him think I had to do it manually  ;)


Glad to help out.  8)  What is this word you speak of ?? maannnooooleeee?  ;D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC