tnvsb Posted October 3, 2018 Posted October 3, 2018 Dear Helpers, I got a lisp code that will update all attributes of single selected block to uppercase. But the lisp code I need is, it should update only single attribute to upper or lowercase for selected block. The code I have is below. It should work for multiple blocks. (defun c:AUC ( / ent enx ) (if (and (setq ent (car (entsel))) (= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) (= 1 (cdr (assoc 66 enx))) (setq ent (entnext ent) enx (entget ent) ) ) (while (= "ATTRIB" (cdr (assoc 0 enx))) (entmod (subst (cons 1 (strcase (cdr (assoc 1 enx)))) (assoc 1 enx) enx)) (setq ent (entnext ent) enx (entget ent) ) ) (princ "\nNo object selected or selected object is not a block.") ) (princ) ) Thanks, T.Brahmanandam Quote
Grrr Posted October 3, 2018 Posted October 3, 2018 (defun C:test ( / *error* enx attag o bnm SS i ) (defun *error* ( m ) '(87 114 105 116 116 101 110 32 98 121 32 71 114 114 114) (and m (not (member m '("Function cancelled" "quit / exit abort"))) (princ m)) (princ) ); defun *error* (and (setq enx ( (lambda (args f) (setvar 'errno 0) (apply (function f) (append (mapcar 'eval args) '(nil nil)))) '(nentsel "\nPick an attribute <exit>: " "ATTRIB") (lambda (sel msg typ e enx) (cond ( (= 52 (getvar 'errno)) nil) ( (= 7 (getvar 'errno)) (princ "\nMissed") (setvar 'errno 0) (f sel msg typ nil nil) ) ( (not e) (f sel msg typ (car (sel msg)) nil) ) ( (not enx) (f sel msg typ e (entget e)) ) ( (not (= typ (cdr (assoc 0 enx)))) (princ (strcat "\nInvalid object, select \"" typ "\".")) (f sel msg typ (car (sel msg)) nil) ) ( enx ) ); cond ); lambda ) ); setq enx (setq attag (cdr (assoc 2 enx))) (setq o (vlax-ename->vla-object (cdr (assoc 330 enx)))) (setq bnm (vla-get-EffectiveName o)) (progn (initget "Uppercase Lowercase Exit") (setq b (eval (cdr (assoc (cond ((getkword "\nChoose [Uppercase/Lowercase/Exit] <Uppercase>: ")) ("Exit")) '( ("Uppercase") ("Lowercase" . t) ("Exit" exit) ) ) ) ) ) t ); progn (setq SS (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`**," bnm)) '(66 . 1) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (repeat (setq i (sslength SS)) (and (eq bnm (vla-get-EffectiveName (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i))))))) (vl-some (function (lambda (x) (if (= attag (vlax-get x 'TagString)) ( (lambda (v) (vlax-put x 'TextString v) t) (strcase (vlax-get x 'TextString) b) ) ); if ); lambda ); function (vlax-invoke o 'GetAttributes) ); vl-some ); and ); repeat ); and (princ) ); defun C:test (vl-load-com) (princ) Quote
tnvsb Posted October 3, 2018 Author Posted October 3, 2018 Thank you So much Sir for spot replay with smart answer. Quote
BIGAL Posted October 3, 2018 Posted October 3, 2018 (edited) Just in case you missed it or for others the secret in Grr's code is the nentsel not entsel this allows you to pick an attribute individually v's the complete block. Nentsel allows selecting an item within like here a block with attributes. Also maybe a little bit quicker is (strcase "sample" T) if you use T then its lower case so maybe a simple just display text and accept yes or no will swap case. (defun c:test ( / obj att ans) (setq obj (vlax-ename->vla-object (car(nentsel "Pick a block attribute")))) (if (= (vla-get-objectname obj) "AcDbAttribute") (progn (setq att (vla-get-textstring obj)) (setq att (strcase att)) (vla-put-textstring obj att) (setq ans (getstring "Press any key to make lowercase <Enter> to keep")) (if (= (strlen ans) 0) (princ) (vla-put-textstring obj (strcase att T)) ) ) (progn (Alert "Object picked was not an attribute") (exit) ) ) ) Edited October 3, 2018 by BIGAL Quote
BIGAL Posted October 3, 2018 Posted October 3, 2018 Grr inspired me to have a go. Just shows lots of ways to do it. Quote
pBe Posted October 3, 2018 Posted October 3, 2018 8 hours ago, Grrr said: (defun C:test ( / *error* enx attag o bnm SS i ) ..... '(nentsel "\nPick an attribute <exit>: " "ATTRIB") ); progn (setq SS (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`**," bnm)) '(66 . 1) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) ... ); defun C:test (vl-load-com) (princ) This is exactly what I had I mind [ on a different forum < one of MANY this request were posted > ] No wonder I didn't get a reply. Quote
BIGAL Posted October 3, 2018 Posted October 3, 2018 I found the multi post as well. Left a link to here on one of them. 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.