Results 1 to 5 of 5

Thread: Insert block for text lisp

  1. #1
    Member
    Join Date
    2005-09
    Posts
    3
    Login to Give a bone
    0

    Default Insert block for text lisp

    Is there some lisp routine that will insert a block in place of a certain font? The block would have to match the text size, insertion point and rotation. A couple of years ago I received a lisp routine that's close to this but needs a little fine tuning. It seems to get the rotation right but the insertion point is off. Also the block comes in at it's regular size of 1 versus what the text size actually is. This is what I have so far:

    Code:
    (defun c:txttoblk( / ss)
    (vl-load-com)
    (setq blk "TREE") ; Put block name here, with directory if block is not already in drawing
    (setq ss (ssget "X" '((0 . "TEXT")(1 . "N"))))
    (if ss
    (progn
    (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
    (mapcar '(lambda (x) (vl-cmdf "-insert" blk (cdr (assoc 10 (entget x))) 1 1 (* (/ 180 pi) (cdr (assoc 50 (entget x)))))
    (entdel x)) ss)
    )
    (princ "\nNo text entities found.")
    )
    (princ)
    )
    This goes back to converting a Microstation file to an Autocad file. The company has a Microstation font that when brought into Autocad changes to the letter 'N'. The 'N's are different sizes and rotation angles. When there are a thousand or so of these it makes it impractical to insert a block at each 'N' location plus of course change size and rotation. And putting this rsc file with Microstation's font into Autocad's working path does not seem to help.

    Thanks to anyone that could come up with a better solution.

    - Bob
    Last edited by rkmcswain; 2017-03-28 at 07:37 PM. Reason: added [CODE] tags

  2. #2
    Member
    Join Date
    2005-09
    Posts
    3
    Login to Give a bone
    0

    Default Re: Insert block for text lisp

    After much searching I found something on another site that is close to what I need. But the insertion point, which works perfectly with the original lisp (txttoblk1), does not come in exactly in the txttoblk2 lisp:

    Code:
    (defun c:txttoblk2( / ss e)
      (vl-load-com)
      (setq blk "TREE") ; Put block name here, with directory if block is not already in drawing
      (setq ss (ssget "X" '((0 . "TEXT")(1 . "N"))))
      (if ss
        (progn
          (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
          (mapcar '(lambda (x)
             (setq e (entget x))
             (entmake
               (append
                 (list (cons 0 "INSERT") (cons 100 "AcDbEntity") (cons 100 "AcDbBlockReference")
                   (cons 410 (cdr (assoc 410 e)))
                   (cons 8 (cdr (assoc 8 e)))
                   (cons 2 blk)
                   (cons 10 (cdr (assoc 10 e)))
                   (cons 41 (* (/ 0.0912 3) (cdr (assoc 40 e))))
                   (cons 42 (* (/ 0.0912 3) (cdr (assoc 40 e))))
                   (cons 50 (cdr (assoc 50 e))))
                 )
               )
             (entdel x)) ss)
          )
        (princ "\nNo text entities found.")
        )
      (princ)
      )
    So I tried to combine the first lisp, that the insertion point worked in, with the second lisp, that worked with placing the block at a specific size relating to the text size. But somewhere I messed up combing the two and cannot get it to work. Can anyone see where this problem lies?

    My combined file (#3):

    Code:
    (defun c:txttoblk3( / ss)
    (vl-load-com)
    (setq blk "TREE") ; Put block name here, with directory if block is not already in drawing
    (setq ss (ssget "X" '((0 . "TEXT")(1 . "N"))))
    (if ss
    (progn
    (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
    (mapcar '(lambda (x) (vl-cmdf "-insert" blk (cdr (assoc 10 (entget x))) 1 1 (* (/ 180 pi) (cdr (assoc 50 (entget x)))))
             (entmake
               (append
                 (list (cons 0 "INSERT") (cons 100 "AcDbEntity") (cons 100 "AcDbBlockReference")
                   (cons 410 (cdr (assoc 410 e)))
                   (cons 8 (cdr (assoc 8 e)))
                   (cons 2 blk)
                   (cons 10 (cdr (assoc 10 e)))
                   (cons 41 (* (/ 0.0912 3) (cdr (assoc 40 e))))
                   (cons 42 (* (/ 0.0912 3) (cdr (assoc 40 e))))
                   (cons 50 (cdr (assoc 50 e))))
                 )
               )
             (entdel x)) ss)
          )
        (princ "\nNo text entities found.")
        )
      (princ)
      )
    Including drawing that I have been testing with.

    Thanks,
    -Bob
    Attached Files Attached Files
    Last edited by rkmcswain; 2017-03-29 at 03:31 PM. Reason: added [CODE] tags

  3. #3
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Insert block for text lisp

    Please attach your dwg in e-transmit way. So the font you use will be loaded with the DWG

  4. #4
    Member
    Join Date
    2005-09
    Posts
    3
    Login to Give a bone
    0

    Default Re: Insert block for text lisp

    Just getting back into office. I found a lisp that's different from the above ones but worked to perfection with a few tweaks. It takes the converted Microstation font and replaces it with a tree block that will match the rotation, insertion point and very close to the size of the Microstation font. The Microstation font actually had a tree block inside it somehow but in the Autocad converted file it just showed the letter 'N'. So this thread can be ended as I have found a result. Thank you.

  5. #5
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Insert block for text lisp

    Ok . Feel free to ask for further help.

Similar Threads

  1. Block Insert Lisp Problem
    By nturley369932 in forum AutoLISP
    Replies: 3
    Last Post: 2014-10-17, 05:41 PM
  2. insert block using pickbox (lisp)
    By mitchellvoss in forum AutoLISP
    Replies: 2
    Last Post: 2014-01-17, 12:10 PM
  3. Simple Lisp To Insert Block
    By omorah in forum AutoCAD Customization
    Replies: 4
    Last Post: 2013-04-12, 09:06 PM
  4. Lisp. Insert block and text in Cell
    By iv.mybox755952 in forum AutoLISP
    Replies: 11
    Last Post: 2012-03-07, 06:22 AM
  5. Using LISP to insert a Dynamic block
    By Ferroequine in forum Dynamic Blocks - Technical
    Replies: 10
    Last Post: 2010-03-25, 02:23 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
  •