craigjonnson Posted October 29, 2008 Posted October 29, 2008 I have tried various routes to enable this routine to work but keep bashing my head against a wall, it has to be simple but i'm really having trouble getting this to work. I am trying to read attribute information "REV" from a block called "A1" if this block is found it writes the ctab value as the same value as "REV". Hoorah task done (see lisp below (defun tab). Now i need this lisp to also look for "A0" if "A1" is not found all the values being the same. (defun c:tab () (setvar "cmdecho" 0) ; Switches off command line (setq blk (ssget "x" '((0 . "insert") (2 . "A1")))) (if (null blk) (exit) ) (setq ent (ssname blk 0)) (setq dwg_rev_1 nil) (setq attribute ent) (while (and (setq attribute (entnext attribute)) (/= "SEQEND" (cdr (assoc 0 (entget attribute)))) ) (setq attag (cdr (assoc 2 (entget attribute)))) (if (= "REV" (strcase attag)) (setq dwg_rev_1 (cdr (assoc 1 (entget attribute)))) ) ) (if dwg_rev_1 (progn (princ "\n the REV is ") (princ dwg_rev_1) (terpri) (command "-layout" "r" (getvar "ctab") dwg_rev_1) ) (progn (alert " attribute not found ") (exit)) ) ) (setvar "cmdecho" 1) (c:tab) (princ) I have tried this method which was suggested on the autodesk discussion but i am having an error which appears to be a missing parenthesis but everything checks out in vlide? (defun tab ( / active_document block_exists block_object source_block) (vl-load-com) (setq active_document (vla-get-activedocument (vlax-get-acad-object) ) ) (defun block_exists (block_name) (if (not (vl-catch-all-error-p (setq block_object &nb sp; (vl-catch-all-apply &n bsp; 'vla-item (list &nbs p; (vla-get-blocks active_document) &nb sp; (strcase block_name) &nbs p; ) ) ) ) ) block_object nil ) ) (if (or (setq source_block (block_exists "A1")) (setq source_block (block_exists "A0")) ) (vlax-for item block_object (if (and (= (vla-get-objectname item) "AcDbAttributeDefinition") & nbsp; (= (vla-get-tagstring item) "REV") (/= (vla-get-name (vla-get-activelayout active_document)) "Model") ) (if (not (vl-catch-all-error-p (vl-catch-all-apply &nb sp; 'vla-put-name &n bsp; (list &nbs p; (vla-get-activelayout active_document) ; (vla-get-textstring item) &nbs p; ) &n bsp; ) ) ) T nil ) ) ) nil ) ) ) Where am i going wrong? Quote
wizman Posted October 30, 2008 Posted October 30, 2008 try this, (not tested) (defun c:tab (/ active_document block_exists block_object source_block) (vl-load-com) (setq active_document (vla-get-activedocument (vlax-get-acad-object) ) ;_ end_vla-get-activedocument ) ;_ end_setq (defun block_exists (block_name) (if (not (vl-catch-all-error-p (setq block_object &nb sp ; (vl-catch-all-apply &n bsp ; 'vla-item (list &nbs p ; (vla-get-blocks active_document) &nb sp ; (strcase block_name) &nbs p ; ) ) ;_ end_list ) ;_ end_setq ) ;_ end_vl-catch-all-error-p ) ;_ end_not block_object nil ) ;_ end_if ) ;_ end_defun (if (or (setq source_block (block_exists "A1")) (setq source_block (block_exists "A0")) ) ;_ end_or (vlax-for item block_object (if (and (= (vla-get-objectname item) "AcDbAttributeDefinition") & nbsp ; (= (vla-get-tagstring item) "REV") (/= (vla-get-name (vla-get-activelayout active_document)) "Model") ) ;_ end_and (if (not (vl-catch-all-error-p (vl-catch-all-apply &nb sp ; 'vla-put-name &n bsp ; (list &nbs p ; (vla-get-activelayout active_document) ; (vla-get-textstring item) &nbs p ; ) &n bsp ; ) ) ;_ end_vl-catch-all-apply ) ;_ end_vl-catch-all-error-p T nil ) ;_ end_not ) ;_ end_if ) ;_ end_if nil ) ;_ end_vlax-for ) ;_ end_if ) ;_ end_defun Quote
BIGAL Posted October 30, 2008 Posted October 30, 2008 Just a suggestion after years of lisp I now write all my block stuff in VBA much easier. Once you find a block you getattributes but basicly you dont need tag names etc its just att(0) att(1) att(2) etc these are the values attribs(0).TextString = "ISSUED FOR CONSTRUCTION" attribs(3).TextString = "0" attribs(0).Update attribs(3).Update as it says this updates all layout tabs in one go to issued another routine finds one individual block from hundreds in drawing and changes attributes based on another block/text pick to find keyword Look on forum here lots of stuff about attribute updating. Quote
craigjonnson Posted October 30, 2008 Author Posted October 30, 2008 Thanks for your suggestion guys, the lisp routine has a syntax error. i have checked the code over and over in vlide, i think i need to have a break to clear my head until i get back to this. Quote
wizman Posted October 30, 2008 Posted October 30, 2008 one more time....'-) (defun c:tab () (setvar "cmdecho" 0) ; Switches off command line (if (or (setq blk (ssget "x" (list '(0 . "insert") '(2 . "A1") (cons 410 (getvar 'ctab))))) (setq blk (ssget "x" (list '(0 . "insert") '(2 . "A0") (cons 410 (getvar 'ctab))))) ) ;_ end_or (progn (setq ent (ssname blk 0)) (setq dwg_rev_1 nil) (setq attribute ent) (while (and (setq attribute (entnext attribute)) (/= "SEQEND" (cdr (assoc 0 (entget attribute)))) ) ;_ end_and (setq attag (cdr (assoc 2 (entget attribute)))) (if (= "REV" (strcase attag)) (setq dwg_rev_1 (cdr (assoc 1 (entget attribute)))) ) ;_ end_if ) ;_ end_while (if dwg_rev_1 (progn (princ "\n the REV is ") (princ dwg_rev_1) (terpri) (command "-layout" "r" (getvar "ctab") dwg_rev_1) ) ;_ end_progn (progn (alert " attribute not found ") (exit)) ) ;_ end_if ) ;_ end_progn (if (null blk) (exit) ) ;_ end_if ) ;_ end_if ) ;_ end_defun (setvar "cmdecho" 1) (c:tab) (princ) Quote
craigjonnson Posted October 31, 2008 Author Posted October 31, 2008 Thank you, It all now seems very clear, ha ha The expression "Couldnt see the wood for the tree's". Craig 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.