Visual LISP, AutoLISP and General Customization

Reply
*CTB
Message 1 of 21 (73 Views)

Drawing Properties

73 Views, 20 Replies
07-10-2001 05:47 PM
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
*Kyle, Matthew
Message 2 of 21 (73 Views)

Re: Drawing Properties

07-17-2001 09:12 PM in reply to: *CTB
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
Distinguished Contributor
Posts: 120
Registered: ‎10-09-2003
Message 3 of 21 (73 Views)

Re: Drawing Properties

11-28-2006 12:02 PM in reply to: *CTB
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.
Distinguished Contributor
Posts: 214
Registered: ‎08-16-2006
Message 4 of 21 (73 Views)

Re: Drawing Properties

11-29-2006 04:37 AM in reply to: *CTB
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:smileyvery-happy:wgPropExp
( / 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:smileyvery-happy:wgPropImp ( / 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
Distinguished Contributor
Posts: 214
Registered: ‎08-16-2006
Message 5 of 21 (73 Views)

Re: Drawing Properties

11-29-2006 05:45 AM in reply to: *CTB
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.
Member
Posts: 4
Registered: ‎12-05-2006
Message 6 of 21 (73 Views)

Re: Drawing Properties

12-06-2006 06:48 PM in reply to: *CTB
Did you ever finish this code?
Distinguished Contributor
Posts: 214
Registered: ‎08-16-2006
Message 7 of 21 (73 Views)

Re: Drawing Properties

12-06-2006 11:22 PM in reply to: *CTB
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.
Distinguished Contributor
Posts: 214
Registered: ‎08-16-2006
Message 8 of 21 (73 Views)

Re: Drawing Properties

12-06-2006 11:30 PM in reply to: *CTB
Sorry forgot to attach ... must be a bad day.
Distinguished Contributor
Posts: 120
Registered: ‎10-09-2003
Message 9 of 21 (73 Views)

Re: Drawing Properties

12-07-2006 05:24 AM in reply to: *CTB
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.
Distinguished Contributor
Posts: 214
Registered: ‎08-16-2006
Message 10 of 21 (73 Views)

Re: Drawing Properties

12-07-2006 06:20 AM in reply to: *CTB
Thanks for the feedback. Which AC version are you using? I've tested it on 2007 - haven't had that error.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community