Add File name to attribute without using Field - across multiple drawings

Add File name to attribute without using Field - across multiple drawings

tstorzuk
Advocate Advocate
1,373 Views
8 Replies
Message 1 of 9

Add File name to attribute without using Field - across multiple drawings

tstorzuk
Advocate
Advocate

A little help please,

 

I have about 60 drawings. In the titleblock, we have multiple attributes. In one of these attributes, I'd like to add the file name (without the file path or .dwg suffix).

 

I do NOT want it to be a field that updates, because when we turn over the drawings to our client, they rename the files to some ungodly name that has not much to do with the original file name.

 

Anyone have a solution for this?

0 Likes
1,374 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Mentor
Mentor

Put something like this in your startup and run a script:

 

(defun _foo (bname tag)
  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for a	b
      (and (vlax-property-available-p a 'name)
	   (= (strcase bname) (strcase (vla-get-name a)))
	   (vl-some '(lambda (x)
		       (and (= (strcase tag) (strcase (vla-get-tagstring x)))
			    (vla-put-textstring x (getvar 'dwgname))
		       )
		     )
		    (vlax-invoke a 'getattributes)
	   )
      )
    )
  )
)
;; Call like so
(_foo "YourBlockName" "TAGTOMODIFY")

Or if you want to run from the command line ( FOO ) use this after you input the correct blockname and tag string.

(defun c:foo (/ bname tag)
  (setq bname "YourBlockName")
  (setq tag "TAGTOMODIFY")
  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for a	b
      (and (vlax-property-available-p a 'name)
	   (= (strcase bname) (strcase (vla-get-name a)))
	   (vl-some '(lambda (x)
		       (and (= (strcase tag) (strcase (vla-get-tagstring x)))
			    (vla-put-textstring x (getvar 'dwgname))
		       )
		     )
		    (vlax-invoke a 'getattributes)
	   )
      )
    )
  )
  (princ)
)

 

Message 3 of 9

tstorzuk
Advocate
Advocate

Correct me if I'm wrong, but this looks like it will only work on a single open drawing.

0 Likes
Message 4 of 9

ronjonp
Mentor
Mentor

@tstorzuk wrote:

Correct me if I'm wrong, but this looks like it will only work on a single open drawing.


Yes hence "Put something like this in your startup and run a script:"

 

For the fastest solution, you could use Lee's ODBX wrapper and call like so:

 

(defun c:foo (/ bname tag)
  (lm:odbx '(lambda (doc)
	      (setq bname "BLOCKNAMEHERE")
	      (setq tag "TAGNAMEHERE")
	      (vlax-for	b (vla-get-blocks doc)
		(vlax-for a b
		  (and (vlax-property-available-p a 'name)
		       (= (strcase bname) (strcase (vla-get-name a)))
		       (vl-some	'(lambda (x)
				   (and	(= (strcase tag) (strcase (vla-get-tagstring x)))
					(vla-put-textstring x (getvar 'dwgname))
				   )
				 )
				(vlax-invoke a 'getattributes)
		       )
		  )
		)
	      )
	    )
	   nil
	   t
  )
  (princ)
)

 

*Definitely test it first .. seem to remember a justification issue from way back when.

 

0 Likes
Message 5 of 9

tstorzuk
Advocate
Advocate

I tested the one using Lee's OBDX Wrapper, and it came back with all of them listed as the file I had open (Drawing1.dwg).

 

And you were right about the justification issue....it messed them all up. Thank goodness it was just a test.

0 Likes
Message 6 of 9

pbejse
Mentor
Mentor

@tstorzuk wrote:

I tested the one using Lee's OBDX Wrapper, and it came back with all of them listed as the file I had open (Drawing1.dwg).

 

And you were right about the justification issue....it messed them all up. Thank goodness it was just a test.


 

There are other options:

  • ACoreconsole  + bat + scr ; <--- you need vanilla lisp for this
  • Scriptpro / Autoscript ; < --- Foo will work wtihout the danger of messing up the justification
  • Scriptwriter  and Batch Attribute Editor ; <-- or you can dive into LM scollection evern more and use this one
  • C# .NET; <-- Different forun

BTW: are you wanting to add the dwgname to an exisitng attribute value ? or set the value regardless?

 

 

 

0 Likes
Message 7 of 9

tstorzuk
Advocate
Advocate

I'm adding the file name (minus the .dwg suffix) to an existing attribute inside a block.

 

I'll try ScriptPro here shortly and let you know if it works. If it doesn't I'll try the Autoscript one with the foo LISP.

0 Likes
Message 8 of 9

pbejse
Mentor
Mentor

@tstorzuk wrote:

I'm adding the file name (minus the .dwg suffix) to an existing attribute inside a block.

 

I'll try ScriptPro here shortly and let you know if it works. If it doesn't I'll try the Autoscript one with the foo LISP.


Let us know how it goes OK?

BTW: if that you mean add to an existing value

(vla-put-textstring x
  	(strcat (Vla-get-textstring x) " " (vl-filename-base (getvar 'dwgname))))

otherwise

(vla-put-textstring x (vl-filename-base (getvar 'dwgname)))

 

HTH

 

 

0 Likes
Message 9 of 9

tstorzuk
Advocate
Advocate

Ah, I see what you mean now.

 

No, it'll completely replace the existing value (it should be blank when the files are created).

0 Likes