Xyzzy Posted January 16, 2022 Share Posted January 16, 2022 Hello, I need a function that determines the number and values of block attributes in Autolisp. I have no idea how to write this, can you help me? Quote Link to comment Share on other sites More sharing options...
mhupp Posted January 16, 2022 Share Posted January 16, 2022 In express tools their is a command attout select the blocks you want to export the attributes of. it wil create a txt file. just drag and drop that file in an open excel. it will have every attribute for you to edit/update. once done save the file and use command attin Quote Link to comment Share on other sites More sharing options...
Xyzzy Posted January 16, 2022 Author Share Posted January 16, 2022 @mhupp I meant that I need to write a program, for example, to replace blocks with one name with blocks with a different name: (defun c:proj4() (setq str (getstring "block' name:")) (setq zb (ssget "X" (list(cons 2 str)))) (setq lzb (sslength zb)) (setq nw (getstring "new block' name:")) (setq i 0) (while (< i lzb) (setq stri (ssname zb i)) (setq dstri (entget stri)) (setq dstri (subst (cons 2 nw) (assoc 2 dstri) dstri) ) (entmod dstri) (setq i (1+ i)) ) ) Quote Link to comment Share on other sites More sharing options...
Xyzzy Posted January 16, 2022 Author Share Posted January 16, 2022 @mhupp I meant that I need to write a program, for example, to replace blocks with one name with blocks with a different name: (defun c:proj4 (setq str (getstring "block' name:") (setq zb (ssget "X" (list(cons 2 str))) (setq lzb (sslength zb) (setq nw (getstring "new block' name:") (setq i 0 (while (< i lzb (setq stri (ssname zb i) (setq dstri (entget stri) (setq dstr (subst (cons 2 nw (assoc 2 dstri dstri (entmod dstri (setq i (1+ i) ))))))))i))))))))() Quote Link to comment Share on other sites More sharing options...
mhupp Posted January 16, 2022 Share Posted January 16, 2022 What is it that you want to do? Quote Link to comment Share on other sites More sharing options...
Xyzzy Posted January 16, 2022 Author Share Posted January 16, 2022 @mhupp I need to write a script in Autolisp, which determines the number and values of block attributes in Autolisp. I think that it ,,enter the number of arguments" ,,enter the value of the attribute one" etc. Quote Link to comment Share on other sites More sharing options...
mhupp Posted January 16, 2022 Share Posted January 16, 2022 this sould get you started. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-block-definition-attributes/td-p/7968755 Quote Link to comment Share on other sites More sharing options...
Xyzzy Posted January 17, 2022 Author Share Posted January 17, 2022 (edited) @mhupp So for now, I have this: 1. Count attributes(defun c:Test (/ s ss) (if (and (princ "\n Select FIRST Attributed Block :") (setq s (ssget "_+.:S:E" '((0 . "INSERT") (66 . 1)))) (princ "\n Select the SECOND Attributed Block :") (setq ss (ssget "_+.:S:E" '((0 . "INSERT") (66 . 1)))) ) (mapcar 'length (mapcar '(lambda (a) (mapcar '(lambda (x) (vla-get-textstring x)) (vlax-invoke (vlax-ename->vla-object a) 'getattributes) ) ) (list (ssname s 0) (ssname ss 0)) ) ) ) ) 2. Retrieve values of attributes (defun c:Test (/ ss n e x) (while (progn (princ "\n Select single attributed block :") (setq ss (ssget "_+.:S" '((0 . "INSERT") (66 . 1)))) ) (setq n (entnext (ssname ss 0))) (while (not (eq (cdr (assoc 0 (setq e (entget n)))) "SEQEND" )) (if (eq (cdr (assoc 0 e)) "ATTRIB") (print (cdr (assoc 1 e))) ) (setq n (entnext n)) ) ) (princ) ) How can i combine them? Edited January 17, 2022 by Xyzzy Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 17, 2022 Share Posted January 17, 2022 Different method but your on right path when you (vlax-invoke (vlax-ename->vla-object a) 'getattributes) it does just that in creation order. You can get each attribute and look at "Textstring" which is attribute value, you can also get how many attributes so if updating block 2 can control which attributes get updated. So lets start again (setq blk (vlax-ename->vla-object (car (entsel "\nPick block ")))) (setq atts (vlax-invoke blk 'getattributes)) (princ (strcat "how many " (rtos (length atts) 2 0) "\n")) (setq lst '()) (foreach att atts (princ (strcat "\n" (vla-get-textstring att))) (setq lst (cons (vla-get-textstring att) lst)) ) (setq lst (reverse lst)) (setq blk2 (vlax-ename->vla-object (car (entsel "\nPick block2 ")))) (setq x 0) (setq atts2 (vlax-invoke blk2 'getattributes)) (foreach att2 atts2 (vla-put-textstring att2 (nth x lst)) (setq x (1+ x)) ) No error checks does block 2 have same or more attributes, uses creation order. ps (vlax-property-available-p blk "hasattributes") Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.