Results 1 to 9 of 9

Thread: globally change diagonal fractions to horizontal fractions

  1. #1
    Member mburke.54112's Avatar
    Join Date
    2016-02
    Location
    NC
    Posts
    43
    Login to Give a bone
    0

    Default globally change diagonal fractions to horizontal fractions

    I found a lisp routine here in AUGI that replaces existing MTEXT horizontal stacked fractions to diagonal. I am having trouble modifying it to do the reverse (diagonal to horizontal).
    I know that I need to change the "\s1#4" (diaginal) to "\s1/4" (horizontal) but I can't get the routine to recognize the "\s1#4". Here is the horizontal to diagonal routine:
    Code:
    (defun c:UFD ()
      (setq ztm (getvar "tilemode"))
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 1)
        )
      (FindReplaceAll "\S1/32" "\S1#32")
      (FindReplaceAll "\S1/16" "\S1#16") 
      (FindReplaceAll "\S3/32" "\S3#32")
      (FindReplaceAll "\S1/8" "\S1#8")
      (FindReplaceAll "\S5/32" "\S5#32") 
      (FindReplaceAll "\S3/16" "\S3#16")
      (FindReplaceAll "\S7/32" "\S7#32")
      (FindReplaceAll "\S1/4" "\S1#4")
      (FindReplaceAll "\S9/32" "\S9#32")
      (FindReplaceAll "\S5/16" "\S5#16") 
      (FindReplaceAll "\S11/32" "\S11#32")
      (FindReplaceAll "\S3/8" "\S3#8") 
      (FindReplaceAll "\S13/32" "\S13#32")
      (FindReplaceAll "\S7/16" "\S7#16") 
      (FindReplaceAll "\S15/32" "\S15#32")
      (FindReplaceAll "\S1/2" "\S1#2")
      (FindReplaceAll "\S17/32" "\S17#32")
      (FindReplaceAll "\S9/16" "\S9#16")
      (FindReplaceAll "\S19/32" "\S19#32")
      (FindReplaceAll "\S5/8" "\S5#8") 
      (FindReplaceAll "\S21/32" "\S21#32")
      (FindReplaceAll "\S11/16" "\S11#16") 
      (FindReplaceAll "\S23/32" "\S23#32")
      (FindReplaceAll "\S3/4" "\S3#4")
      (FindReplaceAll "\S25/32" "\S25#32")
      (FindReplaceAll "\S13/16" "\S13#16") 
      (FindReplaceAll "\S27/32" "\S27#32")
      (FindReplaceAll "\S7/8" "\S7#8")
      (FindReplaceAll "\S29/32" "\S29#32")
      (FindReplaceAll "\S15/16" "\S15#16")
      (FindReplaceAll "\S31/32" "\S31#32")
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 0)
        )
      (princ "\nChanged Horizontal Stacked dimensions to Diagonal Stacked.")
      (princ)
     );defun
    
    ;-------------------------------------------------------------------------------
    ; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
    ; that have a Find$ string with a Replace$ string.
    ; Arguments: 2
    ;   Find$ = Phrase string to find
    ;   Replace$ = Phrase to replace it with
    ; Syntax: (FindReplaceAll "|" "1/4")
    ; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
    ;-------------------------------------------------------------------------------
    (defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
      DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace
      Mid$ Mid2$ NewText$ Num# SS& Text$)
      ;-----------------------------------------------------------------------------
      ; FindReplace: - Returns Str$ with Find$ changed to Replace$
      ; Arguments: 3
      ;   Str$ = Text string
      ;   Find$ = Phrase string to find
      ;   Replace$ = Phrase to replace Find$ with
      ; Returns: Returns Str$ with Find$ changed to Replace$
      ;-----------------------------------------------------------------------------
      (defun FindReplace (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
        (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
        (while Loop
          (setq Mid$ (substr NewStr$ Cnt# FindLen#))
          (if (= Mid$ Find$)
            (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
                  Cnt# (+ Cnt# ReplaceLen#)
            );setq
            (setq Cnt# (1+ Cnt#))
          );if
          (if (= Mid$ "") (setq Loop nil))
        );while
        NewStr$
      );defun FindReplace:
      ;-----------------------------------------------------------------------------
      ; Start of Main function
      ;-----------------------------------------------------------------------------
      (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
        (progn
          (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
            (progn
              (setq Cnt# 0)
              (repeat (sslength SS&)
                (setq EntName^ (ssname SS& Cnt#)
                      EntList@ (entget EntName^)
                      EntType$ (cdr (assoc 0 EntList@))
                      Text$ (cdr (assoc 1 EntList@))
                );setq
                (if (= EntType$ "INSERT")
                  (if (assoc 66 EntList@)
                    (progn
                      (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
                        (setq EntList@ (entget EntName^))
                        (if (= (cdr (assoc 0 EntList@)) "ATTRIB")
                          (progn
                            (setq Text$ (cdr (assoc 1 EntList@)))
                            (if (wcmatch Text$ (strcat "*" Find$ "*"))
                              (progn
                                (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                                (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                                (entupd EntName^)
                              );progn
                            );if
                          );progn
                        );if
                        (setq EntName^ (entnext EntName^))
                      );while
                    );progn
                  );if
                  (if (wcmatch Text$ (strcat "*" Find$ "*"))
                    (progn
                      (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                      (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                      (entupd EntName^)
                    );progn
                  );if
                );if
                (setq Cnt# (1+ Cnt#))
              );repeat
            );progn
          );if
        );progn
      );if
      (princ)
    );defun FindReplaceAll
    But when I try:
    (FindReplaceAll "\S1#4" "\S1/4")
    nothing happens.

    Thanks, in advance for any help.
    Last edited by RobertB; 2010-06-08 at 05:57 PM. Reason: Added [code] tags
    Michael
    CALYX Engineers + Consultants
    www.calyxengineers.com
    - Happiness is Wanting What You Have, Not Having What You Want -

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: globally change diagonal fractions to horizontal fractions

    The issue is that "#" is a wildcard for wcmatch. So you need to override wcmatch to use the literal # when searching for your fractions.

    The code needed a new function and modification in two locations to use the new function.
    Code:
    ;-------------------------------------------------------------------------------
    ; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
    ; that have a Find$ string with a Replace$ string.
    ; Arguments: 2
    ;   Find$ = Phrase string to find
    ;   Replace$ = Phrase to replace it with
    ; Syntax: (FindReplaceAll "|" "1/4")
    ; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
    ;-------------------------------------------------------------------------------
    (defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
      DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace
      Mid$ Mid2$ NewText$ Num# SS& Text$)
    
    (defun i:wcmatch (string pattern)
      (wcmatch string (vl-string-subst "`#" "#" pattern)))
    
      ;-----------------------------------------------------------------------------
      ; FindReplace: - Returns Str$ with Find$ changed to Replace$
      ; Arguments: 3
      ;   Str$ = Text string
      ;   Find$ = Phrase string to find
      ;   Replace$ = Phrase to replace Find$ with
      ; Returns: Returns Str$ with Find$ changed to Replace$
      ;-----------------------------------------------------------------------------
      (defun FindReplace (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
        (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
        (while Loop
          (setq Mid$ (substr NewStr$ Cnt# FindLen#))
          (if (= Mid$ Find$)
            (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
                  Cnt# (+ Cnt# ReplaceLen#)
            );setq
            (setq Cnt# (1+ Cnt#))
          );if
          (if (= Mid$ "") (setq Loop nil))
        );while
        NewStr$
      );defun FindReplace:
      ;-----------------------------------------------------------------------------
      ; Start of Main function
      ;-----------------------------------------------------------------------------
      (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
        (progn
          (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
            (progn
              (setq Cnt# 0)
              (repeat (sslength SS&)
                (setq EntName^ (ssname SS& Cnt#)
                      EntList@ (entget EntName^)
                      EntType$ (cdr (assoc 0 EntList@))
                      Text$ (cdr (assoc 1 EntList@))
                );setq
                (if (= EntType$ "INSERT")
                  (if (assoc 66 EntList@)
                    (progn
                      (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
                        (setq EntList@ (entget EntName^))
                        (if (= (cdr (assoc 0 EntList@)) "ATTRIB")
                          (progn
                            (setq Text$ (cdr (assoc 1 EntList@)))
                            (if (i:wcmatch Text$ (strcat "*" Find$ "*"))
                              (progn
                                (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                                (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                                (entupd EntName^)
                              );progn
                            );if
                          );progn
                        );if
                        (setq EntName^ (entnext EntName^))
                      );while
                    );progn
                  );if
                  (if (i:wcmatch Text$ (strcat "*" Find$ "*"))
                    (progn
                      (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                      (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                      (entupd EntName^)
                    );progn
                  );if
                );if
                (setq Cnt# (1+ Cnt#))
              );repeat
            );progn
          );if
        );progn
      );if
      (princ)
    );defun FindReplaceAll
    Note that this is an incomplete hack to fix your specific issue.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  3. #3
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: globally change diagonal fractions to horizontal fractions

    eg.

    Code:
    (mapcar
      (function (lambda (find replace) (FindReplaceAll find replace)))
      '("\S1/32" "\S1/16" "\S3/32" "\S1/8" "\S5/32") ;find list
      '("\S1`#32" "\S1`#16" "\S3`#32" "\S1`#8" "\S51`#32") ;replace list
    )
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  4. #4
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: globally change diagonal fractions to horizontal fractions

    Quote Originally Posted by alanjt View Post
    eg.

    Code:
    (mapcar
      (function (lambda (find replace) (FindReplaceAll find replace)))
      '("\S1/32" "\S1/16" "\S3/32" "\S1/8" "\S5/32") ;find list
      '("\S1`#32" "\S1`#16" "\S3`#32" "\S1`#8" "\S51`#32") ;replace list
    )
    Alan, you've got the issue backwards. The search list was the problem and your example, while it does a great job of simplifying the original c:UFD function, it doesn't really help the issue noted by the OP. If you switched your find and replace lists with the orginal code, the issue would still be there because "`#", while valid for wcmatch, is not valid for the FindReplace function.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  5. #5
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: globally change diagonal fractions to horizontal fractions

    Quote Originally Posted by RobertB View Post
    Alan, you've got the issue backwards. The search list was the problem and your example, while it does a great job of simplifying the original c:UFD function, it doesn't really help the issue noted by the OP. If you switched your find and replace lists with the orginal code, the issue would still be there because "`#", while valid for wcmatch, is not valid for the FindReplace function.
    Ahh, OK, my mistake. I'm 0-X today.
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  6. #6
    Member mburke.54112's Avatar
    Join Date
    2016-02
    Location
    NC
    Posts
    43
    Login to Give a bone
    0

    Thumbs up Re: globally change diagonal fractions to horizontal fractions

    Thanks Guys, I added the commands and fractions to RobertB's revisions and it works like a charm!
    It contains 2 commands:
    "UFD" to change horizontal fractions to diagonal
    "UFH" to change diagonal fractions to horizontal

    Below is the new code for everyone's use; I have tested it for Mtext in ModelSpace with Acad2010 only.
    Code:
    (defun c:UFD ()
      (setq ztm (getvar "tilemode"))
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 1)
        )
      (FindReplaceAll "1/32" "1#32")
      (FindReplaceAll "1/16" "1#16") 
      (FindReplaceAll "3/32" "3#32")
      (FindReplaceAll "1/8" "1#8")
      (FindReplaceAll "5/32" "5#32") 
      (FindReplaceAll "3/16" "3#16")
      (FindReplaceAll "7/32" "7#32")
      (FindReplaceAll "1/4" "1#4")
      (FindReplaceAll "9/32" "9#32")
      (FindReplaceAll "5/16" "5#16") 
      (FindReplaceAll "11/32" "11#32")
      (FindReplaceAll "3/8" "3#8") 
      (FindReplaceAll "13/32" "13#32")
      (FindReplaceAll "7/16" "7#16") 
      (FindReplaceAll "15/32" "15#32")
      (FindReplaceAll "1/2" "1#2")
      (FindReplaceAll "17/32" "17#32")
      (FindReplaceAll "9/16" "9#16")
      (FindReplaceAll "19/32" "19#32")
      (FindReplaceAll "5/8" "5#8") 
      (FindReplaceAll "21/32" "21#32")
      (FindReplaceAll "11/16" "11#16") 
      (FindReplaceAll "23/32" "23#32")
      (FindReplaceAll "3/4" "3#4")
      (FindReplaceAll "25/32" "25#32")
      (FindReplaceAll "13/16" "13#16") 
      (FindReplaceAll "27/32" "27#32")
      (FindReplaceAll "7/8" "7#8")
      (FindReplaceAll "29/32" "29#32")
      (FindReplaceAll "15/16" "15#16")
      (FindReplaceAll "31/32" "31#32")
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 0)
        )
      (princ "\nChanged Horizontal Stacked dimensions to Diagonal Stacked.")
      (princ)
    );end defun C:UFD
    ;;
    ;;
    ;;Update Diagonal Fractions to Horizontal
    ;;
    (defun c:UFH ()
      (setq ztm (getvar "tilemode"))
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 1)
        )
      (FindReplaceAll "1#32" "1/32")
      (FindReplaceAll "1#16" "1/16") 
      (FindReplaceAll "3#32" "3/32")
      (FindReplaceAll "1#8" "1/8")
      (FindReplaceAll "5#32" "5/32") 
      (FindReplaceAll "3#16" "3/16")
      (FindReplaceAll "7#32" "7/32")
      (FindReplaceAll "1#4" "1/4")
      (FindReplaceAll "9#32" "9/32")
      (FindReplaceAll "5#16" "5/16") 
      (FindReplaceAll "11#32" "11/32")
      (FindReplaceAll "3#8" "3/8") 
      (FindReplaceAll "13#32" "13/32")
      (FindReplaceAll "7#16" "7/16") 
      (FindReplaceAll "15#32" "15/32")
      (FindReplaceAll "1#2" "1/2")
      (FindReplaceAll "17#32" "17/32")
      (FindReplaceAll "9#16" "9/16")
      (FindReplaceAll "19#32" "19/32")
      (FindReplaceAll "5#8" "5/8") 
      (FindReplaceAll "21#32" "21/32")
      (FindReplaceAll "11#16" "11/16") 
      (FindReplaceAll "23#32" "23/32")
      (FindReplaceAll "3#4" "3/4")
      (FindReplaceAll "25#32" "25/32")
      (FindReplaceAll "13#16" "13/16") 
      (FindReplaceAll "27#32" "27/32")
      (FindReplaceAll "7#8" "7/8")
      (FindReplaceAll "29#32" "29/32")
      (FindReplaceAll "15#16" "15/16")
      (FindReplaceAll "31#32" "31/32")
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 0)
        )
      (princ "\nChanged Diagonal Stacked dimensions to Horizontal Stacked.")
      (princ)
    );end defun C:UFH
    ;
    ;
    ;-------------------------------------------------------------------------------
    ; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
    ; that have a Find$ string with a Replace$ string.
    ; Arguments: 2
    ;   Find$ = Phrase string to find
    ;   Replace$ = Phrase to replace it with
    ; Syntax: (FindReplaceAll "|" "1/4")
    ; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
    ;-------------------------------------------------------------------------------
    (defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
      DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace
      Mid$ Mid2$ NewText$ Num# SS& Text$)
    
    (defun i:wcmatch (string pattern)
      (wcmatch string (vl-string-subst "`#" "#" pattern)))
    
      ;-----------------------------------------------------------------------------
      ; FindReplace: - Returns Str$ with Find$ changed to Replace$
      ; Arguments: 3
      ;   Str$ = Text string
      ;   Find$ = Phrase string to find
      ;   Replace$ = Phrase to replace Find$ with
      ; Returns: Returns Str$ with Find$ changed to Replace$
      ;-----------------------------------------------------------------------------
      (defun FindReplace (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
        (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
        (while Loop
          (setq Mid$ (substr NewStr$ Cnt# FindLen#))
          (if (= Mid$ Find$)
            (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
                  Cnt# (+ Cnt# ReplaceLen#)
            );setq
            (setq Cnt# (1+ Cnt#))
          );if
          (if (= Mid$ "") (setq Loop nil))
        );while
        NewStr$
      );defun FindReplace:
      ;-----------------------------------------------------------------------------
      ; Start of Main function
      ;-----------------------------------------------------------------------------
      (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
        (progn
          (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
            (progn
              (setq Cnt# 0)
              (repeat (sslength SS&)
                (setq EntName^ (ssname SS& Cnt#)
                      EntList@ (entget EntName^)
                      EntType$ (cdr (assoc 0 EntList@))
                      Text$ (cdr (assoc 1 EntList@))
                );setq
                (if (= EntType$ "INSERT")
                  (if (assoc 66 EntList@)
                    (progn
                      (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
                        (setq EntList@ (entget EntName^))
                        (if (= (cdr (assoc 0 EntList@)) "ATTRIB")
                          (progn
                            (setq Text$ (cdr (assoc 1 EntList@)))
                            (if (i:wcmatch Text$ (strcat "*" Find$ "*"))
                              (progn
                                (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                                (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                                (entupd EntName^)
                              );progn
                            );if
                          );progn
                        );if
                        (setq EntName^ (entnext EntName^))
                      );while
                    );progn
                  );if
                  (if (i:wcmatch Text$ (strcat "*" Find$ "*"))
                    (progn
                      (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                      (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                      (entupd EntName^)
                    );progn
                  );if
                );if
                (setq Cnt# (1+ Cnt#))
              );repeat
            );progn
          );if
        );progn
      );if
      (princ)
    );defun FindReplaceAll
    Last edited by mburke.54112; 2010-06-09 at 12:00 PM. Reason: added modelspace only
    Michael
    CALYX Engineers + Consultants
    www.calyxengineers.com
    - Happiness is Wanting What You Have, Not Having What You Want -

  7. #7
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: globally change diagonal fractions to horizontal fractions

    What about simply doing the following:
    Code:
    (foreach n '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
      (foreach m '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
        (FindReplaceAll (strcat n "/" m) (strcat n "#" m))
      )
    )
    Should catch them all, and then some!
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  8. #8
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: globally change diagonal fractions to horizontal fractions

    Quote Originally Posted by irneb View Post
    What about simply doing the following:
    Code:
    (foreach n '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
      (foreach m '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
        (FindReplaceAll (strcat n "/" m) (strcat n "#" m))
      )
    )
    Should catch them all, and then some!
    Now that's using the noggin.
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  9. #9
    Member mburke.54112's Avatar
    Join Date
    2016-02
    Location
    NC
    Posts
    43
    Login to Give a bone
    0

    Thumbs up Re: globally change diagonal fractions to horizontal fractions

    Thanks irneb; finally had a chance to update the code with your suggestion. It does catch them all; and now don't have to keep adding to the fractions list.
    Below is the updated code for everyone's use:

    Code:
    ;;
    ;;Update Horizontal Fractions to Diagonal
    ;;
    (defun c:UFD ()
      (setq ztm (getvar "tilemode"))
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 1)
        )
      (foreach n '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
        (foreach m '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
          (FindReplaceAll (strcat n "/" m) (strcat n "#" m))
        )
      )
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 0)
        )
      (princ "\nChanged Horizontal Stacked dimensions to Diagonal Stacked.")
      (princ)
    );end defun C:UFD
    ;;
    ;;
    ;;Update Diagonal Fractions to Horizontal
    ;;
    (defun c:UFH ()
      (setq ztm (getvar "tilemode"))
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 1)
        )
      (foreach n '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
        (foreach m '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
          (FindReplaceAll (strcat n "#" m) (strcat n "/" m))
        )
      )
        (if (= ztm 0) ; tilemode 1=model space, 0=paper space
          (command "tilemode" 0)
        )
      (princ "\nChanged Diagonal Stacked dimensions to Horizontal Stacked.")
      (princ)
    );end defun C:UFH
    ;
    ;
    ;-------------------------------------------------------------------------------
    ; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
    ; that have a Find$ string with a Replace$ string.
    ; Arguments: 2
    ;   Find$ = Phrase string to find
    ;   Replace$ = Phrase to replace it with
    ; Syntax: (FindReplaceAll "|" "1/4")
    ; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
    ;-------------------------------------------------------------------------------
    (defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
      DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace
      Mid$ Mid2$ NewText$ Num# SS& Text$)
    
    (defun i:wcmatch (string pattern)
      (wcmatch string (vl-string-subst "`#" "#" pattern)))
    
      ;-----------------------------------------------------------------------------
      ; FindReplace: - Returns Str$ with Find$ changed to Replace$
      ; Arguments: 3
      ;   Str$ = Text string
      ;   Find$ = Phrase string to find
      ;   Replace$ = Phrase to replace Find$ with
      ; Returns: Returns Str$ with Find$ changed to Replace$
      ;-----------------------------------------------------------------------------
      (defun FindReplace (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
        (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
        (while Loop
          (setq Mid$ (substr NewStr$ Cnt# FindLen#))
          (if (= Mid$ Find$)
            (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
                  Cnt# (+ Cnt# ReplaceLen#)
            );setq
            (setq Cnt# (1+ Cnt#))
          );if
          (if (= Mid$ "") (setq Loop nil))
        );while
        NewStr$
      );defun FindReplace:
      ;-----------------------------------------------------------------------------
      ; Start of Main function
      ;-----------------------------------------------------------------------------
      (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
        (progn
          (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
            (progn
              (setq Cnt# 0)
              (repeat (sslength SS&)
                (setq EntName^ (ssname SS& Cnt#)
                      EntList@ (entget EntName^)
                      EntType$ (cdr (assoc 0 EntList@))
                      Text$ (cdr (assoc 1 EntList@))
                );setq
                (if (= EntType$ "INSERT")
                  (if (assoc 66 EntList@)
                    (progn
                      (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
                        (setq EntList@ (entget EntName^))
                        (if (= (cdr (assoc 0 EntList@)) "ATTRIB")
                          (progn
                            (setq Text$ (cdr (assoc 1 EntList@)))
                            (if (i:wcmatch Text$ (strcat "*" Find$ "*"))
                              (progn
                                (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                                (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                                (entupd EntName^)
                              );progn
                            );if
                          );progn
                        );if
                        (setq EntName^ (entnext EntName^))
                      );while
                    );progn
                  );if
                  (if (i:wcmatch Text$ (strcat "*" Find$ "*"))
                    (progn
                      (setq ReplaceWith$ (FindReplace Text$ Find$ Replace$))
                      (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                      (entupd EntName^)
                    );progn
                  );if
                );if
                (setq Cnt# (1+ Cnt#))
              );repeat
            );progn
          );if
        );progn
      );if
      (princ)
    );defun FindReplaceAll
    Michael
    CALYX Engineers + Consultants
    www.calyxengineers.com
    - Happiness is Wanting What You Have, Not Having What You Want -

Similar Threads

  1. 2014: Converting all fractions in all text selected to stacked fractions
    By mbrandt5 in forum AutoCAD General
    Replies: 2
    Last Post: 2015-06-10, 09:42 PM
  2. Global Change of Fractions
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2008-10-12, 06:31 PM
  3. Find and Replace stacked diagonal fractions?
    By tedg in forum AutoCAD General
    Replies: 1
    Last Post: 2006-12-14, 05:09 PM
  4. Can I change unit fractions to decimals in different views?
    By michael.118924 in forum Revit Architecture - General
    Replies: 4
    Last Post: 2006-08-11, 07:49 PM
  5. dim text...yet again :s (horizontal fractions)
    By smdin79 in forum AutoCAD LT - General
    Replies: 2
    Last Post: 2005-05-09, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •