leonucadomi Posted July 12, 2023 Posted July 12, 2023 hello: I have a code that extracts the data from a block with attributes. but you have to select the block with click. knowing that the block is called "block1 or block2" always I want to ask for your help to modify the code and not have to select anything with click. if not do it automatically. thanks here the code... (defun LM:vl-getattributevalue ( blk tag );LEE MAC (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) (defun c:pru () (while (setq obj_block (vlax-ename->vla-object (car (entsel "\nSelecciona bloque: ")))) (setq dato2 (LM:vl-getattributevalue obj_block "DATO2")) (princ dato2) ) ) Quote
leonucadomi Posted July 12, 2023 Author Posted July 12, 2023 I think this routine can help me but I don't know how to use it, does anyone know? ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:vl-getattributevalue ( blk tag ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) Quote
mhupp Posted July 12, 2023 Posted July 12, 2023 Even simpler Yet. but only works with newer versions of AutoCAD. also setpropertyvalue! (defun c:pru (/) (while (setq blk (car (entsel "\nSelecciona bloque: "))) (princ (getpropertyvalue blk "DATO2")) ) ) 1 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.