Results 1 to 5 of 5

Thread: AutoCAD Lisp For Replacing Text With A Block

  1. #1
    Member
    Join Date
    2020-10
    Posts
    2
    Login to Give a bone
    0

    Default AutoCAD Lisp For Replacing Text With A Block

    Hi All,

    I hope I am on the right forum.

    I have been looking for a lisp routine that will replace multiple text entities with a block.
    The block should be at the same insertion point as the text and the same rotation.

    I found similar threads online, but not quite the same thing.

    Does anyone have a routine to share?

    I am not able to write the routine myself, so I was looking for an existing one.

    Kind Regards,
    WayneSA

  2. #2
    Active Member
    Join Date
    2015-12
    Location
    Western Europe
    Posts
    57
    Login to Give a bone
    0

    Default Re: AutoCAD Lisp For Replacing Text With A Block

    You'll need to be more specific? Text and/or MText? What happens if the *Text is justified? Is the block static or dynamic? Does it have attributes? How do you want to select the *Text? Is the *Text on a single layer or Multiple layers?

  3. #3
    Member
    Join Date
    2001-03
    Location
    ROMANIA
    Posts
    35
    Login to Give a bone
    0

    Default Re: AutoCAD Lisp For Replacing Text With A Block

    Quote Originally Posted by waynekay24792565 View Post
    Hi All,

    I hope I am on the right forum.

    I have been looking for a lisp routine that will replace multiple text entities with a block.
    The block should be at the same insertion point as the text and the same rotation.

    I found similar threads online, but not quite the same thing.

    Does anyone have a routine to share?

    I am not able to write the routine myself, so I was looking for an existing one.

    Kind Regards,
    WayneSA
    Try this:
    Code:
    ;;liviu_dova@yahoo.com
    (vl-load-com)
    (DEFUN C:REP-TXBK (/ *error* $Name bName EgEnt ENT lsBlN)
      (defun *error* (s)
        (or (wcmatch (strcase s) "*BREAK,*CANCEL*,*EXIT*") (prompt (strcat "\nError: " s)))
        (princ)
      ) ;;*error*
    ;List of block names
      (vlax-for
         itm
        (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
        (if (and
              (vlax-property-available-p itm "Name")
              (/= (substr (setq $Name (vla-get-name itm)) 1 1) "*")
            )
          (setq lsBlN (cons $Name lsBlN))
        )
      )
      (if lsBlN
        (progn
    ;;Choose the block
          (while (not bName)
            (setq bName (getstring T "\nEnter block name or [?]: "))
            (cond
              ( (= bName "?")
                (textscr)
                (prompt "\nDefined blocks:")
                (foreach el lsBlN (prompt (strcat "\n" el)))
                (prompt "\nClick or Press any key to continue...")
                (vl-catch-all-apply (function grread) (list nil 14 0))
                (setq bName (graphscr))
              )
              ( (= bName "")
                (setq bName nil)
              )
              ( (and bName  (not (vl-position (strcase bName) (mapcar (function strcase) lsBlN))))
                (setq bName (prompt (strcat "\nCould not find block name \"" bName "\".")))
              )
              (T nil)
            )
          )
    ;;Choose the text and replace it with the choosed block.
          (while  (and  (setq ENT (car (entsel "\nSelect the text to be replaced: ")))
                        (= (cdr (assoc 0 (setq EgEnt (entget ENT)))) "TEXT")
                  )
            (if (= (logand 4 (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 EgEnt))))))) 0) ;;Layer not locked
              (progn
                (entdel ENT)
                (entmake
                  (list
                    (quote (0 . "INSERT"))
                    (quote (100 . "AcDbEntity"))
                    (cons 67  (cdr (assoc 67  EgEnt)))
                    (cons 410 (cdr (assoc 410 EgEnt)))
                    (cons 8   (cdr (assoc 8   EgEnt)))
                    (quote (100 . "AcDbBlockReference"))
                    (cons 2 bName)
                    (cons 10 (cdr (assoc 10 EgEnt)))
                    (cons 50 (cdr (assoc 50 EgEnt)))
                  )
                )
              )
              (prompt "\nText is on a locked layer.")
            )
          )
        )
        (prompt "\nNo block definitions in the drawing.")
      )
      (princ)
    ) ;;REP-TXBK

  4. #4
    Member
    Join Date
    2020-10
    Posts
    2
    Login to Give a bone
    0

    Default Re: AutoCAD Lisp For Replacing Text With A Block

    Hi, the routine runs initially but stalls at text selection. The text is single line text; justified at middle centre. Text is all on the same layer and unlocked. The block is just static. Thanks for commenting. Regards, Wayne.

  5. #5
    Member
    Join Date
    2001-03
    Location
    ROMANIA
    Posts
    35
    Login to Give a bone
    0

    Default Re: AutoCAD Lisp For Replacing Text With A Block

    Quote Originally Posted by waynesa View Post
    Hi, the routine runs initially but stalls at text selection. The text is single line text; justified at middle centre. Text is all on the same layer and unlocked. The block is just static. Thanks for commenting. Regards, Wayne.
    I checked the program for the middle center text justification and it works. Please attach a drawing (maximum rel. 2015) and the name of the block to be inserted.

Similar Threads

  1. Replacing a title block
    By pdstro in forum AutoLISP
    Replies: 0
    Last Post: 2018-11-18, 05:28 AM
  2. Replacing blocks with a block with the same name
    By Wish List System in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2013-10-28, 12:22 PM
  3. Replacing Text
    By masonjur in forum Revit Architecture - General
    Replies: 2
    Last Post: 2006-08-28, 03:46 PM
  4. LISP for selecting block and replacing with another
    By ken_nofuente in forum AutoLISP
    Replies: 2
    Last Post: 2006-06-29, 04:53 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
  •