C. Roberts Posted September 13 Posted September 13 I am needing to get a list of all the text entities within the DesCalc block that don't equal the text height of the table text objects and then after getting the list I need to mod them to have the same text height. I have followed an answer that was given in a previous thread but it lists all entities of the block, I only want text entities that have text heights that don't equal the text heights of the entities in the table of the block. Topic: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-acces-entities-within-a-block/td-p/4572545 Reply: (defun get-block-entities ( blk / ent lst ) ;; Define the function, declare local variables (if ;; If the following returns a non-nil value ;; i.e. if the block exists in the drawing (setq ent (tblobjname "block" blk)) ;; get the BLOCK entity (while (setq ent (entnext ent)) ;; Step through the entities in the block definition (setq lst (cons ent lst)) ;; Construct a list of the block components ) ;; end WHILE ) ;; end IF (reverse lst) ;; Return the list ) ;; end DEFUN My portion that I am trying to get to work but gives an error (; error: bad argument type: listp <Entity name: 283109094c0>) ;; --- Compile list of entity names of text objects with text heights that are different from the table text objects text height --- ;; (if (setq ent3 (tblobjname "BLOCK" "DesCalc")) (while (setq ent3 (entnext ent3)) (if (and (eq (cdr (assoc 0 ent3)) "TEXT") (/= (cdr (assoc 40 ent3)) tbl_txtht)) (setq lst (cons ent3 lst)) ) ) ) What do I need to change to be able to have a list of only entities with the criteria shown above? After I get the list I believe I can just use a foreach function and loop through the list and mod the text heights accordingly like I do with the last portion of the lisp that is scaling the DesCalc block? Full code (defun c:WPD () ;; --- User selects DesCalc.dxf from correct job folder to be inserted and places in drawing--- ;; (command "CLASSICINSERT" "\\") ;; --- Find EWTABL block and retrieve text height of the text object with contents of "MAXIMUM ASD REACTIONS" --- ;; (cond ((setq tbl1 (tblobjname "BLOCK" "EWTABL")) (setq ent1 (entget tbl1)) (while (setq ent1 (entnext (cdar ent1))) (setq ent1 (entget ent1)) (if (and (eq (cdr (assoc 0 ent1)) "TEXT") (eq (cdr (assoc 1 ent1)) "MAXIMUM ASD REACTIONS")) (setq reaction_txtht (cdr (assoc 40 ent1))) ) ) ) ) ;; --- Find DesCalc block and retrieve text height of the text object with contents of "Zone" --- ;; (cond ((setq tbl2 (tblobjname "BLOCK" "DesCalc")) (setq ent2 (entget tbl2)) (while (setq ent2 (entnext (cdar ent2))) (setq ent2 (entget ent2)) (if (and (eq (cdr (assoc 0 ent2)) "TEXT") (eq (cdr (assoc 1 ent2)) "Zone")) (setq tbl_txtht (cdr (assoc 40 ent2))) ) ) ) ) ;; --- Compile list of entity names of text objects with text heights that are different from the table text objects text height --- ;; (if (setq ent3 (tblobjname "BLOCK" "DesCalc")) (while (setq ent3 (entnext ent3)) (if (and (eq (cdr (assoc 0 ent3)) "TEXT") (/= (cdr (assoc 40 ent3)) tbl_txtht)) (setq lst (cons ent3 lst)) ) ) ) ;; --- Modify text entities from above to have same text height as table text objects --- ;; ;; --- use foreach to loop through all entities in list to change text heights --- ;; ;; --- Calculate scale factor --- ;; (setq scale_factor (/ reaction_txtht tbl_txtht)) ;; --- Modify DesCalc scale in a single loop --- ;; (foreach axis (list 41 42 43) (setq descalc_blk (tblobjname "BLOCK" "DesCalc")) (setq descalc_ent (entget descalc_blk )) (entmod (subst (cons axis scale_factor) (assoc axis descalc_ent) descalc_ent))) ) I have attached a drawing file with the necessary blocks for the lisp to run AnDwg-4.dwg Quote
Steven P Posted September 13 Posted September 13 So for your portion: In your (assoc 0 ent3) and (assoc 40 ent3) lines 'ent3' is the entity name and not the entity description - there is no assoc to find in '<Entity name: 283109094c0>'.. so to fix that 'entget' your entity name to get the description and then the assocs will work. If you are making a list of entities then I'd create a selection set instead of a list using ssadd ;; --- Compile list of entity names of text objects with text heights that are different from the table text objects text height --- ;; (if (setq ent3 (tblobjname "BLOCK" "DesCalc")) (while (setq ent3 (entnext ent3)) (if (and (eq (cdr (assoc 0 (entget ent3))) "TEXT") (/= (cdr (assoc 40 (entgetent3))) tbl_txtht)) (setq lst (cons ent3 lst)) ) ) ) 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.