Author Topic: Text Style in Attribute  (Read 2871 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Text Style in Attribute
« on: July 12, 2005, 07:35:48 AM »
I have the following lisp to go through the drawing and change andy text and Mtext to the standard style. How can I modify this to also search through all blocks with attributes to allso change them to the standard style?

Code: [Select]

(defun C:CTS (/ ss idx cnt n e en ent opt)
  (vl-load-com)
  (setq txtstyle "Standard")
;        (if (= (tblsearch "STYLE" txtstyle) nil)
        (command "-style" txtstyle "Simplex.shx" 0 1 0 "No" "No" "No")
  (setq ss (ssget "_X" '((-4 . "<or")(0 . "MTEXT")(0 . "TEXT")(-4 . "or>"))))
  (if (null ss)
  (progn
      (alert "ERROR - No Text Entities found")
      (setvar "CMDECHO" 1)
      (exit)
    )
    (progn)
   )
  (setq idx 0)
  (setq cnt 0)
  (setq n (sslength ss))
  ;(setq opt (getstring "\nENTER NEW STYLE NAME: "))
  (setq opt "Standard")
  (repeat n
    (setq e (ssname ss cnt))
    (setq en (vlax-ename->vla-object e))
    (setq ent (vlax-get-property en "StyleName"))
    (vla-put-StyleName en opt)
    (setq cnt (1+ cnt )))
  (princ)
  )
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Text Style in Attribute
« Reply #1 on: July 12, 2005, 07:48:34 AM »
Not proofed
Code: [Select]
:(defun C:CTS (/ ss idx cnt n e en ent opt)
  (vl-load-com)
  (setq txtstyle "Standard")
;        (if (= (tblsearch "STYLE" txtstyle) nil)
        (command "-style" txtstyle "Simplex.shx" 0 1 0 "No" "No" "No")
  (setq ss (ssget "_X" '((0 . "MTEXT,TEXT,INSERT"))))
  (if (null ss)
  (progn
      (alert "ERROR - No Text Entities found")
      (setvar "CMDECHO" 1)
      (exit)
    )
    (progn)
   )
  (setq idx 0)
  (setq cnt 0)
  (setq n (sslength ss))
  ;(setq opt (getstring "\nENTER NEW STYLE NAME: "))
  (setq opt "Standard")
  (repeat n
    (setq e (ssname ss cnt))
    (setq en (vlax-ename->vla-object e))
    (if (eq (vla-get-ObjectName en) "AcDbBlockReference")
     (if (= (vla-get-HasAttributes en) :vlax-true)
      (progn
       (mapcar
       '(lambda (o) (vla-put-StyleName o opt))
        (vlax-invoke en 'GetAttributes)
       )
       (vla-Update en)
      )
     )
     (progn
      (setq ent (vlax-get-property en "StyleName"))
      (vla-put-StyleName en opt)
     )
    )
    (setq cnt (1+ cnt )))
  (princ)
  )
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Text Style in Attribute
« Reply #2 on: July 12, 2005, 08:10:18 AM »
That worked great. Actually I just found a bug in the original lisp posted. The problem I have found is that it does change any Text or Mtext in a drawing to Standard style but in the case of Mtext the Font is not is still hard-coded if you will with whatever it was originally made with. For instance right now the Standard style is default and with a Simplex Font but the routine only changed the style of the Mtext and the font for it is still Romans for example. Any fixing for this?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Text Style in Attribute
« Reply #3 on: July 12, 2005, 08:46:08 AM »
Here is one i was working on.
Not fully tested & it strips all formatting.
Code: [Select]
;;;=======================[ Strip.lsp ]==================================
;;; Author:  Charles Alan Butler Copyright© 2005
;;; Version: 1.0 June 22, 2005
;;; Purpose: Strip format characters from text or mtext
;;; Returns: A string  
;;; Sub_Routines: -None
;;; Arguments: A string variable
;;;======================================================================

(defun strip (entstr / skipchr ndx newstring code nextchr fmtcode strlength)
 
  (setq ndx     1
        ;; "fmtcode" is a list of code flags that will end with ;
        fmtcode  (list "\\C" "\\F" "\\H" "\\T" "\\Q" "\\W" "\\A")
  )
  (if (/= entstr nil) ; skip if empty text ""
    (progn
      (setq strlength (strlen entstr)
            newstring ""
      )
      (while (<= ndx strlength)
        ;; step through text and find FORMATT CHARACTERS
        (setq nextchr (substr entstr ndx 1) ; Get next character
              skipchr 0)

        (cond
          ((or (= nextchr "{") (= nextchr "}"))
           (setq skipchr 1)
          )
          ((or (= nextchr "\\") (= nextchr "%"))
           ;; process ctrl codes  
           ;;  This section processes groups codes

           (setq code (strcase (substr entstr ndx 2)))
           ;; get next 2 characters
           ;; set to 2 because \\ is counted as one

           (cond ;; Process Coded information
                 ((= (strlen code) 1) ; true if \ or % is last char in text
                  (setq skipchr 2)
                 ) ; end cond 1

                 ((member code fmtcode) ; this code will end with ";"
                  (while (/= (setq nextchr (substr entstr (+ skipchr ndx) 1)) ";")
                    (setq skipchr (1+ skipchr))
                  ) ; end while Loop
                  (setq skipchr (1+ skipchr))
                 ) ; end cond 2

                 ((= nextchr "%")
                  (if (= code "%%") ; code found
                    (if (distof (substr entstr (+ ndx 2) 1))
                      ;;number found so fmtcode %%nnn
                      (setq skipchr 6)
                      ;; else letter code, so fmtcode %%p
                      (setq skipchr 4)
                    ) ; endif
                    ;; else no %% codes so add the % char to list
                  ) ; endif
                 ) ; end cond 3

                 ;; found \\U then get 7 character group
                 ((= code "\\U") (setq skipchr 8)) ; end cond 4 ; CAB add

                 ;; found \\M then get 8 character group
                 ((= code "\\M") (setq skipchr 9)) ; end cond 5 ; CAB add
                 
                 ;; found \\P then replace with CR LF
                 ((= code "\\P")
                    (setq newstring (strcat newstring (chr 13)(chr 10))
                          ndx (+ ndx 1)
                          skipchr 1)
                 ) ; end cond 6

                 ;; found \\ this is the normal brace, skip over \\
                 ((= code "\\{") (setq  ndx (+ ndx 1))) ; end cond 7
                 
                 ;; found \\ this is the normal brace, skip over \\
                 ((= code "\\}") (setq  ndx (+ ndx 1))) ; end cond 8
                 
                 ;; found \\ this is the non breaking space
                 ((= code "\\~")
                  (setq newstring (strcat newstring " "))
                  (setq skipchr 2) ; end cond 9
                 )
                 
                 ;; found \\\\ it is one \
                 ((= code "\\\\")
                    (setq newstring (strcat newstring "\\")
                          ndx (+ ndx 2))
                 ) ; end cond 10

                 ;;  Stacked text format as "[ top_txt / bot_txt ]"
                 ((= code "\\S")
                    (setq pt (1+ ndx)
                          tmp ""
                          newstring (strcat newstring "[")
                          )
                  (while
                    (not
                      (member
                        (setq tmp (substr entstr (setq pt (1+ pt)) 1))
                        '("^" "/" "#")))
                    (setq newstring (strcat newstring tmp))
                  )
                  (setq newstring (strcat newstring "/"))
                  (while (/= (setq tmp (substr entstr (setq pt (1+ pt)) 1)) ";")
                    (setq newstring (strcat newstring tmp))
                    )
                  (setq newstring (strcat newstring "]")
                        ndx pt
                        skipchr (1+ skipchr)
                  )
                 ) ; end cond 11

                 ;; found \\ then get 2 character group \L \l \O \o
                 ((= nextchr "\\") (setq skipchr 3)) ; end cond 12
           )
           ;; end cond  Process Coded information
          ) ; end cond (or (= NextChr "\\") (= NextChr "%"))

        ) ; end cond
        (if (zerop skipchr) ; add char to string
          (setq newstring (strcat newstring (substr entstr ndx 1))
                ndx (+ ndx 1))
         ;;  else skip some characters
          (setq ndx (+ ndx skipchr))
        )

      ) ; end while Loop
    ) ; end progn
  ) ; endif
  newstring ; return the stripped string
) ; end defun
;;;======================================================================
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pmvliet

  • Guest
Text Style in Attribute
« Reply #4 on: July 12, 2005, 12:27:36 PM »
There is a lisp here

http://www.theswamp.org/phpBB2/viewtopic.php?t=1452&postdays=0&postorder=asc&highlight=stripmtext&start=10

That has a link to another mtext fixer.

just sharing what I have found. I know CAB does good work, but maybe there is something else in this routine he could incorporate.

Pieter

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Text Style in Attribute
« Reply #5 on: July 12, 2005, 12:36:06 PM »
Thanks for the compliment.
Here is a direct link to get
Quote
StripMtext v3.07 for AutoCAD 2000 thru 2004

This program creates a user command that will quickly remove
formatting applied to individual characters and words inside
Mtext objects.

StripMtext can remove the following types of formatting:

Alignment
Color
Font
Height
Underscore
Overscore
Linefeed (Paragraph Return)
Obliquing
Stacking
Tracking
Width
Non-breaking Space

StripMtext does not modify Mtext properties such as style,
justification, width, and rotation.  Nor does it manipulate
inherited properties such as layer, entity color, etc.


http://www.users.qwest.net/~sdoman/

The routine uses a different programing approach and his setup allows for removing
selected overrides.

I wrote mine for another routine in which I wanted all overrides gone.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.