h0okem Posted November 18, 2011 Share Posted November 18, 2011 (edited) I have a routine that replaces one block with another block based on the block name. I need help making it run only if a specific string of text is found in one of the attributes within the found block. Can someone help? Thanks. (defun c:name () (setvar "attreq" 0) (setq ssblocks (ssget "x" '((0 . "INSERT")))) (if ssblocks (progn (setq lstblockmap (txtfile2lst "C:\\path\\filename.txt" ) ) (setq lstblocks (sel2lst ssblocks)) (foreach enblock lstblocks (setq strblockname (car (getval (setq stroldname (strcase (getval 2 enblock))) lstblockmap ) ) ) (if strblockname (progn (prompt (strcat "****** " strblockname " found.******")) (progn ;;;;;Do more code ) ) (progn (prompt "No block definition, Skipping...") ) ) ) ) ) ) Edited November 19, 2011 by h0okem Quote Link to comment Share on other sites More sharing options...
LibertyOne Posted November 19, 2011 Share Posted November 19, 2011 We were all instructed that you have to read this before we help you... http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines Quote Link to comment Share on other sites More sharing options...
pBe Posted November 19, 2011 Share Posted November 19, 2011 (if (member str (result of your attb string retrieval sub)) (do your thing) (msg) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 19, 2011 Share Posted November 19, 2011 My version ... (defun c:TesT (/ blks b found st i sn n e) ;;; Tharwat 19. Nov. 2011 ;;; (if (and (setq blks (ssget "_x" '((0 . "INSERT") (66 . 1)))) (setq b (getstring t "\n Enter Name of Block to be replaced :")) (setq found (tblsearch "BLOCK" b)) (setq st (getstring t "\n Enter Attribute string :")) ) (repeat (setq i (sslength blks)) (setq sn (ssname blks (setq i (1- i)))) (setq n (entnext sn)) (while (not (eq (cdr (assoc 0 (setq e (entget n)))) "SEQEND" ) ) (if (and (eq (cdr (assoc 0 e)) "ATTRIB") (eq (cdr (assoc 1 e)) st) ) (progn (entmakex (list '(0 . "INSERT") (assoc 10 (entget sn)) (cons 2 b) '(41 . 1.) '(42 . 1.) '(43 . 1.) ) ) (entdel sn) ) ) (setq n (entnext n)) ) ) (cond ( (not blks) (princ "\n You do not have Attributed Blocks in this drawing !!" ) ) ( (not found) (princ "\n Name of block is not found in this drawing !!") ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
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.