Adding new Custom Properties to multiple drawings

Adding new Custom Properties to multiple drawings

edward.sabourin
Explorer Explorer
3,120 Views
15 Replies
Message 1 of 16

Adding new Custom Properties to multiple drawings

edward.sabourin
Explorer
Explorer

I'm really new at LISP creation . I am trying to find a quick way to add and update about 20 Custom Drawing Properties so that we can update all the title blocks in our drawings.

 

So like want to add " Drawn By" "XX"

Drawn By - Day "DD"

Drawn By - Month "MM"

etc.......  like below . 

edwardsabourin_0-1637937632427.png

 

0 Likes
Accepted solutions (2)
3,121 Views
15 Replies
Replies (15)
Message 2 of 16

CodeDing
Advisor
Advisor
Accepted solution

@edward.sabourin ,

 

Not sure if this is 100% what you're asking for, but I used to have to do this quite a bit at my last company. Attached is a "PROPS.lsp" file which uses 2 commands "PROPOUT" and "PROPIN".

 

PROPOUT will export all custom dwgprops from your current drawing to a place of your choosing.

PROPIN will ask for the file which was exported, then import all of those properties into the current drawing.

 

You will clearly have to load this lisp file into each drawing since lisps do not run across multiple drawings.

 

BUT... If you just want to learn more about manipulating Custom DWG Props with lisp, you can look here at the SummaryInfo Object. It houses all of the Custom DWG Props. Look at the Methods in particular, they will provide good example codes..

 

SummaryInfo - https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-A029FB49-B0DB-43E4-8888-698E1BF49878

 

Best,

~DD

0 Likes
Message 3 of 16

edward.sabourin
Explorer
Explorer

I loaded the Lisp file on the file i wanted to export all the properties from . Then typed propout.  Saved the file as new props.prop.  Then I open the file  which I wanted to import the properties from ant typed in propin .  both times command said complete but   the file I wanted to import to still  has no custom properties in it . I'm using AutoCad 2019  to run this test on.

 

Confused !

Best regards,

Ted

0 Likes
Message 4 of 16

CodeDing
Advisor
Advisor

Weird.. The testing worked for me each time and there shouldn't be much room for error. After you create the props.prop file, open it with Notepad. Are the properties visible inside the file?

0 Likes
Message 5 of 16

edward.sabourin
Explorer
Explorer

Yep I opened with notepad , I can see all the properties are there .

So Im confused as to why it doesn't work 

0 Likes
Message 6 of 16

CodeDing
Advisor
Advisor

Ok thanks.. And to be VERY clear, your workflow looks like this correct? :

 

[DWG-1] - Has Custom DWG Props

[DWG-2] - No Custom DWG Props

 

>> Open [DWG-1]

>> Run PROPOUT

>> "props.prop" file is created

>> Open [DWG-2]

>> Run PROPIN

>> Select "props.prop" file

>> Custom Properties SHOULD be created

0 Likes
Message 7 of 16

edward.sabourin
Explorer
Explorer

Yep exactly like that .     

 

0 Likes
Message 8 of 16

CodeDing
Advisor
Advisor

Well, I can not think of a single reason it should not work then Lol.

Can you perhaps post an example dwg with the Custom DWG Props in it that when exported do not import into another dwg?

 

Best,

~DD

0 Likes
Message 9 of 16

edward.sabourin
Explorer
Explorer

I tried it on 2 separate versions of ACAD 2019 & 2022 and 2 different networks.  In every case the propout works but Propin doesn't .    Anyhow,

 I appreciate the effort , Wondering if is because there are values assigned in the properties ?

Best regards,

Ted

0 Likes
Message 10 of 16

CodeDing
Advisor
Advisor
Accepted solution

@edward.sabourin ,

 

Hmmm, I may have found a silly simple mistake. Try the updated attached file. Might fix it.

 

Best,

~DD

Message 11 of 16

edward.sabourin
Explorer
Explorer

Awesome, Totally works now!  

Message 12 of 16

edward.sabourin
Explorer
Explorer
Thank you so much, Glad you found the glitch!
0 Likes
Message 13 of 16

CodeDing
Advisor
Advisor

Great! Sorry for all the troubles. Glad to help though 😎👍

