PDA

View Full Version : Lisp to select attributes within a block


jsowinski
2006-08-08, 08:00 PM
Hi Everyone-

I'm writing a lisp routine that will modify the justification and size of the text that represents an attribute within a block. I'm having problems writing the code that will find the data in the attribute text. (i.e. Layer name, (0 . "ATTDEF"), etc.) I have the information that will modify the text, but I just can't seem to find the sub entities of a block. I appreciate any help. Thanks.

-jsowinski

intergrupocr
2006-08-08, 08:06 PM
You have to check (nentsel), nested entity select and (entnext). Maybe if you give us more information we can help.!

T.Willey
2006-08-08, 09:36 PM
Use (nentsel..... ) if you want to select one at a time, and if you want to change them all, then use an (ssget ... ) to the get insert, and then step through the sub-entities with (entnext .. ) until you get to an entity whose 0 code is "SEQEND".

Just what "intergrupocr" said, with a little more explanation.

jsowinski
2006-08-09, 03:14 PM
I understand the use of nentsel, but could you please illustrate a little the use of (ssget) and (entnext). I'm not sure how to use entnext to search for sub entities in a block. My goal is to be able to change the attributes globally with one command instead of picking one block at a time. Thanks.

-jsowinski

abdulhuck
2006-08-09, 04:07 PM
I understand the use of nentsel, but could you please illustrate a little the use of (ssget) and (entnext). I'm not sure how to use entnext to search for sub entities in a block. My goal is to be able to change the attributes globally with one command instead of picking one block at a time. Thanks.

-jsowinski
Hi Jsowinski,

The following code I am using for long time. It can be improved with Visual Lisp. Hope this will help you. This function will ask for a reference text entity or an attribute, and changes the properties of all the attributes (within blocks) to match the reference object.


(defun C:ChAttribFont (/ rfont rent rfx rht rob ent i blks)
(princ
"\nChange Attribute font, by Abdul Huck, <abdulhuck@rediffmail.com"
)
(prompt "\nSelect the reference text or attribute . . . \n")
(setq rfont (entsel))
(setq rent (entget (car rfont)))
(if (= (cdr (assoc 0 rent)) "TEXT")
(progn
(setq rfx (cdr (assoc 7 rent)))
(setq rht (cdr (assoc 40 rent)))
(setq rob (cdr (assoc 51 rent)))
(setq rly (cdr (assoc 8 rent)))
)
)
(if (assoc 66 rent)
(setq rent (entget (entnext (cdr (assoc -1 rent)))))
)
(if (= (cdr (assoc 0 rent)) "ATTRIB")
(progn
(setq rfx (cdr (assoc 7 rent)))
(setq rht (cdr (assoc 40 rent)))
(setq rob (cdr (assoc 51 rent)))
(setq rly (cdr (assoc 8 rent)))
)
)
(prompt "\nSelect attributes to match new style . . . \n")
(setq blks (ssget '((0 . "INSERT"))))
(if blks
(progn
(setq len (sslength blks)
i 0
)
(while (< i len)
(setq ent (entget (ssname blks i)))
(if (assoc 66 ent)
(progn
(while (/= "SEQEND" (cdr (assoc 0 ent)))
(setq ent (entget (entnext (cdr (assoc -1 ent)))))
(if (= "ATTRIB" (cdr (assoc 0 ent)))
(progn
(setq ent (subst (cons 7 rfx) (assoc 7 ent) ent))
(setq ent (subst (cons 40 rht) (assoc 40 ent) ent))
(setq ent (subst (cons 51 rob) (assoc 51 ent) ent))
(setq ent (subst (cons 8 rly) (assoc 8 ent) ent))
(entmod ent)
)
)
)
)
)
(entupd (ssname blks i))
(setq i (1+ i))
)
)
)
)


Regards,
Abdul Huck

jsowinski
2006-08-09, 11:32 PM
Thanks for the help! I think the last part of the routine will help me.

Jim Sowinski