+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Forum Newbie
    Using
    AutoCAD 2010
    Join Date
    Oct 2009
    Posts
    4

    Default Lisp to find and replace text of a certain font.

    Registered forum members do not see this ad.

    On some projects we work in Solid Edge, and then translate the drawings to AutoCAD for the customer. When Solid Edge is installed on a machine it installs certain fonts, one of which is a symbols font for Geometric Tolerances. If a customer opens the autocad translation they can't see the geo tol symbols because they don't have the fonts on their machines. Some are ok with us sending them the fonts, others are not. So I'd like to write a lisp that would change the style to use the autocad gdt font, after finding and replacing the text of the solid edge font with the letters that the autocad gdt font uses. This will have to work within blocks and probably mtext. So I would need to be able to find and replace single letters that only occur on a certain text style, so all the letters in the drawing aren't replaced.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    You could select all Text/MText of a certain TextStyle using:

    Code:
    (ssget "_X" '((0 . "TEXT,MTEXT") (7 . "YourTextStyleHere")))
    Or perhaps all Text/MText of a certain style, and all attributed blocks:

    Code:
    (ssget "_X"
     '(
        (-4 . "<OR")
          (-4 . "<AND")
            (0 . "TEXT,MTEXT")
            (7 . "YourTextStyleHere")
          (-4 . "AND>")
          (-4 . "<AND")
            (0 . "INSERT")
            (66 . 1)
          (-4 . "AND>")
        (-4 . "OR>")
      )
    )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Forum Newbie
    Using
    AutoCAD 2010
    Join Date
    Oct 2009
    Posts
    4

    Default

    Will the first one work for text within non-attributed blocks?

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    Quote Originally Posted by mikeSIEMENS View Post
    Will the first one work for text within non-attributed blocks?
    No, ssget will only select primary entities, for text entities within blocks you will need to look through and modify the block definition within the block table.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Forum Newbie
    Using
    AutoCAD 2010
    Join Date
    Oct 2009
    Posts
    4

    Default

    Now how do I find & replace within the selection set.

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    If you wanted to dig through block definitions, this would be how I might approach it:

    Code:
    (defun GetBlockEntities ( block / lst )
      (reverse
        (if (setq block (tblobjname "BLOCK" block))
          (while (setq block (entnext block))
            (setq lst (cons block lst))
          )
        )
      )
    )
    Or recursively,
    Code:
    (defun GetBlockEntities ( block )
    
      (defun EntnextToEnd ( e )
        (if (setq e (entnext e))
          (cons e (EntnextToEnd e))
        )
      )
    
      (if (setq block (tblobjname "BLOCK" block))
        (EntnextToEnd block)
      )
    )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by mikeSIEMENS View Post
    Now how do I find & replace within the selection set.
    Well, first you'd have to iterate through the items in the selection set using a loop construct coupled with ssname perhaps.

    Then, there are many ways to perform the replacement - you could use substr to look through each character individually, or vl-string-subst within a loop to account for all occurrences, or even RegularExpressions using the RegExp object.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. The Best Text Find And Replace LISP Ever...
    By Freerefill in forum AutoLISP, Visual LISP & DCL
    Replies: 23
    Last Post: 14th Jul 2011, 02:04 am
  2. Find & Replace Text
    By drewd1508 in forum AutoLISP, Visual LISP & DCL
    Replies: 25
    Last Post: 19th Mar 2010, 09:57 pm
  3. Find & Replace Automation -- Need Lisp
    By jamathi in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 22nd Feb 2010, 06:51 pm
  4. Find & Replace Text
    By happyunited in forum AutoCAD General
    Replies: 14
    Last Post: 4th Aug 2009, 05:44 pm
  5. Find/Replace text?
    By Ste1978 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 16th Nov 2007, 03:28 pm

Bookmarks

Posting Permissions

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