+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Dec 2008
    Location
    NS CANADA
    Posts
    10

    Default insert text from a lisp

    Registered forum members do not see this ad.

    is it possible to insert text automatically from a lisp,
    I tried this but does not work....

    Code:
    (command "dtext" 
         pt1 ; variable for insertion point
     
                "" ; scale
                "" ; rotation
         pt1Z ; variable for text
         ""
    I got the cursor to insert the text manually,
    Last edited by SLW210; 18th Jan 2013 at 02:45 pm.

  2. #2
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    Windows 7 Professional
    Computer:
    Dell
    CPU:
    Intel Xeon E5-1603@2,80GHz
    RAM:
    4GB
    Graphics:
    NVIDA Quadro K600
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,535

    Default

    I think you have to precede the variables with a !

    Code:
    (command "DTEXT" !pt1 "" "" "my text" "")
    you may also need a "" for text height.
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson
    "Everything in drafting is logical. Except what isn’t." - Gavin Guile. (from the Lightbringer series of books by Brent Weeks)

    Dave

  3. #3
    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
    16,882

    Default

    Hi morgos, and welcome to CADtutor,

    If I were you, I would use entmake to insert your text, as it is far more reliable. - sometimes the in-built ACAD text insertor will assume a text height or rotation or both, hence screwing with the order of your prompts.
    Last edited by Lee Mac; 23rd Dec 2008 at 01:48 am.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  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
    16,882

    Default

    Something like this:

    Code:
    (defun c:txt (/ *error* varlist oldvars pt1 tval)
        (defun *error* (msg)
        (mapcar 'setvar varlist oldvars)
        (if (= msg "")
            (princ "\nText Inserted.")
            (princ "\nEsc or Error Pressed...")
        ) ;_  end if
        (princ)
        ) ;_  end defun
        (setq varlist (list "CMDECHO" "CLAYER")
          oldvars (mapcar 'getvar varlist)
        ) ;_  end setq
        (while (and    (/= (setq pt1 (getpoint "\nSelect Insertion Point: ")) nil)
            (/= (setq tval (getstring t "\nSpecify Text: ")) "")
           ) ;_  end and
        (if (not (tblsearch "Layer" "TEXT"))
            (command "-layer" "m" "TEXT" "")
        ) ;_  end if
        (entmake (list '(0 . "TEXT")
                   '(8 . "TEXT") ; Change this for different Layer (type layer name in quote marks)
                   (cons 10 pt1)
                   (cons 40 (getvar "TEXTSIZE")) ; Change this for different height (set at default text size, change all red parts to just a number, i.e. (cons 40 2.5)
                   (cons 1 tval)
                   '(50 . 0.0)
                   '(7 . "STANDARD") ; change this for different Text Style (type style name in quote marks)
                   '(71 . 0)
                   '(72 . 0)
                   '(73 . 0)
             ) ;_  end list
        ) ;_  end entmake
        ) ;_  end while
        (*error* "")
        (princ)
    ) ;_  end defun
    Remove the blue lines if you do not wish for a Text layer to be created (if there isn't a TEXT layer already), and change the red parts to suit your needs accordingly
    Last edited by Lee Mac; 23rd Dec 2008 at 01:51 am.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  5. #5
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,144

    Default

    here's the 2 subroutines i use:
    MTEXT
    Code:
    (defun makeMTEXT (pt txt width txtsize / entl)
      (setq entl (list
                   '(0 . "MTEXT")
                   '(100 . "AcDbEntity")
                   '(100 . "AcDbMText")
                   (cons 10 pt)
       &nb22)
                    (cons 1 val2)
                    (cons 7 tstyle)
                    (cons 10 p1)
                    (cons 40 theight)
                    (cons 41 1)
                    (cons 50 0)
             )
      )
      (entmake txt1)
    )

  6. #6
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    803

    Default

    I too would use entmakex but to use the command use this:
    Code:
     ;; If text height is undefined (signified by 0 in the table) 
      (if (zerop (cdr(assoc 40(tblsearch "style" (getvar "textstyle")))))
        ;; Draw the text using the current text height (textsize) 
        (command ".text" "c" "_non" txtpt "" L_Angle txt)
        ;; Otherwise use the defined text height 
        (command ".text" "c" "_non" txtpt L_Angle txt)
      ) ; endif

  7. #7
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Dec 2008
    Location
    NS CANADA
    Posts
    10

    Default

    thanks all for the quick reply,
    I just started my working day,
    thanks Lee for your neat and complete code,
    I will try all this later in the day,


    Morgos.

  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
    16,882

    Default

    Quote Originally Posted by CAB View Post
    I too would use entmakex but to use the command use this:
    Code:
     ;; If text height is undefined (signified by 0 in the table) 
      (if (zerop (cdr(assoc 40(tblsearch "style" (getvar "textstyle")))))
        ;; Draw the text using the current text height (textsize) 
        (command ".text" "c" "_non" txtpt "" L_Angle txt)
        ;; Otherwise use the defined text height 
        (command ".text" "c" "_non" txtpt L_Angle txt)
      ) ; endif
    Nice one CAB, a smaller and simpler solution to my LISP - but what is the difference between entmakex and entmake?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  9. #9
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    803

    Default

    Love those questions.

    entmake returns a partial entity list while entmakex returns the ent name.
    I find that more useful.

  10. #10
    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
    16,882

    Default

    Registered forum members do not see this ad.

    Ok, Thanks

    Does that alter the way you would use them, like with the text example, is it just as simple as replacing the entmake with entmakex?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. Lisp to insert positional number
    By Tiger in forum AutoLISP, Visual LISP & DCL
    Replies: 33
    Last Post: 27th Aug 2010, 07:32 am
  2. Lisp/DCL using browse to insert
    By Impala62 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 20th Nov 2008, 02:08 pm
  3. ...add a line of text to insert into a lisp...
    By Gar in forum AutoCAD General
    Replies: 1
    Last Post: 19th Dec 2006, 06:56 pm
  4. lisp function to insert objects
    By minerman in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 12th Mar 2006, 04:57 am
  5. insert block lisp...
    By minerman in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 24th Feb 2006, 03:56 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