Author Topic: What is wrong? Change the style of text blocks and blocks with attributes.  (Read 2870 times)

0 Members and 1 Guest are viewing this topic.

josan

  • Mosquito
  • Posts: 15
I have a drawing with text blocks and blocks with attributes and need to change the text style.
I was looking for but just got this code.
How I can fix it?
Code: [Select]
(setq ss (ssget '((0 . "INSERT"))));;block text attribute.
(setq e1 (entget (ssname ss 0)))
(setq e2 (cdr (assoc -1 e1)))
(setq e3 (entget(entnext e2)))
(setq e4 (cdr (assoc 7 e3)))
(setq e5 (subst (cons 7 "LPArialNarrow")(cons 7 e4) e3))
(entmod e5)
(setq e6 (subst e5 e3 e1))
(entmod e6)[code=cadlisp-7]
[/code]

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: What is wrong? Change the style of text blocks and blocks with attributes.
« Reply #1 on: September 29, 2016, 08:00:03 AM »
Here is an example for you to consider:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ent enx idx sel sty )
  2.     (setq sty "LPArialNarrow") ;; New Textstyle
  3.     (cond
  4.         (   (not (tblsearch "style" sty))
  5.             (princ (strcat "\nTextstyle \"" sty "\" doesn't exist."))
  6.             (textscr)
  7.         )
  8.         (   (setq sty (cons 7 sty)
  9.                   sel (ssget "_:L" '((0 . "INSERT") (66 . 1)))
  10.             )
  11.             (repeat (setq idx (sslength sel))
  12.                 (setq ent (entnext (ssname sel (setq idx (1- idx))))
  13.                       enx (entget ent)
  14.                 )
  15.                 (while (= "ATTRIB" (cdr (assoc 0 enx)))
  16.                     (if (entmod (subst sty (assoc 7 enx) enx))
  17.                         (entupd ent)
  18.                     )
  19.                     (setq ent (entnext ent)
  20.                           enx (entget  ent)
  21.                     )
  22.                 )
  23.             )
  24.         )
  25.     )
  26.     (princ)
  27. )

Note that any changes to attribute references will be reversed following the use of the ATTSYNC command; you will need to modify the corresponding attribute definitions for the changes to become permanent.

josan

  • Mosquito
  • Posts: 15
Re: What is wrong? Change the style of text blocks and blocks with attributes.
« Reply #2 on: September 29, 2016, 09:11:18 AM »

Thanks I will apply.

josan

  • Mosquito
  • Posts: 15
Re: What is wrong? Change the style of text blocks and blocks with attributes.
« Reply #3 on: September 30, 2016, 09:03:48 PM »
The function is very efficient, I thought it was going to change all types of blocks.
But I can only select blocks of text as an attribute.
Text blocks and dynamic blocks are not modified.
How I can change the routine so you can select them?

Thank you.


josan

  • Mosquito
  • Posts: 15
Re: What is wrong? Change the style of text blocks and blocks with attributes.
« Reply #5 on: September 30, 2016, 11:26:03 PM »

It's great but I can not change the style of text, mtext become block.

thanks.

danallen

  • Guest
You want to only change text inside blocks, but not loose text?

josan

  • Mosquito
  • Posts: 15

This is a drawing of an example, I have trouble through the list of elements within blocks. To change the texts out of the blocks I have no problems.
That's my problem I do not understand how walking the elements contained within the block and discard those that are not "TEXT" or "MTEXT".

danallen

  • Guest
Did you try T. Willey's fuction ChangeAllTextObjectsStyle ? It will change the style of mtexts inside blocks

josan

  • Mosquito
  • Posts: 15
I check the file and served me a lot but does not do what I need. In the previous post load the dwg file that I'm testing routines.

With this code try to find the blocks containing texts, which are not attributes, and walk the entities that make up the block, finding the TEXT or MTEXT, sack some values ​​of the database and then modify them.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:ChTB ()
  2. ;(stilos:texto)                
  3. (setq Conjunto (ssget "X" '((0 . "INSERT") (66 . 0))))
  4. (setq cont 0)
  5. (repeat (sslength Conjunto)
  6. (setq e1 (ssname Conjunto cont))
  7. (setq e2 (entget e1))
  8. (setq e3 (tblobjname "BLOCK" (cdr (assoc 2 e2))))
  9. (while (setq e4 (entnext e3))
  10. (setq e5 (entnext e4))
  11. (if (/= e5 nil)
  12. (if (= (setq e6 (cdr (assoc 0 (entget e5)))) "MTEXT")(setq e7(cdr (assoc 7 (entget e5)))))
  13. (if (= (setq e6 (cdr (assoc 0 (entget e5)))) "TEXT")(setq e7(cdr (assoc 7 (entget e5)))))
  14. )
  15. )
  16. )
  17. (setq cont (1+ cont))
  18. )
  19. )

danallen

  • Guest
Re: What is wrong? Change the style of text blocks and blocks with attributes.
« Reply #10 on: October 02, 2016, 12:39:13 PM »
You're not being clear on what help you need, first post says change text style, the link I posted does that. In any case the vla-put methods cycling through the drawing database via (vlax-for Blk (vla-get-Blocks Doc), allows modification of entities inside blocks. SSGET and ENTUPD won't do that for you. Note your last code posted is missing and ENTUPD fuction to modify the blocks.