0 Likes
Message 14 of 16

3rduser
Contributor
Contributor

Stumbled across this thread yesterday and found the code really useful. Thanks @CodeDing for pointing the code out, I wanted to throw my two cents in for potential quick improvements if anyone wants it.

 

-I have renamed the lisp "dwgpe" for dwg props edit.

-Edited so it's all in one program now with "export" and "import" options.

-I noticed when I used the above code it gets all of my properties correctly, stores them correctly, but when importing it reverses them. I have fixed this as well (it least on my end) so the new properties come in exactly as listed in order within the .prop file.

-I have also re-tabbed the whole code to make it easier to read.

 

cheers.

(defun c:dwgpe ( / dwgsel cdps path f str txt props )
	(initget 1 "e i")
	(setq dwgsel (getkword "\nSELECT DWGPROPS OPTION: [(E)xport/(I)mport] > "))
	(cond
		(
			(eq dwgsel "e")
			(vl-load-com)
			(if
				(and
					(setq cdps (CDP-List))
					(setq path (getfiled "\nSELECT FILE LOCATION AND NAME TO SAVE AS >" (getvar 'DWGPREFIX) "prop" 1))
				)
				(progn
					(setq f (open path "w"))
					(foreach cdp cdps
						(write-line (car cdp) f)
						(write-line (cdr cdp) f)
					)
					(close f)
					(prompt (strcat "\nFILE CREATED >" path))
					(setq str "\nEXPORT COMPLETE!")
					(princ str)
				)
				(prompt "\nERROR: CUSTOM DRAWING PROPERTIES NOT FOUND OR INVALID FILE LOCATION.")
			)
		)
		(
			(eq dwgsel "i")
			(vl-load-com)
			(if
				(setq path (getfiled "\nSELECT PROPERTIES IMPORT FILE >" (getvar 'DWGPREFIX) "prop" 0))
				(progn
					(setq cdps (CDP-List))
					(if cdps (setq cdps (mapcar 'cons (mapcar 'strcase (mapcar 'car cdps)) (mapcar 'cdr cdps))))
					(setq f (open path "r"))
					(while
						(setq txt (read-line f))
						(cond
							(
								(and cdps (not (assoc (strcase txt) cdps)))
								(setq props (append props (list (cons txt (read-line f)))))
							)
							(cdps (read-line f))
							(t (setq props (append props (list (cons txt (read-line f))))))
						)
					)
					(close f)
					(foreach cdp props (CDP-Create (car cdp) (cdr cdp)))
					(setq str "\nIMPORT COMPLETE!")
					(princ str)
				)
				(prompt "\nERROR: NO PROPERTIES FILE SELECTED.")
			)
		)
	)
	(princ)
)

(defun CDP-Create ( key val / docProps return num keyVal propVal )
	(vl-load-com)
	(if
		(and (eq 'STR (type key)) (eq 'STR (type val)))
		(progn
			(setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
			(vla-AddCustomInfo docProps key val)
			(cons key val)
		)
	)
)

(defun CDP-List ( / docProps cnt key val return )
	(vl-load-com)
	(setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
	(repeat
		(setq cnt (vla-NumCustomInfo docProps))
		(vla-GetCustomByIndex docProps (setq cnt (1- cnt)) 'key 'val)
		(setq return (cons (cons key val) return))
	)
)

 

Message 15 of 16

mwern
Explorer
Explorer

Hi -

Thank you for posting this code.  I am new to lisp creation.  

 

I am able to successfully load the dwgpe.lsp file and when I perform the export and import it says they both worked.  However, after I import the new .prop file back into the drawing it does not change any of my values.  I want to change the "value" of the "name" of VENDOR.  Can you help me with this?  My customer has dwgprops set because he uses autodesk vault software.

 

 I'm attaching a .dwg file for the example.  

 

Thank you,

Mitzi

 

0 Likes
Message 16 of 16

Sea-Haven
Mentor
Mentor

Something we did was not using custom properties but rather copy a layout attributes to all other layouts, so could pick one attribute or multiple and the new value would be copied/updated to all layouts. is this something that would be useful ? You get a display of tagnames and current value in the title block shown leave blank and that attribute is not updated. Just a Ps my last title block had 25 attributes.

0 Likes