Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drawing Properties

20 REPLIES 20
Reply
Message 1 of 21
Anonymous
887 Views, 20 Replies

Drawing Properties

Does anyone know where I can get my grubby paws on a lisp routine or
programme which copies or replaces the drawing properties from one drawing
to another. I'm sure I saw one somewhere and could now do with it!

TIA

CTB
20 REPLIES 20
Message 2 of 21
Anonymous
in reply to: Anonymous

Does anyone know how to have the Drawing Properties dialog popup whenever a
"SaveAs" is done or a new drawing is saved. We'd like to start reminding
people to fill in the information.

Thank You


--
Matthew Kyle
Kephart Architects
770 Sherman St.
Denver, CO 80203
303/ 832-4474
303/ 832-4476 fax
Message 3 of 21
CR-AdskSubscription
in reply to: Anonymous

You could do this: Use the CUI to make a new button on a toolbar or palette and use this for the macro:

^C^Cdwgprops;saveas

Name the button whatever you want.

This will open the Drawing Properties so you can fill it in. After clicking OK or Cancel, the SAVEAS dialog will open.

You would have to convince your users to use the new button instead of doing a regular File>Save As. Or, you could alter the existing File>Save As command (via the CUI) with this code and the Drawing Properties dialog will open whether they want it to or not.
Message 4 of 21
irneb
in reply to: Anonymous

I'm working on exactly this at the moment. Although mine doesn't copy the properties between drawings, it rather exports them to a file, then import it to a different drawing. I've got the saving out of the drawing's properties to a file working. The function to load that file into the current drawing's properties is still incomplete. Here's my code so far:

