andy_gs_99 Posted August 31, 2009 Posted August 31, 2009 Hello guys, I have template which has several attribute values. I need to update one of the value. I am finding difficult to extract that particular value Block name is "bplog" & tag is "weight". can some one help me how to extract this and update the value with user input Thanks in advance. Quote
Lee Mac Posted August 31, 2009 Posted August 31, 2009 You can get at the block objects using something like: (ssget "_X" '((0 . "INSERT") (2 . "BPLOG") (66 . 1))) And you can then either use Visual LISP to edit the attributes: (foreach att (vlax-invoke <Block Object> 'GetAttributes) (if (eq "WEIGHT" (vla-get-TagString att)) (vla-put-TextString att ... Or maybe though AutoLISP: (while (/= "SEQEND" (cdr (assoc 0 (entget (setq ent (entnext <Block Entity>)))))) (if (eq "WEIGHT" (cdr (assoc 2 (entget ent)))) (entmod (subst (cons 1 <New Text>) (assoc 1 (entget ent)) (entget ent)))))) ... Lee Quote
andy_gs_99 Posted August 31, 2009 Author Posted August 31, 2009 Thanks for the reply, but it's not working, can you explain in detail Quote
flowerrobot Posted September 1, 2009 Posted September 1, 2009 bascily what lee has shown you. But a bit more generic I use to get attibute data, Passing the selction with what number item you want. will return all attribute in a format of "attibute name" "attibute value" (defun attget (ss1 count / edata blockdata) (setq edata (entget (entnext (cdr (assoc -1 (entget (ssname ss1 count))))))) (while (not(= (cdr (assoc 0 edata)) "SEQEND")) (setq blockdata (cons (cons (cdr (assoc 2 edata)) (cdr (assoc 1 edata))) blockdata) edata (entget (entnext (cdr (assoc -1 edata))))) ) blockdata ) Passing the selction with what number item you want & all the attributes in the same format given (update the list using subst) (defun attput (ss1 count blockdata / edata) (setq edata (entget (entnext (cdr (assoc -1 (entget (ssname ss1 count))))))) (while (not(= (cdr (assoc 0 edata)) "SEQEND")) (entmod (subst (cons 1 (cdr (assoc (cdr (assoc 2 edata)) blockdata)))(assoc 1 edata) edata)) (setq edata (entget (entnext (cdr (assoc -1 edata))))) ) ) Quote
Lee Mac Posted September 1, 2009 Posted September 1, 2009 Thanks for the reply, but it's not working, can you explain in detail I have just shown you the way to approach the problem - you will need to modify my code somewhat and include the variables containing either you block entity or VLA-object. Quote
VVA Posted September 1, 2009 Posted September 1, 2009 Hello guys, can some one help me how to extract this and update the value with user input Try this example (command TEST) (defun C:TEST () (vl-load-com) (setq blockname "BPLOG") (setq tagname "WEIGHT") (setq new_user_attrib_data (getstring t "\nEnter new weight value: ")) (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blockname) '(66 . 1)) ) ;_ end of ssget ) ;_ end of setq (mapcar '(lambda (block) (mip-block-setattr-bylist block (list (cons (strcase tagname) new_user_attrib_data)) ) ;_ end of mip-block-setattr-bylist ) ;_ end of lambda (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex ss)) ) ;_ end of vl-remove-if ) ;_ end of mapcar ) ;_ end of if ) ;_ end of defun ;; ATTRIBUTE (defun mip-block-setattr-bylist (obj att_list / txt lst) ;; obj - Ename or Vla object of block ;; att_list - list ((Tag_Name1 . Value1)(Tag_Name2 . Value2) ...) ;; Tag_Name - string ;; Value - string ;; Use (Block have attribute tag name WEIGHT) ;;; (mip-block-setattr-bylist ;;; (car (entsel "\nSelect block:")) ;;; (list (cons "WEIGHT" 44)) ;;; ) (if (= (type obj) 'ENAME) (setq obj (vlax-ename->vla-object obj)) ) ;_ end of if (setq att_list (mapcar '(lambda (x) (cons (strcase (mip-conv-to-str (car x))) (mip-conv-to-str (cdr x)) ) ;_ end of cons ) ;_ end of lambda att_list ) ;_ end of mapcar ) ;_ end of setq (if (and obj (not (vlax-erased-p obj)) (= (vla-get-objectname obj) "AcDbBlockReference") (eq :vlax-true (vla-get-hasattributes obj)) (vlax-property-available-p obj 'Hasattributes) (vlax-write-enabled-p obj) ) ;_ end of and (vl-catch-all-apply (function (lambda () (foreach at (vlax-invoke obj 'Getattributes) (if (setq lst (assoc (strcase (vla-get-tagstring at)) att_list) ) ;_ end of setq (vla-put-textstring at (mip-string-subst " " "\n" (cdr lst)) ) ;_ end of vla-put-TextString ) ;_ end of if ) ;_ end of foreach ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of if ) ;_ end of defun (defun mip-conv-to-str (dat) (cond ((= (type dat) 'INT)(setq dat (itoa dat))) ((= (type dat) 'REAL)(setq dat (rtos dat 2 12))) ((null dat)(setq dat "")) (t (setq dat (vl-princ-to-string dat))))) ;;; String replace (defun mip-string-subst (newchar curchar str) (while (vl-string-search curchar str) (setq str (vl-string-subst newchar curchar str)) ) str ) Quote
Lee Mac Posted September 1, 2009 Posted September 1, 2009 Another: (defun attupd (bNme Tag Val / ss sel lst t1) (vl-load-com) (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 bNme) '(66 . 1)))) (progn (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))) (setq lst (vlax-invoke Obj 'GetAttributes)) (while (progn (setq t1 (car lst)) (cond ((eq (strcase (vla-get-TagString t1)) tag) (vla-put-TextString t1 Val) nil) ((setq lst (cdr lst))) (t nil))))) (vla-delete sel)))) (defun c:test (/ blk tag val) (if (and (setq blk (getstring t "\nSpecify Block Name: ")) (setq tag (getstring "\nSpecify Attribute Tag: ")) (setq val (getstring t "\nSpecify New Attribute Value: "))) (attupd blk tag val)) (princ)) Quote
andy_gs_99 Posted September 16, 2009 Author Posted September 16, 2009 Thanks for your time VVA , works great 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.