PDA

View Full Version : Selecting items by a registered application


rklee
2008-07-24, 08:08 PM
Is there a way to select blocks that have xdata attached with the registered program "b_number". I used the (regapp "b_number") prior to attaching the xdata, and gave the blocks a standard name. Some users have changed the block name and I am working on a program that checks an attribute tag "eq_number" and if the block name is different, then change the block name to match the equipment number.

Lions60
2008-07-24, 09:19 PM
This might do the trick i haven't tested it though.


(defun c:app ()
(setq blocks (ssget "X" '((0 . "INSERT"))))
(setq blocknum (sslength blocks))
(setq counter 0)
(repeat blocknum
(progn
(setq ename (ssname blocks counter))
(if(setq elist (entget ename '("b_number")))
(progn
;; Do your coding here if the block has an appid of b_number
(entmod elist)
);; end of progn
(progn
;; Do your coding here if the block doesn't have that appid
);; end of progn
);; end of if
(setq counter (1+ counter))
);; end of progn
);; end of repeat
);; end of program


I just found this so you could also use the below code


(defun c:app ()
(if(setq blocks(ssget "X" '((0 . "INSERT") (-3 ("b_number"))))) ;; selects all blocks with the appname b_number
(progn
(setq blocknum (sslength blocks))
(setq counter 0)
(repeat blocknum
(progn
(setq ename (ssname blocks counter))
(if(setq elist (entget ename))
(progn
;; Do your coding here if the block has an appid of b_number
(entmod elist)
);; end of progn
(progn
;; Do your coding here if the block doesn't have that appid
);; end of progn
);; end of if
(setq counter (1+ counter))
);; end of progn
);; end of repeat
);; end of progn
);; end of if
);; end of program

rklee
2008-07-24, 09:56 PM
Thank you, I got the first one to work, but the second one not yet. Now I am trying to do a macth on two strings and if they do not match, then list the block and attribute. I appreciate your help, I think I am getting lost in the parentheses.

Lions60
2008-07-24, 11:17 PM
Your very welcome and yes it is very easy to get lost in the parenthesis when your code gets long.

~ Good luck ~