Login

View Full Version : Looking for a one click or Auto fix for Textstyle reformatting.



jhohman
2005-03-30, 04:38 PM
I am looking for a lisp routine or diesel coding that will update existing textstyles within a drawing. I need to change the font and width factor for 3 to 4 styles (depending on the drawing) from condhand.shx to be simplex.shx and the width factor from .6 to be .7. Any help would be appreciated. Thank you in advance.

CAB2k
2005-03-30, 05:02 PM
Have you tried this one?


;;; CHTEXT.lsp
;;; Copyright (C) 1990 by Autodesk, Inc.
;;;
;;; Permission to use, copy, modify, and distribute this software and its
;;; documentation for any purpose and without fee is hereby granted.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
;;; ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
;;; MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;; by Jan S. Yoder
;;; 09 March 1990
;;;
;;;-------------------------------------------------------------------------
;;; DESCRIPTION
;;; This is a "text processor" which operates in a global manner
;;; on all of the text entities that the user selects; i.e., the
;;; Height, Justification, Location, Rotation, Style, Text, and
;;; Width can all be changed globally or individually, and the
;;; range of values for a given parameter can be listed.
;;;
;;; The command is called with CHT from the command line at which
;;; time the user is asked to select the objects to change.

Here is one you can modify.

(defun c:Alan2A5()
(StyleChange "Alan1" "A5-8")
(princ)
)
(defun c:AlanSmall2A3()
(StyleChange "Alan Small" "A3-8")
(princ)
)