;; Export Drawing Properties
(defun c:DwgPropExp
( / fn doc db si fid lst n pname pdata )
(setq fn (strcat;Get default filename from current drawing name
(getvar "DWGPREFIX") ;Get path to current drawing
(vl-filename-base (getvar "DWGNAME")) ;Get name of current drawing, excl. extension
".PRP" ;Set different extension
) ;_ end of strcat
) ;_ end of setq

(if (setq fn (getfiled "DwgProp Save" fn "prp" 1));Let user select filename
(progn
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) ;get vl object for current drawing
(setq db (vla-get-Database doc)) ;get vl object for drawing db
(setq si (vla-get-SummaryInfo db)) ;get vl object for drawing properties

;Get all standard drawing properties
(setq lst
(list
(vl-list* "TITLE" (vla-get-title si)) ;Get Title property
(vl-list* "SUBJECT" (vla-get-subject si)) ;Get Subject property
(vl-list* "AUTHOR" (vla-get-author si)) ;Get Author property
(vl-list* "KEYWORDS" (vla-get-keywords si)) ;Get Keywords property
(vl-list* "COMMENTS" (vla-get-comments si)) ;Get Comments property
(vl-list* "REVISION" (vla-get-revisionnumber si)) ;Get RevisionNumber property
(vl-list* "HYPERLINKBASE" (vla-get-hyperlinkbase si)) ;Get HyperlinkBase property
(vl-list* "LASTSAVEDBY" (vla-get-lastsavedby si)) ;Get LastSavedBy property
)
)

;Get all custom drawing properties
(setq n (1- (vlax-invoke-method si 'NumCustomInfo))) ;Set counter to 0 & get number of custom properties
(while (>= n 0) ;Step through all custom properties
(vlax-invoke-method si 'GetCustomByIndex n 'pname 'pdata) ;Get custom property number n
(setq lst (append lst (list (vl-list* pname pdata)))) ;Append to list
(setq n (1- n))
)

;Save list to file
(setq fid (open fn "w") pname (length lst) n 0);open / create file for saving properties
(while (< n pname) ;step through list
(setq pdata (nth n lst)) ;get nth element of list
(print pdata fid) ;write the current list item to the file
(setq n (1+ n))
)
(close fid)
)
)
(princ)
)

;; Import Drawing Properties
(defun c:DwgPropImp ( / fn fid lst line doc db si pname pdata pcount n p )
(if (setq fn (getfiled "DwgProp Save" "" "prp" 8));Let user select filename
(progn
(setq fid (open fn "r") lst (list))
(while (setq line (read-line fid))
(setq lst (cons (read line) lst))
)
(setq lst (reverse lst))

(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) ;get vl object for current drawing
(setq db (vla-get-Database doc)) ;get vl object for drawing db
(setq si (vla-get-SummaryInfo db)) ;get vl object for drawing properties

(defun is-custom-key-p ( si name / n ret pname pdata pcount )
(setq ret nil n 0 pcount (vlax-invoke-method si 'NumCustomInfo))
(while (and (< n pcount) (not ret))
(vlax-invoke-method si 'GetCustomByIndex n 'pname 'pdata)
(if (= pname name) (setq ret n) (setq n (1+ n)))
)
ret
)

;Set all standard drawing properties
(vlax-put-property si 'Title (cdr (assoc "TITLE" lst))) ;Set Title property
(vlax-put-property si 'Author (cdr (assoc "SUBJECT" lst))) ;Set Author property
(vlax-put-property si 'Author (cdr (assoc "AUTHOR" lst))) ;Set Author property
(vlax-put-property si 'Author (cdr (assoc "KEYWORDS" lst))) ;Set Author property
(vlax-put-property si ' (cdr (assoc "COMMENTS" lst))) ;Set Author property
(vlax-put-property si 'RevisionNumber (cdr (assoc "REVISION" lst))) ;Set Author property
(vlax-put-property si 'HyperlinkBase (cdr (assoc "HYPERLINKBASE" lst))) ;Set Author property
(vlax-put-property si 'LastSavedBy (cdr (assoc "LASTSAVEDBY" lst))) ;Set Author property
(setq lst
(list
(vl-list* "TITLE" (vla-get-title si)) ;Get Title property
(vl-list* "SUBJECT" (vla-get-subject si)) ;Get Subject property
(vl-list* "AUTHOR" (vla-get-author si))
(vl-list* "KEYWORDS" (vla-get-keywords si)) ;Get Keywords property
(vl-list* "COMMENTS" (vla-get-comments si)) ;Get Comments property
(vl-list* "REVISION" (vla-get-revisionnumber si)) ;Get RevisionNumber property
(vl-list* "HYPERLINKBASE" (vla-get-hyperlinkbase si)) ;Get HyperlinkBase property
(vl-list* "LASTSAVEDBY" (vla-get-lastsavedby si)) ;Get LastSavedBy property
)
)

;Get all custom drawing properties
(setq n (length 8)) ;Set counter to 0 & get number of custom properties
(while (>= n 0) ;Step through all custom properties
(vlax-invoke-method si 'GetCustomByIndex n 'pname 'pdata) ;Get custom property number n
(setq lst (append lst (list (vl-list* pname pdata)))) ;Append to list
(setq n (1- n))
)
)
)
(princ)
)

Of course the second function needs quite a lot of modification, maybe even a dialog so you can select which properties to import. Message was edited by: irneb
Message 5 of 21
irneb
in reply to: Anonymous

I wonder if you could use a reactor ... although it's not recommended to use reactors for user input ... but that's because you don't want hundreds of queries to the user - in this case it should only happen once for a saveas command.

Otherwise you could redefine the saveas command, but I don't know if it will have further repercussions.
Message 6 of 21
Anonymous
in reply to: Anonymous

Did you ever finish this code?
Message 7 of 21
irneb
in reply to: Anonymous

Just finished it now ... here's the LSP & DCL files.

Place them in a folder in one of AutoCAD's support directories & load the LSP before you use it. It saves to a PRP file. The import function opens a dialog where you can select which properties to import as well as which existing properties to delete. The commands are:
iDwgPropExp for Export
iDwgPropImp for Import

You may want to add a command to your custom menu for this, you could even add the autoloading loading to your acad.lsp or acaddoc.lsp file by adding the following line to one.

(autoload "iProperties" '("iDwgPropExp" "iDwgPropImp"))

Please note that it hasn't been tested properly, so there may be some bugs.
Message 8 of 21
irneb
in reply to: Anonymous

Sorry forgot to attach ... must be a bad day.
Message 9 of 21
CR-AdskSubscription
in reply to: Anonymous

Nice tool! There could be some value here. I gave it a test drive. The export side of the routine worked for me. Is PRP a new file extension? No matter...the export seems to work.

When I tried to import into a different drawing, I was able to select the PRP file that I exported, but my command line came back with this message:

; error: quit / exit abort

I thought you'd like to know for debugging purposes.
Message 10 of 21
irneb
in reply to: Anonymous

Thanks for the feedback. Which AC version are you using? I've tested it on 2007 - haven't had that error.
Message 11 of 21
irneb
in reply to: Anonymous

You're right the PRP extension is a new one I've chosen (PRoPerties). You could change this by altering the LSP file in the corresponding places. I've checked for naming conflicts, the only one I've found is: "Compressed GIMP Image with Properties of GIMP Properties File"

This file is simply a text file containing a list of "dotted-pairs" (separated by new-line) as follows:
("Property name" . "Property value")

Sorry about the error, I've found that I've misspelled the REVISION property, as the actual name is RevisionNumber. The update is attached.
Message 12 of 21
CR-AdskSubscription
in reply to: Anonymous

I am also using 2007.

I must be doing something wrong.

What is the main command to run it?
Message 13 of 21
CR-AdskSubscription
in reply to: Anonymous

Never mind. I forgot to set the search path.
Message 14 of 21
Anonymous
in reply to: Anonymous

Eveything worked fine as is....However, I was getting an error message on the revision heading...so I just removed it from the code.

Great Code...Thanks a lot!
Message 15 of 21
irneb
in reply to: Anonymous

No prob ... that revision thing I've updated ... got the same problem, see my previous post. It wouldn't make a difference though, it just wouldn't update the Revision Number property.

Not that you could use it in the Drawing Properties dialog, as it isn't shown there. I've included it because the SummaryInfo ActiveX object has such a property. Of course it gets ignored by default, so as I said - wouldn't make a difference.
Message 16 of 21
Anonymous
in reply to: Anonymous

THANKS, YOU HAVE BEEN A GREAT HELP!
Message 17 of 21
karthur1
in reply to: Anonymous

Below is a copy/paste of the code that is in your zip file. Where in this does the values get written back to the drawing properties? How do I set what drawing property gets written to? I have a value that I would like to write to the "Title" drawing property.

Thanks

(defun C:CHG-ATT-TAGS (/ ss blk Tagname NewValue Tag x atts att)
; Change Attribute Tag Values
(vl-load-com)
(setq ss nil)
(setq Tagname (strcase (getstring "\nAttribute TagName:")))
(setq NewValue (getstring 1 "\nNew Attribute Value String:"))
(setq Tagname "XX") ; name of attribute tag
(setq NewValue " ") ; just replace with a space character
(setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 66 1))))
; get just Blocks w/ attr
(if (/= ss nil)
(progn
(setq x 0)
(repeat (sslength ss)
(setq blk (vlax-ename->vla-object (ssname ss x)))
(if (safearray-value
(setq atts (vlax-variant-value (vla-getattributes blk)))
)
(progn
(setq atts (vlax-safearray->list
(vlax-variant-value (vla-getattributes blk))
)
)
(foreach att atts
(setq Tag (strcase (vla-get-tagstring att)))
(if (= Tag (strcase Tagname))
(vla-put-textstring att NewValue)
) ; if
) ; foreach
) ; progn
) ; if
(setq x (+ x 1))
) ; repeat length ss
) ; progn
) ; if
(princ)
) ; end function
(C:CHG-ATT-TAGS) ; run function when loaded - for scripting..
(princ) ; silent load
Message 18 of 21
irneb
in reply to: Anonymous

The lines saving to the standard properties (where the Title property is contained) is near the end of the c:iDwgPropImp function.

(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) ;get vl object for current drawing
(setq db (vla-get-Database doc)) ;get vl object for drawing db
(setq si (vla-get-SummaryInfo db)) ;get vl object for drawing properties
;;;;; some other code here ;;;;;
(if (vl-position str iPropStanList) ;Check if standard property
(vlax-put-property si str (cdr lstp)) ;Set standard property

In your case it would be something like
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq db (vla-get-Database doc))
(setq si (vla-get-SummaryInfo db))
(vlax-put-property si "Title" "whatever value you want here")

Looking at your function, am I understanding correctly that you want to update your drawing's Title property from an Attribute in a block?
Message 19 of 21
karthur1
in reply to: Anonymous

Yes, I am trying to update the Title property with an Attribute value from a block. At first I thought this would be simple, but the block name could vary between all the drawings that I have to go through. It looks like there are 4 different block names that I have to find. Once I find the block, then I can drill down inside it and find the tag value.
Message 20 of 21
irneb
in reply to: Anonymous

If you're going to run this in a script. Why not hardcode the various block names into the lisp, then use your ssget with something like this:
(ssget "x" '((0 . "INSERT") (2 . "blkname1,blkname2,blkname3")))

The string of block names you could set as a global variable at the start of the lisp, so you can more easily add / remove any blkock names at a later stage.

Then the only thing you have to worry about is the attribute tag names, which may of course also vary.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost