Author Topic: esc command script  (Read 1817 times)

0 Members and 1 Guest are viewing this topic.

johnratliff

  • Guest
esc command script
« on: October 01, 2013, 01:43:43 PM »
I need a little help here:

I'm trying to use the below lisp to extract plain text in a script file. The lisp ends the text selection with the esc. I've tried ^c,^C^C, (Command) and can't get the script to escape the selection.

Code: [Select]
(defun C:ETEXT  (/ FILE FUNC ENTITY ENTTYP TEXTMT)
 (setq fnamepe (getvar "dwgname"))
  (setq fnameme (substr fnamepe 1 (- (strlen fnamepe) 4)));Gets drawing name and strips file name extension.
  (setq fname (strcat fnameme ".txt")) ;add new extension to fname
  (if (= FNAME NIL)
    (setq FNAME
           (getfiled
             "Select the text file in which you want to extract data"
             "c:/"
             "txt"
             1))
    (setq FUNC
           (getstring
             (strcat
               "[data to be stored in "
               FNAME
               "]"
               "/Change file/<press Enter or Right-click to proceed>:")))
    )
  (if (= FUNC "c")
    (setq FUNC "C"))
  (if (= FUNC "C")
    (setq FNAME
           (getfiled
             "Select the text file in which you want to extract data"
             "c:/"
             "txt"
             1)))
  (while (/= FNAME NIL)
    (setq ENTITY
           (car
             (entsel
               "\nPress `Esc` to exit, or select the text string to be exported.")))
    (if (/= ENTITY NIL)
      (progn
        (setq ENTTYP (cdr (assoc 0 (entget ENTITY))))
        (if (wcmatch ENTTYP "*TEXT*")
          (progn
            (setq TEXTMT (cdr (assoc 1 (entget ENTITY))))
            (setq FILE (open FNAME "a"))
            (write-line TEXTMT FILE)
            (close FILE)
            (prompt (strcat "\nLine- `" TEXTMT "` added to " FNAME))
            )
          (prompt "\nSelected entity is not a text string")
          )
        )
      (prompt "\nNo entity selected")
      )
    )
  )
;;;;end of code

ronjonp

  • Needs a day job
  • Posts: 7533
Re: esc command script
« Reply #1 on: October 01, 2013, 02:24:04 PM »
Are you trying to put selected text object strings into a *.txt file?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

johnratliff

  • Guest
Re: esc command script
« Reply #2 on: October 01, 2013, 02:41:07 PM »
Yes, I'm using the lisp to build the text file. I'm then using a script to run the lisp on multiple files but the lisp uses "esc" to end the selection and I can't find the escape command to end the script. I don't know enough lisp to modify the lisp routine.


johnratliff

  • Guest
Re: esc command script
« Reply #3 on: October 01, 2013, 07:49:03 PM »
It was a bit of a struggle, but I got rid of all the while's and and most of the if's and the lisp now closes the file. I'd still like to know if there is a command line for the "esc" key so it could be used in a script.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: esc command script
« Reply #4 on: October 03, 2013, 05:12:21 PM »
This may be of some use to you.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:etext (/ fname ofile path)
  2.   (setq fname (vl-filename-base (getvar "DWGname")))
  3.   (setq path (getvar "DWGPrefix"))
  4.   (setq fname (strcat fname ".txt"))
  5.   (setq ofile (open (strcat path fname) "a"))
  6.         (setq err (vl-catch-all-apply
  7.                     '(lambda ()
  8.                        ;;  the following will catch ESCape
  9.                        (while t
  10.                          (setq entity (car (entsel "\nPress `Esc` to exit, or select the text string to be exported.")))
  11.                          (if (and entity
  12.                                   (setq obj (vlax-ename->vla-object entity))
  13.                                   (vlax-property-available-p obj 'textstring)
  14.                                   (setq txt (vla-get-textstring obj))
  15.                                   (/= "" (vl-string-trim " /t/n" txt))
  16.                              )
  17.                            (progn
  18.                              (write-line txt ofile)
  19.                              (prompt (strcat "\nText added to " fname))
  20.                            )
  21.                            (prompt "\nMissed or Selected entity is not a text string")
  22.                          )
  23.                        )
  24.                      )
  25.                   )
  26.         )
  27.       )
  28.     (if (wcmatch (strcase (vl-catch-all-error-message err)) "*CANCEL*")
  29.       (princ "\nUser Quit")
  30.     )
  31.   )
  32.  
  33.   (and ofile (close ofile))
  34.  
  35.   (princ)
  36. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.