Results 1 to 4 of 4

Thread: Predefining a find and replace

  1. #1
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Predefining a find and replace

    So I found this code that allows me to find and replace fractions with stacked fractions
    I'm wondering if there is a way that I can predefine the fractions that the code searches for and if anyone would be willing to help me do so...

    So it would have to implicate something like

    Code:
    (IF(osi=1/4, 1/2, 1/8)
      (Setq nsi={\H0.75x;\S1#4;}, {\H0.75x;\S1#2;}, {\H0.75x;\S1#8;})

    Now obviously I don't know the syntax for the above code seeing I've done bare minimal with lisp a while ago

    Here is the code currently

    Code:
    (defun c:superstr()
        (setq olsosmode (getvar "OSMODE"))
        (setvar "OSMODE" 0)
        (setq p (ssget))  
        (if p
     (progn
                (setq osl (strlen (setq os (getstring "\nOld string: " t))))
                (setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
         (setq l 0 chm 0 n (sslength p))
         (setq adj
      (cond
          ((/= osl nsl) (- nsl osl))
          (T nsl)
      )
         )
     (while (< l n)                  
         (setq d (entget (setq e (ssname p l))))
         (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
      (progn
          (setq e (entnext e))
          (while e
       (setq d (entget e))
       (cond
           ((= (atext 0) "ATTRIB")
        (setq chf nil si 1)
        (setq s (cdr (setq as (assoc 1 d))))
        (while (= osl (setq sl (strlen
            (setq st (substr s si osl)))))
            (cond
         ((= st os)
             (setq s (strcat (substr s 1 (1- si)) ns
             (substr s (+ si osl))))
             (setq chf t)
             (setq si (+ si adj))
         )
            )
        (setq si (1+ si))
           )
           (if chf
        (progn       
            (setq d (subst (cons 1 s) as d))
            (entmod d)       
            (entupd e)       
            (setq chm (1+ chm))
        )
           )
           (setq e (entnext e))
           )
           ((= (atext 0) "SEQEND")
        (setq e nil))
           (T (setq e (entnext e)))
                            )
          )
      )
         )
                (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
                   (cdr (assoc 0 (setq e (entget (ssname p l))))))
                      (progn
                         (setq chf nil si 1)
                         (setq s (cdr (setq as (assoc 1 e))))
                         (while (= osl (setq sl (strlen
                            (setq st (substr s si osl)))))
                            (if (= st os)
                               (progn
                                  (setq s (strcat (substr s 1 (1- si)) ns
                                            (substr s (+ si osl))))
                               (setq chf t) ; Found old string
                            (setq si (+ si nsl))
                          )
                          (setq si (1+ si))
                      )
                   )
                   (if chf (progn        ; Substitute new string for old
                      (setq e (subst (cons 1 s) as e))
                      (entmod e)         ; Modify the TEXT entity
                      (setq chm (1+ chm))
                   ))
                )
             )
         (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
                   (cdr (assoc 0 (setq e (entget (ssname p l))))))
                      (progn
                         (setq chf nil si 1)
                         (setq s (cdr (setq as (assoc 1 e))))
                         (while (= osl (setq sl (strlen
                            (setq st (substr s si osl)))))
                            (if (= st os)
                               (progn
                                  (setq s (strcat (substr s 1 (1- si)) ns
                                            (substr s (+ si osl))))
                               (setq chf t) ; Found old string
                            (setq si (+ si nsl))
                          )
                          (setq si (1+ si))
                      )
                   )
                   (if chf (progn        ; Substitute new string for old
                      (setq e (subst (cons 1 s) as e))
                      (entmod e)         ; Modify the TEXT entity
                      (setq chm (1+ chm))
                   ))
                )
             )
         (if (= "TEXT"            ; Look for TEXT entity type (group 0)
                   (cdr (assoc 0 (setq e (entget (ssname p l))))))
                      (progn
                         (setq chf nil si 1)
                         (setq s (cdr (setq as (assoc 1 e))))
                         (while (= osl (setq sl (strlen
                            (setq st (substr s si osl)))))

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Predefining a find and replace

    Please post a link to where you found it.

  3. #3
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Re: Predefining a find and replace


  4. #4
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Re: Predefining a find and replace

    Sorry, I realized that I didn't post the full code originally... so here it is

    Code:
    (defun c:superstr()
        (setq olsosmode (getvar "OSMODE"))
        (setvar "OSMODE" 0)
        (setq p (ssget))  
        (if p
     (progn
                (setq osl (strlen (setq os (getstring "\nOld string: " t))))
                (setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
         (setq l 0 chm 0 n (sslength p))
         (setq adj
      (cond
          ((/= osl nsl) (- nsl osl))
          (T nsl)
      )
         )
     (while (< l n)                  
         (setq d (entget (setq e (ssname p l))))
         (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
      (progn
          (setq e (entnext e))
          (while e
       (setq d (entget e))
       (cond
           ((= (atext 0) "ATTRIB")
        (setq chf nil si 1)
        (setq s (cdr (setq as (assoc 1 d))))
        (while (= osl (setq sl (strlen
            (setq st (substr s si osl)))))
            (cond
         ((= st os)
             (setq s (strcat (substr s 1 (1- si)) ns
             (substr s (+ si osl))))
             (setq chf t)
             (setq si (+ si adj))
         )
            )
        (setq si (1+ si))
           )
           (if chf
        (progn       
            (setq d (subst (cons 1 s) as d))
            (entmod d)       
            (entupd e)       
            (setq chm (1+ chm))
        )
           )
           (setq e (entnext e))
           )
           ((= (atext 0) "SEQEND")
        (setq e nil))
           (T (setq e (entnext e)))
                            )
          )
      )
         )
                (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
                   (cdr (assoc 0 (setq e (entget (ssname p l))))))
                      (progn
                         (setq chf nil si 1)
                         (setq s (cdr (setq as (assoc 1 e))))
                         (while (= osl (setq sl (strlen
                            (setq st (substr s si osl)))))
                            (if (= st os)
                               (progn
                                  (setq s (strcat (substr s 1 (1- si)) ns
                                            (substr s (+ si osl))))
                               (setq chf t) ; Found old string
                            (setq si (+ si nsl))
                          )
                          (setq si (1+ si))
                      )
                   )
                   (if chf (progn        ; Substitute new string for old
                      (setq e (subst (cons 1 s) as e))
                      (entmod e)         ; Modify the TEXT entity
                      (setq chm (1+ chm))
                   ))
                )
             )
         (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
                   (cdr (assoc 0 (setq e (entget (ssname p l))))))
                      (progn
                         (setq chf nil si 1)
                         (setq s (cdr (setq as (assoc 1 e))))
                         (while (= osl (setq sl (strlen
                            (setq st (substr s si osl)))))
                            (if (= st os)
                               (progn
                                  (setq s (strcat (substr s 1 (1- si)) ns
                                            (substr s (+ si osl))))
                               (setq chf t) ; Found old string
                            (setq si (+ si nsl))
                          )
                          (setq si (1+ si))
                      )
                   )
                   (if chf (progn        ; Substitute new string for old
                      (setq e (subst (cons 1 s) as e))
                      (entmod e)         ; Modify the TEXT entity
                      (setq chm (1+ chm))
                   ))
                )
             )
         (if (= "TEXT"            ; Look for TEXT entity type (group 0)
                   (cdr (assoc 0 (setq e (entget (ssname p l))))))
                      (progn
                         (setq chf nil si 1)
                         (setq s (cdr (setq as (assoc 1 e))))
                         (while (= osl (setq sl (strlen
                            (setq st (substr s si osl)))))
                            (if (= st os)
                               (progn
                                  (setq s (strcat (substr s 1 (1- si)) ns
                                            (substr s (+ si osl))))
                               (setq chf t) ; Found old string
                            (setq si (+ si nsl))
                          )
                          (setq si (1+ si))
                      )
                   )
                   (if chf (progn        ; Substitute new string for old
                      (setq e (subst (cons 1 s) as e))
                      (entmod e)         ; Modify the TEXT entity
                      (setq chm (1+ chm))
                   ))
                )
             )
         (setq l (1+ l))
     )
     )
        )
        (if (> chm 1)
           (princ (strcat "\nUpdated " (itoa chm) " text strings"))
           (princ (strcat "\nUpdated " (itoa chm) " text string"))
        )
        (setvar "OSMODE" oldosmode)
        (terpri)
    )
    ;
    (defun atext (num)
       (cdr (assoc num d))
    )
    Also someone on another forum suggested that i could utilize this function...I'm just not sure where to put it within the code and what part of the code i would need to delete in the process...

    Code:
    (if (vl-string-search "/" os)
      (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))

Similar Threads

  1. Find and Replace
    By Danny Polkinhorn in forum Revit - API
    Replies: 93
    Last Post: 2010-07-29, 07:10 PM
  2. Find and replace
    By eric_keneson2 in forum AutoLISP
    Replies: 1
    Last Post: 2010-02-09, 04:26 PM
  3. Find and Replace
    By RMEYER.46723 in forum AutoCAD Civil 3D - General
    Replies: 5
    Last Post: 2009-06-09, 01:53 AM
  4. Find and Replace
    By U.Rackharrow in forum AutoCAD General
    Replies: 9
    Last Post: 2007-10-16, 02:44 PM
  5. Find / Replace
    By gs in forum Revit Architecture - General
    Replies: 3
    Last Post: 2005-12-09, 07:16 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
  •