• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Valued Contributor
    Posts: 59
    Registered: 12-28-2009

    Alternative to getsel?

    98 Views, 3 Replies
    01-27-2012 02:17 PM

    Ok, so I'm trying to find the text contents of a line of text. I found a way that I can do it, however I want to be able to have the code select the text, not have the user need to select it. What would be the command to do so?(Here's what I currently have:

    (cdr (assoc 1 (entget (car (entsel "\n<insert your question here>"))))) in a setq)

    Thanks,
    Adam Richardson

    If needed: AutoCAD 2011 User using Visual LISP for editing LISP and DCL files
    Valued Contributor
    Posts: 79
    Registered: 05-01-2003

    Re: Alternative to getsel?

    01-27-2012 02:29 PM in reply to: AR12

    Having the program select the line of text without the user selecting is difficuly because how does the program know which text the user wants to select.

     

    There are ways in Autolisp to filter selections based upon the properties of a textstring (color, layer, font, etc.), but if there are more than one text string of the same type, both text strings will be selected.

     

    Please explain in more detail what you are trying to accomplish with your overall program

    Valued Contributor
    Posts: 59
    Registered: 12-28-2009

    Re: Alternative to getsel?

    01-27-2012 02:31 PM in reply to: lgabriel

    This is a small part of it, I am going to be changing lines of text, and I will have a dialog box that if I'm capable of doing it, it will display what the lines currently read allowing the user to change what they want to change.

    Thanks,
    Adam Richardson

    If needed: AutoCAD 2011 User using Visual LISP for editing LISP and DCL files
    Valued Contributor
    Posts: 79
    Registered: 05-01-2003

    Re: Alternative to getsel?

    01-27-2012 05:09 PM in reply to: AR12

    Do not know if the following will help, but its a program that I have written that allows the user to select as many TEXT and MTEXT objects at one time, open NOTEPAD.exe allowing the user to edit as many lines, save file, and all text in AutoCAD will update with the changes. NOTE: The name/path of the temporary file (C:\\TEMP\\tmpedtx.dat) can be changed to whatever you want.

     

    ;EDTX.LSP
    ;
    ;Adapted for V edit L. Gabriel 1.22.88 from ET.lsp
    ;
    ;object: selects text entities in drawing, writes them to a text
    ;        file for editing purposes (V edit), reads file and changes
    ;        text string in drawing.
    ;
    ;Rev 01: added ALERT dialog box for prompting user to update text
    ;        l. gabriel 03.27.00
    ;
    'Rev 02: filtered selection set ss to accept only TEXT entities
    ;        l. gabriel 10.17.03
    ;
    ;Rev 03: filtered selection set ss to accept only TEXT or MTEXT entities
    ;
    (defun echooff ()
      (setq oldecho (getvar "CMDECHO"))
      (setq oldblip (getvar "BLIPMODE"))
      (setq oldosm (getvar "OSMODE"))
      (setvar "CMDECHO" 0)
      (setvar "BLIPMODE" 0)
      (setvar "OSMODE" 0)
      (setq olderror_echo *ERROR*)
      (terpri)
      (defun *ERROR* (msg)
        (princ " \n")
        (princ msg)
        (echoon)
      )
    )
    ;
    (defun echoon ()
      (setvar "CMDECHO" oldecho)
      (setvar "BLIPMODE" oldblip)
      (setvar "OSMODE" oldosm)
      (setq *ERROR* olderror_echo)
      (princ)
    )
    ;
    (defun c:edtx (/ ss ssl f i e tx)
      (echooff)
      (princ "Select text entities\n")
      (setq ss (ssget))
      (cond
        (
          (not ss)
          (princ)
        )
        (
          (> (sslength ss) 100000)
            (princ "Cannot edit more than 100,000 entities at a time\n")
            (princ)
        )
        (T
          (setq ssl (sslength ss)
                f (open "C:/TEMP/tmpedtx.dat" "w")
                i 0
          )
          (princ "\nWriting file...\n")
          (while (< i ssl)
             (if (OR (= (cdr(assoc 0 (entget(ssname ss i)))) "TEXT")(= (cdr(assoc 0 (entget(ssname ss i)))) "MTEXT"))
             (progn

               (setq e (entget (ssname ss i))
                     tx (cdr (assoc 1 e))
               )
               (princ tx f)
               (princ "\n" f)
             )
             )
             (setq i (+ i 1))
          )

          (close f)
          (princ "\n\n")
          (command "shell" "notepad C:\\TEMP\\tmpedtx.dat" )
          (alert "Click OKAY to update: ")
          (if (setq f (open "C:/TEMP/tmpedtx.dat" "r"))
            (progn
              (setq i 0
              )
              (princ "\nReading and updating...\n")
              (while (< i ssl)
     
               (if (OR (= (cdr(assoc 0 (entget(ssname ss i)))) "TEXT")(= (cdr(assoc 0 (entget(ssname ss i)))) "MTEXT"))
                (progn
                (setq e (entget (ssname ss i))
                      tx (read-line f)
                      e (subst (cons 1 tx) (assoc 1 e) e)
                )
                (entmod e)
                )
               )
               (setq i (+ i 1))
              )
              (close f)
            )
          )
          (princ)
        )
      )
    (graphscr)
    (redraw)
    (echoon)
    )