Visual LISP, AutoLISP and General Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi guys. I wonder if you can help me. There is a BLOCKA that I'd like to extract its attributes - Tag and Color - into an external format (excel). There after, I'd like to import it into the drawing and based on its color attribute value, change the value to that color in the drawing.
Any hints/suggestions would be appreciated.
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I think easier yet to read / write data to CSV file
You may want to use something like that
;;________________________ Write to file ___________________________;;
;;write attributes to CSV file
(defun c:bf(/ file lst)
;;list to file
(defun wrs (file lst / filename atts blockname en obj ss)
(setq filename (open file "W"))
(foreach x lst
(write-line (lst2str x "\t") filename)
)
(close filename)
(princ)
)
(defun lst2str (lst sep)
(if (cadr lst)
(strcat (vl-princ-to-string (car lst))
sep
(lst2str (cdr lst) sep)
)
(vl-princ-to-string (car lst))
)
)
(setq file "C:\\Test\\attributes.csv");<-- change file name
(setq blockname "BLOCKA");<-- change block name
(setq lst nil)
(if (setq ss (ssget "X" (list (cons 2 (strcat "`*U*," blockname))(cons 66 1))))
(progn
(while (setq en (ssname ss 0))
(progn
(setq obj (vlax-ename->vla-object en))
(if (eq blockname (vla-get-effectivename obj))
(progn
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes obj))))
(foreach att atts
(setq lst (cons (list (vla-get-tagstring att) (itoa (vla-get-colorindex (vla-get-truecolor att)))) lst))
)
)
)
)
(ssdel en ss)
)
)
)
(wrs file lst)
(princ)
)
;;______________________ Read from file _______________________;;
;;Read data from CSV file
(defun C:af(/ data file pos result x)
(defun file-to-list (filename / file result line)
(if (findfile filename)
(progn (setq file (open filename "r"))
(while (setq line (read-line file))
(setq result (cons line result))
)
(close file)
(reverse result)
)
(alert (strcat "File " filename " not found!"))
)
)
(defun split (txt sep)
(if (not (eq sep txt))
(if (setq pos (vl-string-search sep txt 0))
(cons (substr txt 1 pos)
(split (substr txt (+ pos 1 (strlen sep))) sep))
(list txt)) )
)
(setq file "C:\\Test\\attributes.csv")
(setq data (file-to-list file))
(setq result (mapcar '(lambda(x)(split x "\t")) data))
(print result)
(alert "Do whatever you need with attribute info here")
(princ)
)
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thank you very much, Hallex! I'm sorry about the delay response, but I was out all day yesterday. I tested the routine. It exported fine into csv format. However, when I opened it up using excel, it give me a weird ? in between the tag info and the color info. When I opened it using notepad, it shows up fine.
This is what it gives me when I ran the routine. I changed the number/color 7 to 5 to see if it will update the attribute property so that it's now blue, instead of white, but how do I incorporate this code? Thanks.
(("TAG" "7"))
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
kameron1967 wrote:....when I opened it up using excel, it give me a weird ? in between the tag info and the color info. When I opened it using notepad, it shows up fine...
Use comma "," instead of tab "\t"
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
kameron1967 wrote:
This is what it gives me when I ran the routine. I changed the number/color 7 to 5 to see if it will update the attribute property so that it's now blue, instead of white, but how do I incorporate this code? Thanks.
(("TAG" "7"))
(defun subkameron (lst bn / a b)
(vlax-for ent (vla-item (vla-get-blocks (vla-get-ActiveDocument
(vlax-get-acad-object))) bn)
(if (and (eq (vla-get-ObjectName ent)
"AcDbAttributeDefinition")
(setq b (assoc (vla-get-TagString ent) lst)))
(vla-put-color ent (atoi (cadr b)))))
(command "_attsync" "Name" bn)
)(subkameron result "BLOCKA")
HTH
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks, Pbejse! Wow - I feel so honored to have the routine named after me! ![]()
I had a chance to incorporate your portion of the routine and put the last line at the end of Hallex's routine. It ran successfully! I had to update the way it writes to the csv file "," and the way it reads per your suggestion. I initially only modified the read portion, but after changing the write portion, it worked great! Thank you for your finishing touch, Pbejse - and thank you Hallex for the awesome routine! Kudos to you both!! ![]()
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Glad to help
Cheers ![]()
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Export/Imp ort attribute values and its color.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
kameron1967 wrote:Thanks, Pbejse! Wow - I feel so honored to have the routine named after me!
You like that huh? ![]()
kameron1967 wrote:
Thank you for your finishing touch, Pbejse - and thank you Hallex for the awesome routine! Kudos to you both!!
You are wellcome
Good for you kameron.. It's all Hailex really...
Cheers
