+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Junior Member Arepo's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Posts
    10

    Idea MText command in LISP

    Registered forum members do not see this ad.

    I am trying to write a routine to "simulate" MText command in lisp using predefined Text Height (2.0mm in this case for 1:1 scale) and text Style. I started with this code:

    Code:
    (defun C:test (/ Height Style)
    	(setvar "cmdecho" 1)
    	(setq Height (* (getvar "DIMSCALE") 2.0 ))
    	(setq Style "My_Style")
    	(command "._MTEXT" pause "H" Height "S" Style pause)
     	(princ)
    )
    The text style seems to work but the Text Height doesn't change.
    Could anyone help please?
    Last edited by Arepo; 9th Jul 2012 at 11:17 pm.

  2. #2
    Senior Member
    Computer Details
    rickh's Computer Details
    Operating System:
    W7 x64
    RAM:
    8G
    Graphics:
    1G
    Discipline
    Structural
    rickh's Discipline Details
    Occupation
    Designer
    Discipline
    Structural
    Using
    Civil 3D 2011
    Join Date
    Feb 2011
    Location
    Houston
    Posts
    152

    Default

    Is (getvar "textsize") what you need instead of dimscale? You also have to ensure the text style used does not have a predefined height.
    From F1 help for textsize:
    Sets the default height for new text objects drawn with the current text style.
    TEXTSIZE has no effect if the current text style has a fixed height.

    -edit- if you just want the height to be 2.0, enter "2.0" instead of Height in your (command... ) line. Right now it is setting the value of Height to 2 times the current dimscale.

  3. #3
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Code:
    (defun c:Test (/ str p)
      (if (and (not (eq (setq str (getstring t "\n Type text string :")) ""))
           (setq p (getpoint "\n Specify Text location :"))
          )
        (entmake (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText")
               (cons 10 p)
               (cons 40 (* (getvar "DIMSCALE") 2.0))
               (cons 7 (if (tblsearch "STYLE" "My_Style")  "My_Style"   "Standard" ))
               (cons 1 str)
             )
        )
      )
      (princ)
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  4. #4
    Junior Member Arepo's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Posts
    10

    Default

    What I am trying is to write a set of commands for different text styles and sizes. The text styles to be used are already loaded in the drawing template. Of course, text size should depend on DIMSCALE. I want the command to look as close to AutoCAD Mtext command as possible (have the Text Formatting box and the ability to write text on multiple lines). Something simple like MTEXT (MT) command I tried above, only having text style and text size predefined so I won't have to change them for different texts I'm using.
    Rickh: The text styles I'm using don't have a predefined text height and I need text height depending on DIMSCALE so I have the right text size in Paper Space.
    Tharwat: thank you for your code, works well but gives me the option to write text on one line only. Could you tell me why the code I tried doesn't work properly?

  5. #5
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Quote Originally Posted by Arepo View Post
    Tharwat: thank you for your code, works well but gives me the option to write text on one line only.
    Try this ....

    Code:
    (defun c:Test (/ lst st p)
      (while (not (eq (setq st (getstring t "\n Type text string :")) "")
             )
        (setq lst (cons (strcat st "\\P") lst))
      )
      (if (setq p (getpoint "\n Specify Text location :"))
        (entmake (list '(0 . "MTEXT")
                       '(100 . "AcDbEntity")
                       '(100 . "AcDbMText")
                       (cons 10 p)
                       (cons 40 (* (getvar "DIMSCALE") 2.0))
                       (cons 7
                             (if (tblsearch "STYLE" "My_Style")
                               "My_Style"
                               "Standard"
                             )
                       )
                       (cons 1 (apply 'strcat (reverse lst)))
                 )
        )
      )
      (princ)
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  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,729

    Default

    An alternative method:

    Code:
    (defun c:mtx ( / e h p s )
    
        (setq s "My_Style"
              h (* 2 (getvar 'dimscale))
        )    
        (if (setq p (getpoint "\nPoint for MText: "))
            (progn
                (setq e
                    (entmakex
                        (list
                           '(0 . "MTEXT")
                           '(100 . "AcDbEntity")
                           '(100 . "AcDbMText")
                           '(1 . "")
                            (cons 10 (trans p 1 0))
                            (cons 40 h)
                            (cons 07 (if (tblsearch "STYLE" s) s "Standard"))
                        )
                    )
                )
                (command "_.mtedit" e)
            )
        )
        (princ)
    )
    Lee Mac Programming

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

    Just another Swamper

  7. #7
    Junior Member Arepo's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Posts
    10

    Default

    [QUOTE=Lee Mac;484697]An alternative method:

    That's exactly what I was looking for. I like having the Text Formatting window. It turned out to be more complicated code than I thought
    Thank you very much!

  8. #8
    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,729

    Default

    You're very welcome Arepo
    Lee Mac Programming

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

    Just another Swamper

  9. #9
    Junior Member Arepo's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Posts
    10

    Default

    Thank you Tharwat, this works nicely.

  10. #10
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Arepo View Post
    Thank you Tharwat, this works nicely.
    No problem ..
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

Similar Threads

  1. Using Lisp to Explode Mtext?
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 17th Nov 2010, 09:19 pm
  2. Use lisp to put text into mtext box
    By bgator220 in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 3rd Oct 2010, 07:58 pm
  3. Replies: 2
    Last Post: 31st Aug 2010, 06:53 pm
  4. Ending MText Lisp command
    By pracslipkerm in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 6th Aug 2010, 03:31 am
  5. Can Lisp use mtext to make multi string mtext editor?
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 18th Dec 2006, 03:22 am

Tags for this Thread

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