I am trying to write a lisp routine that will open the dwgprops box
and fill in new information automaticly. No having used lisp for a while
I need to know how to program the alt key to pick the add file in the box.
Any help would be appreciated.
|
I am trying to write a lisp routine that will open the dwgprops box
and fill in new information automaticly. No having used lisp for a while
I need to know how to program the alt key to pick the add file in the box.
Any help would be appreciated.
Are you trying to add information under the Custom tab? If so I have a lisp that will do this, and if your running 2006 I have a cool c# version
Dan
Dan
that is exactly what I am looking for. I would appreciate it if I could get that inforfmation.
Ralph
Ralph
Here is a little routine that imports / exports custom properties to and from a .CSV files
the comands are impdwp , expdwp and clrdwp. The last one will clear the custom properties.
inside the code you can see the properties and methods.
Tested with 2005 and 2006
enjoy
Just to let you know, .CSV files have problems if your properties contain commas, (ex. January, 2006)Originally Posted by dmarcotte4
to fix this problem possibly use .XLS files instead and change all , additions to t, it works just as well and you can then use commas in your properties. I could post the adjusted file if you dont mind, or I could just keep it to myself
yes, that sure is a problem with delimited files… you can’t use the delimiter character .
I would love to see what you have done with the code.
thanks
Daniel
Here it is, I highlighted everything I modified in red, the goal was to save the file to a tab delimited file instead of a comma delimited file, and also to always default open to the folder that the current drawing is from (I have not fully tested this ability to see if it always works, although it appears that way.) The changes were relatively simple, in notepad I just found and replaced all CSV references with XLS and then found where it added commas and took them out and replace those with t for tabs.Originally Posted by dmarcotte4
If you need to edit the XLS file externally, use notepad, if you use Excel, it will add extra quoatation marks around some of the items.
the code didn't come in right, so I attached it, please do NOT use the below code
Code:(defun c:expdwp () (GetallCustomDwgProp) ) (defun c:impdwp () (ImportallCustomDwgProp) ) (defun c:clrdwp () (ClearCustomDwgProp) ) (defun ClearCustomDwgProp (/ app cnt cnt1 cnt2 doc dwgprops result) (vl-load-com) (setq result (dwpMsgbox "Warning" "Your are about to erase data do you with to contunue?" vlax-vbOKCancel vlax-vbExclamation ) ) (if (= result 1) (progn (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) cnt1 0 cnt2 (vla-NumCustomInfo DwgProps) ) (repeat cnt2 (vla-RemoveCustomByIndex DwgProps cnt1) ) (dwpMsgbox "Done" (strcat "Removed " (itoa cnt2) " Items from Custom Properties" ) vlax-vbOKOnly vlax-vbInformation ) ) (dwpMsgbox "Cancel" "Operation Canceled" vlax-vbOKOnly vlax-vbInformation ) ) (princ) ) (defun GetallCustomDwgProp (/ app counter counter2 doc dwgprops FN dname fh s1 s2) (vl-load-com) (setq dname (GETVAR "DWGPREFIX")) (setq FN (getfiled "Select a File" dname "XLS" 1)) (if FN (progn (setq FH (open FN "w")) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) counter 0 counter2 (vla-NumCustomInfo DwgProps) ) (repeat counter2 (vla-GetCustomByIndex DwgProps counter 's1 's2) (setq counter (+ 1 counter)) (princ (strcat s1 "t" s2 "n") FH) ) (close FH) (dwpMsgbox "Done" (strcat "Exported " (itoa counter2) " Items to " (vl-filename-base FN) (vl-filename-extension FN) ) vlax-vbOKOnly vlax-vbInformation ) ) ) (princ) ) (defun getCustomDwgProp (key / app doc dwgprops try val) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (cond ((vl-catch-all-error-p (setq try (vl-catch-all-apply 'vla-GetCustomByKey (list DwgProps key 'val) ) ) ) (setq val nil) ) ) val ) (defun SetCustomDwgProp (key value / App Doc DwgProps) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (if (getCustomDwgProp key) (vla-SetCustomByKey DwgProps key value) (vla-AddCustomInfo DwgProps key value) ) ) (defun ImportallCustomDwgProp (/ a b fh fn l dname txtline) (setq dname (GETVAR "DWGPREFIX")) (setq FN (getfiled "Select a XLS File" dname "XLS" 0)) (if FN (progn (setq FH (open FN "r")) (while (setq txtLine (read-line FH)) (setq l (strparse (strcat txtLine "") "t") a (car l) b (cadr l) ) (if (= b nil) (setq b " ") ) (SetCustomDwgProp a b) ) (close fh) (dwpMsgbox "Done" (strcat "Imported Items from " (vl-filename-base FN) (vl-filename-extension FN) ) vlax-vbOKOnly vlax-vbInformation ) ) ) (princ) ) (defun strparse (strng chs / len c l s chsl cnt) (setq chsl (strtol chs)) (setq len (strlen strng) s "" cnt (1+ len) ) (while (> (setq cnt (1- cnt)) 0 ) (setq c (substr strng cnt 1)) (if (member c chsl) (if (/= cnt len) (setq l (cons s l) s "" ) ) (setq s (strcat c s)) ) ) (cons s l) ) (defun strtol (s / lst c) (repeat (setq c (strlen s)) (Setq lst (cons (substr s c 1) lst) c (1- c) ) ) lst ) (defun dwpMsgBox (Title Message MsgBoxType Icon / acadobject iicon imsgboxtype oldvar result strmessage strtitle ) (vl-load-com) (setq oldvar (getvar "USERI1")) (setvar "USERI1" 0) (setq acadobject (vlax-get-Acad-Object) strTitle title strMessage Message iIcon Icon iMsgBoxType MsgBoxType ) (vla-eval acadobject (strcat "ThisDrawing.SetVariable "USERI1", " "MsgBox ("" strMessage ""," (itoa (+ iIcon iMsgBoxType)) ","" strTitle "")" ) ) (setq result (GETVAR "USERI1")) (SETVAR "USERI1" oldvar) result )
Last edited by ccowgill; 2006-02-02 at 11:39 AM. Reason: code did not come in correctly
Actually, you can... but it requires another special character.Originally Posted by dmarcotte4
Most programs that use .csv files will also parse double-quotes as special characters. Items can be included in double-quotes. If you want to use an actual double-quote character, you should use two successive double-quotes, and place the overall field in double-quotes. An example, containing four items:That line in a CSV file equates to the following four items:Code:"January 1, 2006", "A ""quoted"" word",a third item,"""four"""The problem is that not every program parses .csv files the way it should. Yet another argument for a software standards body.Code:January 1, 2006 A "quoted" word a third item "four"
Last edited by sinc; 2006-02-07 at 11:57 PM. Reason: Clarify example