bcarlso2 Posted February 27, 2017 Posted February 27, 2017 How do I set an attribute value that is within a block to a variable using a lisp statement? I do not want any user input to be used, it needs to be scriptable. There will only be one instance of the block in the drawings. If you need more information, I will gladly give it. Thanks Quote
Tharwat Posted February 27, 2017 Posted February 27, 2017 Welcome to CADTutor. Have a play with the following and you should be able to see the list of attributes in the command line; (defun c:Test ( / s sn e lst) (if (setq s (ssget "_X" '((0 . "INSERT")(66 . 1) (2 . "MyBlock")))) [color="red"];; Change the MyBlock name to your block name[/color] (progn (setq sn (ssname s 0)) [color="red"];; Assumed to run on one block instance / reference.[/color] (while (= "ATTRIB" (cdr (assoc 0 (setq e (entget (setq sn (entnext sn))))))) (setq lst (cons (cdr (assoc 1 e)) lst)) ) ) ) lst [color="red"];; list of attributes values if available.[/color] ) Quote
bcarlso2 Posted February 27, 2017 Author Posted February 27, 2017 I ran your code with my block name inserted. I then type test in the command line and the only thing I get back is nil. I am not sure what I am supposed to do here. Quote
Tharwat Posted February 27, 2017 Posted February 27, 2017 Is you block dynamic or regular? And how did you add your block name into the codes? Quote
Grrr Posted February 27, 2017 Posted February 27, 2017 Another (just for fun) : (defun GetBlkAttVals ( bnm / o L ) (if (and (setq o (FirstBlkOccurrence bnm)) (setq L (vlax-invoke o 'GetAttributes)) ) (mapcar 'vla-get-TextString L) ) ); defun GetBlkAttVals ; recursive (defun FirstBlkOccurrence ( n / rec ) (defun rec ( b n i / o ) (cond ( (vl-catch-all-error-p (setq o (vl-catch-all-apply 'vla-item (list b i)))) (prompt "\nError") ) ( (and (vlax-property-available-p o 'EffectiveName) (= n (vla-get-EffectiveName o))) o) ( (rec b n (1+ i)) ) ); cond ); defun (rec (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))) n 0) ); defun FirstBlkOccurrence ; iterative (defun FirstBlkOccurrence ( n / i->L b o ) (defun i->L ( i / L ) (if (eq 'INT (type i)) (repeat i (setq L (cons (setq i (1- i)) L)))) ) (setq b (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))))) (vl-some (function (lambda (x) (if (and (setq o (vla-item b x)) (vlax-property-available-p o 'EffectiveName) (= n (vla-get-EffectiveName o)) ) o ) ) ) (i->L (vla-get-Count b)) ); vl-some ); defun FirstBlkOccurrence Usage example - (where the blockname is case-sensitive) : (GetBlkAttVals "MyBlockName") Quote
bcarlso2 Posted February 28, 2017 Author Posted February 28, 2017 Is you block dynamic or regular?And how did you add your block name into the codes? My block is static. I inserted my block name like so: (if (setq s (ssget "_X" '((0 . "INSERT")(66 . 1) (2 . "FCA_TB")))) ;; Change the MyBlock name to your block name Quote
Tharwat Posted March 1, 2017 Posted March 1, 2017 Nothing is special in my posted codes above, so if you can upload a sample drawing that would be great to check that out closely. Quote
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.