p7q Posted 10 hours ago Posted 10 hours ago (edited) Hi everyone, I’m trying to get the text from an Attribute Definition (ATTDEF) inside a dynamic block using AutoLISP, and then change that text. Unfortunately, I haven’t been able to make it work. Here is what I tried: (defun getblockentities (blk / ent enx rtn) (if (setq ent (tblobjname "block" blk)) (while (setq ent (entnext ent)) (setq enx (entget ent)) (if (= "INSERT" (cdr (assoc 0 enx))) (getblockentities (cdr (assoc 2 enx))) (progn (setq text (vlax-ename->vla-object ent)) (if (car text) (setq tlist (append tlist (list text))) ) ) ) ) ) ) And then I tried to collect attributes like this: (setq attlist (vlax-invoke textObj 'GetAttributes)) (foreach att attlist (if (not (eq (vla-get-tagstring att) nil)) (progn (setq text (vla-get-tagstring att)) (setq tlist (append tlist (list text))) ) ) ) But with this approach I couldn’t retrieve the attribute text. Is there another method to get (and later modify) the text string of an attribute inside a dynamic block? Thanks in advance for any guidance. edit: ı'm adding to dwg for trydinamic block text.dwg Edited 7 hours ago by p7q Quote
Saxlle Posted 5 hours ago Posted 5 hours ago Hi @p7q, You can try with this several options from image below. From the last lines of code, you will get something like this. Try to play with this. Also, you can get from Lee Mac website about Attribute Functions. Best regards. Quote
mhupp Posted 1 hour ago Posted 1 hour ago try using nentsel (nested entity select) Tho you will have to select the attribute itself and not just the block. might want to add some error handling like check for attribute or text. then after you edit will have to regen to update the drawing. (defun c:foo () (while (setq sel (nentsel "\nSelect Block Attribute : ") (setq ename (car sel)) ;check if sel is attribute (setq edata (entget ename)) (setq tag (cdr (assoc 2 edata))) ; Attribute tag (setq val (cdr (assoc 1 edata))) ; Attribute value (princ (strcat "\nTag: " tag ", Value: " val)) ) (princ) ) 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.