Jump to content

Text Lisp


neekcotrack

Recommended Posts

I have this below. I would like to be able to type the text and insert and see the text I type to insert it to where I like. I this possible.

 

(command "_.text" "style" "simpfrac" pause "0" pause)

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • neekcotrack

    14

  • Lee Mac

    13

  • CAB

    5

  • Se7en

    1

Maybe this?

;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;; FUNCTION Get_String.lsp
;;;  create a text object, then allow user to edit it via grread
;;;  return the text string, keep the text object unless ESCAPE 
;;; 
;;; ARGUMENTS 
;;;   see listed below
;;; 
;;; PLATFORMS 
;;; 2000+ 
;;; 
;;; AUTHOR 
;;; Copyright© 2008 Charles Alan Butler  
;;;   Contact at TheSwamp.org
;;; 
;;; VERSION 
;;; 1.0 Oct 14, 2008 
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;;
;;; This routine may be used and copied for non-profit
;;;  purposes only. If you wish to include any of the file in a
;;;  commercial program, contact the author.
;;;
 
;;;-------------------------------------------------------------

 (defun get_string (pt       ; insert point            
                    just     ; text justification      
                    str      ; starting string         
                    pro      ; command line prompt     
                    flist    ; Characters Filter List (wcmatch chr "[a-z],[A-Z],[0-9],-"))
                    lay      ; layer to use, nil = current
                    cursor   ; text rotation           
                    ed_color ; Color to use during edit
                    rot      ; Text rotation angle in radians
                    tstyle   ; text style to use, nil = current
                    txtht    ; text height, nil = current textsize
                    / *error* dxf72 dxf73 elist TextEnt key grr cursor cLen)

   
   ;;-------------------------------------------------
   (defun *error* (msg)
     (if (not
           (member msg '("console break" "Function cancelled" "quit / exit abort" "" nil))
         )
       (princ (strcat "\nError: " msg))
     )
     ;; if TextEnt exist then delete it.
     (and TextEnt (entdel TextEnt)) 
     (and usrcmd (setvar "cmdecho" 0))
     (princ)
   )       ; end error function


   ;;  Catch any nil variables & set to defaults
   (or lay (setq lay (getvar "clayer")))
   (or ed_color (setq ed_color 2))     ; set color = yellow
   (or txtht (setq txtht (getvar "textsize")))
   ;;  Note that _ as cursor does not work for some fonts
   (or cursor (setq cursor "I")) ; cursor position indicator default character
   (setq cLen (strlen cursor))
   (if (or (/= (type just) 'STR) (= str ""))
     (setq str cursor) ; default start character, visual referance on the screen
     (setq str (strcat str cursor))
   )

   ;; Set up the Text justification for DXF 72 & 73
   (setq just   (if (= (type just) 'STR) (strcase just) "L")) ; force upper case or "L"
   (setq dxf72 (cdr (assoc just '(("TL" . 0 )("TC" . 1 )("TR" . 2 )("ML" . 0 )("MC" . 1 )
                      ("MR" . 2 )("BL" . 0 )("BC" . 1 ) ("BR" . 2 )("L"  . 0 )("C"  . 1 )
                      ("R"  . 2 )("A"  . 3 )("M"  . 4 )("F"  . 5 ) ))))
   (setq dxf73 (cdr (assoc just '(("TL" . 3 )("TC" . 3 )("TR" . 3 )("ML" . 2 )("MC" . 2 )
                      ("MR" . 2 )("BL" . 1 )("BC" . 1 )("BR" . 1 )("L"  . 0 )("C"  . 0 )
                      ("R"  . 0 )("A"  . 0 )("M"  . 4 )("F"  . 5 ) ))))
   (setq elist ; set up a text entity
          (list
            '(0 . "TEXT")
            (cons 8 lay) ; layer
            (cons 7 (getvar "textstyle"))
            (cons 40 txtht)
            (cons 62 ed_color)
            (cons 50 rot)   ; rotation
            (cons 10 pt)    ; insert point
            (cons 11 pt)    ; Second alignment point
            (cons 72 dxf72) ; vertical justification
            (cons 73 dxf73) ; horizontal justification
            (cons 1  str)
          )
   )

   (cond ; adjust prompt if needed
    ((/= (type pro) 'STR) (setq pro "\nEnter text: "))
    ((/= (substr pro 1 1) "\n") (setq pro (strcat "\n" pro)))
   )
   ;; create a text object then edit it
   (setq TextEnt (entmakex elist)) 
   (setq elist (entget TextEnt))  
   (prompt (strcat pro (substr str 1 (-(strlen str)cLen))))
   (while ; get the string from user, exit only for ENTER
     (cond ; 11111111111
       ((eq 2 (car (setq grr (grread)))) ; keyboard input
        (setq key (cadr grr))
        (cond ; 222222222222
          ((= key  ; backspace
           (if (and (/= str "")(/= str cursor))
             (progn
               (setq str (strcat (substr str 1 (- (strlen str) (1+ clen))) cursor))
               (prompt (strcat (chr  " " (chr ))
               (setq elist (subst (cons 1 str) (assoc 1 elist) elist))
               (entmod elist)
             )
             t ; stay in loop
           )
          )
          ((= key 13) ; ENTER- we're done here
           (if (/= str cursor)
             (progn
               (setq str (substr str 1 (-(strlen str)cLen)))
               (setq elist (subst (cons 1 str) (assoc 1 elist) elist))
               (entmod elist)
             )
             (setq str "")
           )
           nil ; exit loop
          )
          ;;  if a valid key press add to string, ignore others but print message
          ((or (not flist)(wcmatch (chr key) flist)) 
           (if (= str cursor)
             (setq str (strcat (chr key) cursor))
             (setq str (strcat (substr str 1 (-(strlen str)clen)) (chr key) cursor))
           )
           (prompt (chr key))
           ;;  update text on screen
           (setq elist (subst (cons 1 str) (assoc 1 elist) elist))
           (entmod elist)
          )
          ((princ "\nInvalid Keypress.")
           (princ (strcat pro (substr str 1 (-(strlen str)cLen))))
          )
        ) ; end cond stmt 2222
       )
       ((princ "\nKeyboard entry only.")
        (princ (strcat pro (substr str 1 (-(strlen str)cLen))))
       )
     )    ; end cond stmt 1111
   )     ; while
   (if (= str "")
     (entdel TextEnt) ; remove empty string entity
     (progn
       ;; set up to change the text color in the database
       (setq elist (subst (cons 62 256) (assoc 62 elist) elist))
       (entmod elist) ; update the database
     )
   )
   str   ; return the string
 )


;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;;
;;  Intermediate routine used to handle some of the options as fixed
;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(defun get_text (pt just str pro )
 (get_string pt   ; insert point
             just ; text justification
             str  ; starting string
             pro  ; text prompt
             nil  ; No Character Filter List
             nil  ; Use current layer
             "_"  ; char to use as the cursor position
             nil  ; Color to use during edit
             0.0  ; text rotation
             nil  ; text style
             nil  ; text height  ; (/ (getvar "VIEWSIZE") 50.)
             )
)


;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;;  User Test Routine 
(defun c:test(/ usrcmd p1 data)
 (setq p1 (getpoint "\nPick text insert point:"))
 (setq data (get_text p1              ; starting position
                      "L"             ; text justification
                      "Starting Text" ; beginning string
                      "Enter Text: "  ; command line prompt
                      ))
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Link to comment
Share on other sites

Thanks CAB, but I am looking for something really simple. I was thinking somewthing like this:

 

(defun c:test (ip)

(command "_.text" "s" "simpfrac" ip "0" pause)

(setq ip (get..............)

)

 

I think it is possible but not sure how. Thanks in advance for any help.

Link to comment
Share on other sites

This is simple form of edit:

;;; FUNCTION 
;;;   Use ddedit box to edit a text string.
;;; 
;;; PLATFORMS 
;;; 2000+ 
;;; 
;;; AUTHOR 
;;; Charles Alan Butler 
;;; ab2draft@TampaBay.rr.com 
;;; 
;;; VERSION 
;;; 1.1 Oct. 06, 2004 
(defun text_edit (txt / entlist ent)
 (if (setq ent
            (entmakex
              (list
                '(0 . "TEXT")
                (cons 10 '(0 0))
                (cons 40 1)
                (cons 7 (getvar "TEXTSTYLE"))
                (cons 1 txt)           ; Text String
              )
            )
     )
   (progn
     (command "._ddedit" ent "")
     (setq txt (cdr (assoc 1 (entget ent))))
     (entdel ent)
     txt
   )
 )
)

(defun c:test (/ newtext)
 (setq newtext (text_edit "This is a test string."))
)

Link to comment
Share on other sites

I am loking for something that lets me type my text and then lets me see it and place it. At my old job we had something just like it.

Link to comment
Share on other sites

Perhaps?

 

(defun c:test (/ txt ent)
 (if (/= "" (setq txt (getstring "\nSpecify Text...")))
   (progn
     (entmakex
   (list '(0 . "TEXT")
         (cons 10 '(0 0 0))
         (cons 40 1)
         (cons 7 (getvar "TEXTSTYLE"))
         (cons 1 txt)))
     (command "_move" (entlast) "" '(0 0 0) pause))
   (princ "\n<!> No Text Specified <!>"))
 (princ))

Link to comment
Share on other sites

Nice change there Lee.

You need to take advantage of the fact the entmakex returns the entity name. :)

And don't forget the (getstring t

(defun c:test (/ txt ent)
 (if
   (and
     (/= "" (setq txt (getstring t "\nSpecify Text...")))
     (setq ent (entmakex
                 (list '(0 . "TEXT")
                       (cons 10 '(0 0 0))
                       (cons 40 1)
                       (cons 7 (getvar "TEXTSTYLE"))
                       (cons 1 txt)
                 )
               )
     )
   )
    (command "_move" ent "" '(0 0 0) pause)
 )
 (princ "\n<!> No Text Specified <!>")
 (princ)
)

Link to comment
Share on other sites

Another variation would be to _cutclip the new text & use _pasteclip

This way Escape would not leave the text in the DWG & there would be no vector from 0,0 displayed during the paste.

Just a thought.8)

Link to comment
Share on other sites

Good Call.

 

(defun c:test  (/ txt ent)
 (if (and (/= "" (setq txt (getstring t "\nSpecify Text...")))
      (setq ent (entmakex
              (list '(0 . "TEXT")
                    (cons 10 '(0 0 0))
                    (cons 40 1)
                    (cons 7 (getvar "TEXTSTYLE"))
                    (cons 1 txt)))))
    (command "_cutclip" ent "" "_pasteclip" pause)
   (princ "\n<!> No Text Specified <!>"))
 (princ))

Link to comment
Share on other sites

Maybe?

 

(defun c:test  (/ txt ent styl)
 (if (and (/= "" (setq txt (getstring t "\nSpecify Text...")))
   (or (and (tblsearch "STYLE" "ROMANS") (setq styl "ROMANS"))
       (setq styl (getvar "TEXTSTYLE")))
   (setq ent (entmakex
	       (list '(0 . "TEXT")
		     (cons 10 '(0 0 0))
		     (cons 40 1)
		     (cons 7 styl)
		     (cons 1 txt)))))
   (command "_cutclip" ent "" "_pasteclip" pause)
   (princ "\n<!> No Text Specified <!>"))
 (princ))

Link to comment
Share on other sites

Maybe?

 

(defun c:test  (/ txt ent styl)
 (if (and (/= "" (setq txt (getstring t "\nSpecify Text...")))
      (or (and (tblsearch "STYLE" "ROMANS") (setq styl "ROMANS"))
          (setq styl (getvar "TEXTSTYLE")))
      (setq ent (entmakex
              (list '(0 . "TEXT")
                (cons 10 '(0 0 0))
                (cons 40 1)
                (cons 7 styl)
                (cons 1 txt)))))
   (command "_cutclip" ent "" "_pasteclip" pause)
   (princ "\n<!> No Text Specified <!>"))
 (princ))

 

One more when I run the command everything works fine, but when I right click to repeat the command the insert point compared to the text are way apart from each other.

Link to comment
Share on other sites

I think that may be just something with using the cutclip and pastclip method... but not sure... maybe CAB knows a bit more..

 

Try this and let me know if you still get it:

 

(defun c:test  (/ txt ent styl)
 (if (and (/= "" (setq txt (getstring t "\nSpecify Text...")))
      (or (and (tblsearch "STYLE" "ROMANS") (setq styl "ROMANS"))
          (setq styl (getvar "TEXTSTYLE")))
      (setq ent (entmakex
              (list '(0 . "TEXT")
                (cons 10 '(0 0 0))
                (cons 40 1)
                (cons 7 styl)
                (cons 1 txt)))))
   (command "_move" ent "" '(0 0 0) pause)
   (princ "\n<!> No Text Specified <!>"))
 (princ))

Link to comment
Share on other sites

I think that may be just something with using the cutclip and pastclip method... but not sure... maybe CAB knows a bit more..

 

Try this and let me know if you still get it:

 

(defun c:test  (/ txt ent styl)
 (if (and (/= "" (setq txt (getstring t "\nSpecify Text...")))
      (or (and (tblsearch "STYLE" "ROMANS") (setq styl "ROMANS"))
          (setq styl (getvar "TEXTSTYLE")))
      (setq ent (entmakex
              (list '(0 . "TEXT")
                (cons 10 '(0 0 0))
                (cons 40 1)
                (cons 7 styl)
                (cons 1 txt)))))
   (command "_move" ent "" '(0 0 0) pause)
   (princ "\n<!> No Text Specified <!>"))
 (princ))

 

No but that is doing the moving again.

Link to comment
Share on other sites

I am trying to combined these two know:

 

(defun c:pz ()

(command "_.layer" "m" "test" "c" "4" "" "")

(command "_.INSERT" "pz" "s" (getvar "dimscale") PAUSE PAUSE)

(c:test)

)

(defun c:test (/ txt ent)

(if

(and

(/= "" (setq txt (getstring t "\nSpecify Text...")))

(setq ent (entmakex

(list '(0 . "TEXT")

(cons 10 '(0 0 0))

(cons 40 1)

(cons 7 (getvar "TEXTSTYLE"))

(cons 1 txt)

)

)

)

)

(command "_move" ent "" '(0 0 0) pause)

)

(princ "\n No Text Specified ")

(princ)

)

 

The problem I am having is I want the text loop to be placed and then it does the text so I can place it at the end of the text loop, but I just want it to let me put it where I like, nothing fancy.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...