(defun StyleChange (OlSty NuSty / filterList ss NuStyList entList
NuEntList NextEnt)
;;fix the case
(setq OlSty (strcase OlSty))
;;fix the case
(setq NuSty (strcase NuSty))
;;build a filter to select only text with that style
;;Note: DXF group code 7 is the style of a text entity
;; 0 is the entity type
(setq FilterList (list '(0 . "TEXT,MTEXT") (cons 7 OlSty)))

(cond
((null(setq ss (ssget "X" FilterList)));put the text in a selection set.
(alert (strcat "Found No text with style "OlSty))
)
(
;;check and make sure NuSty exist
(tblsearch "STYLE" NuSty)
;;make a dotted pair
(setq NuStyList (cons 7 NuSty))
;;set a counter
(setq n 0)
;;grab the first ent in the ss
(setq NextEnt (ssname ss n))

;;loop until all ents changed
(while NextEnt
;;get the list
(setq EntList (entget NextEnt))
;;get the old style
(setq OlStyLst (assoc 7 EntList))
;;replace it in the list
(setq NuEntList (subst NuStyList OlStyLst EntList))
;;change the ent
(entmod NuEntList)
;;update the screen
(entupd (cdr (assoc -1 NuEntList)))
;;increment
(setq n (1+ n))
;;grab next
(setq NextEnt (ssname ss n))
) ;_ end of while
(alert (strcat (itoa n) " Items Changed "))
)
(
;;otherwise you blew it.
T
(alert (strcat "Hey You,\n\n"
NuSty
" doesn't exist!"
) ;_ end of strcat
) ;_ end of alert
)
) ;_ end of cond
(princ)
) ;_ end of defun

tyshofner
2005-03-30, 05:49 PM
Here's a quickie that will fix ALL TEXT STYLES in a drawing to be "simplex.shx" with a width of "0.7". Use caution though because this will change EVERY TEXT STYLE, if you only want to change certain text styles than let me know and I can modify the code. :mrgreen:

Ty

lance.81922
2005-03-30, 06:30 PM
Ty,
Is there a reason you are selecting only TEXT and not MTEXT in your routine?

jhohman
2005-03-30, 07:02 PM
ty,
I would need 4 named styles to be reset to simplex with a width factor .7
The style names are NOTES, DWGTITLE, HANDDWGTITLE, and RMNAMES. I created a button that invokes the textstyle settings through the command line (-style) and basically sets all 4 styles to be updated, also if they do not exist, the code created them and then sets the current style to be NOTES, finally it will regen the drawing and you're back to the command line, it works pretty well but I find that not all text gets updated. I typically will use the qselect to search the entire drawing for text with a width factor not equal to .7, append to a new selection set, and then set the width factor for the qselect results to be .7 in the properties box. I have also noticed that MTEXT does not update as I would prefer, I usually double click an MTEXT entitty to enter the editor then set the style from NOTES to NOTES and it updates the MTEXT. I would like a LISP that would handle this for me. See the attached thumbnail if you would like to see the diesel macro for the button. Thanks.

tyshofner
2005-03-30, 08:04 PM
Lance,

The only reason I even created a selection set was to change any already existing TEXT to a width factor of "0.7". MTEXT does not behave the same as TEXT when your talking about the value of the width factor (assoc 41). The width factor of MTEXT is the width of the bounding box that contains the text not the text itself. When I change the text style to a width factor of "0.7" and then "regen", all MTEXT entities will update to that width factor. But, since you questioned me, it made me think for a minute and I did not account for the user changing the MTEXT text style from within the MTEXT editor using the pull-down. So, I will have to select the MTEXT as well.

jhohman,

I'll adjust the routine to do what you need (^as well as what was discussed above^) and I'll post the updated file.

Ty :mrgreen:

lance.81922
2005-03-30, 08:32 PM
Yes, Ty, you're right about how the width of MTEXT is handled. I didn't read your code too carefully -- my bad. I've been working on some routines to change properties of MTEXT so noted your work with interest. That bounding box-versus-width-of-the text business is interesting.

jhohman
2005-03-30, 08:49 PM
Lance,
Basically MTEXT with a width of 0 means that the text will not return unless you press enter to move it to the line below. With a with greater than 0, you end up with wordwrap mtext that has a boudary that can be manipulted. Just for your info.

tyshofner
2005-03-30, 09:19 PM
Alright,
Here are two updates. The first attachment (fixtextstyle.lsp) is an update of the first routine I posted, this will change ALL text to "simplex" with a width of "0.7". The second attachment (fixtextstyle-New.lsp) is for the specific styles that jhohman needs. This routine will check to see if the styles are present, if not it will create them, if they do exist it will fix them. It will ONLY affect the specific styles: NOTES, DWGTITLE, HANDDWGTITLE, and RMNAMES. If you have any question or comments post away!! Always happy to help.

Ty :mrgreen:

jhohman
2005-03-30, 09:35 PM
Amazing!! Worked like a charm! Truly genius, thanks for all the help, Lance included, I have added a positive to both reputations. Thank you, thank you, thank you!!!

tyshofner
2005-03-30, 10:07 PM
jhohman,

Your welcome, always glad to be of assistance.

Ty :mrgreen:

doggarn.70892
2005-04-04, 05:07 PM
Here is a way I do it.... adjust your styles once and run after declaring your dimscale.




;;TDD.LSP
;;
;;
;;Sets up text styles (IMPERIAL) without having softdesk loaded..
;;
(DEFUN C:Tdd ()


(setvar "cmdecho" 0)(graphscr)
(setvar "userr5" 1)
(setvar "USERR4" (* 1 (getvar "DIMSCALE")))
(setq scl_fact (getvar "userr4"))
(command ".style" "L100" "simplex" (* 0.100 scl_fact) "1" "0" "n" "n" "n")
(setq sname "L100")
(setvar "textstyle" sname)



(setvar "CMDECHO" 0)(textscr)
(setq scl_fact (getvar "dimscale"))
(command "textstyle" "L100")
(setvar "textsize" (* 0.100 scl_fact))
(setq sname (getvar "textstyle"))(princ)
(command ".style" "Standard" "simplex" (* 1.000 1.000) "1" "0" "n" "n" "n")(princ)
(command ".style" "L10" "simplex" (* 0.010 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L20" "simplex" (* 0.020 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L30" "simplex" (* 0.030 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L40" "simplex" (* 0.040 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L50" "simplex" (* 0.050 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L60" "simplex" (* 0.060 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L80" "simplex" (* 0.080 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L100" "simplex" (* 0.100 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L120" "simplex" (* 0.120 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L140" "simplex" (* 0.140 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L175" "simplex" (* 0.175 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L200" "simplex" (* 0.200 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L240" "simplex" (* 0.240 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L290" "simplex" (* 0.290 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L350" "simplex" (* 0.350 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L425" "simplex" (* 0.425 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "L500" "simplex" (* 0.500 scl_fact) "1" "0" "n" "n" "n")(princ)
(command ".style" "ROMANT" "ROMANT" (* 0.175 scl_fact) "1" "0" "n" "n" "n")(princ)
(setq scl_fact_ps (getvar "userr5"))(princ)

(command ".style" "Line" "simplex" (* 1.00 1.000) "1" "0" "n" "n" "n")(princ)
(command ".style" "DASH100" "dashfont" (* 0.1000 scl_fact) "1" "0" "n" "n")(princ)
(command ".style" "DASH120" "dashfont" (* 0.1200 scl_fact) "1" "0" "n" "n")(princ)
(command ".style" "DASH140" "dashfont" (* 0.1400 scl_fact) "1" "0" "n" "n")(princ)
(command ".style" "DASH240" "dashfont" (* 0.2400 scl_fact) "1" "0" "n" "n")(princ)
(command ".style" "PL100" "simplex" (* 0.1 scl_fact_PS) "1" "0" "n" "n" "n")(princ)
(command ".style" "PL120" "simplex" (* 0.12 scl_fact_PS) "1" "0" "n" "n" "n")(princ)
(command ".style" "PL140" "simplex" (* 0.14 scl_fact_PS) "1" "0" "n" "n" "n")(princ)
(command ".style" "PL80" "simplex" (* 0.08 scl_fact_PS) "1" "0" "n" "n" "n")(princ)
(command ".style" "RomanT100" "ROMANT" (* 0.1 scl_fact_PS) "1" "0" "n" "n" "n")(princ)
(command ".style" "RomanT120" "ROMANT" (* 0.12 scl_fact_PS) "1" "0" "n" "n" "n")(princ)
(setvar "cmdecho" 0)(setvar "textstyle" sname)(princ)


(setq sname (getvar "textstyle"))(princ)
(graphscr)
(princ)

)




Hope this will help.

[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]