Need a LISP that will edit multiple lines of text on a single sheet

Need a LISP that will edit multiple lines of text on a single sheet

GMangat
Participant Participant
876 Views
7 Replies
Message 1 of 8

Need a LISP that will edit multiple lines of text on a single sheet

GMangat
Participant
Participant

Hello,

 

I am struggling to create a lisp that allows me to do the following:

1. Enter "ET" into the command line to begin the command.

2. allow me to window select as many text lines i want, can be anywhere on the sheet.

3. allow me to edit the text similar to when it is double clicked with a mouse (i am trying to avoid seeing my edits in the command line, as my current lisp does).

4. each time i hit the enter key, the next line of text will be selected (going from top most to bottom most)

5. this process is to continue until i press enter on the final line of text that i selected for editing.

 

below is my current existing lisp. the issues i am having with this one are as follows:

1. the editing of the text appears in the command line, i want the editing to work as though i double clicked that line of text on the sheet.

2. it processes my multiple selected lines of text from the bottom up, i need it to process top down.

 

LISP:

(defun c:ET ()

(setq textObjects (ssget '((0 . "TEXT")))) ; Select all text objects
(if textObjects

(progn

(setq count (sslength textObjects) index 0)
(princ "\nPress Enter to start editing the selected text.")
(getstring) ; Wait for Enter key

 

(while (< index count)

(setq ent (ssname textObjects index))
(setq entData (entget ent))

;; Prompt for new text
(setq newText (getstring (strcat "\nEnter new text for: " (cdr (assoc 1 entData)) ": ")))

;; Update text if newText is not empty
(if (not (equal newText ""))

(progn

(entmod (subst (cons 1 newText) (assoc 1 entData) entData)) ; Update text
(princ (strcat "\nUpdated text: " newText))

)

)

 

(setq index (1+ index)) ; Move to next text object

)

)
(princ "\nNo text objects selected.")

)
(princ)

)

0 Likes
877 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

You can try my free Text Apps which includes a multi text line editor DDTxtMed


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 8

pendean
Community Legend
Community Legend

@GMangat to go with your LISP can you share a sample DWG file with all that text/mtext that you need to edit "on screen" please?

0 Likes
Message 4 of 8

GMangat
Participant
Participant

i did not have one prepared, i was just tinkering on a blank sheet. the DWG i attached was just created, all additional layers have been purged. all 4 text lines were created using single line text.

0 Likes
Message 5 of 8

paullimapa
Mentor
Mentor

Running TextApps DDTXTMED command on your sample dwg:

paullimapa_1-1727284556444.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@GMangat wrote:

....

2. it processes my multiple selected lines of text from the bottom up, i need it to process top down

....


With a text-editing command, rather than manipulating entity data, this seems to do what you describe:

 

(defun c:EdT (/ textObjects index)
  (if (setq textObjects (ssget "_:L" '((0 . "TEXT")))) ; Select all text objects
    (progn ; then
      (alert "\nPress OK to start editing the selected text.")
      (repeat (setq index (sslength textObjects))
        (command "_.textedit" (ssname textObjects (setq index (1- index))) "")
      ); repeat
    ); progn
    (princ "\nNo text object(s) on unlocked Layer(s) selected."); else
  ); if
  (princ)
)

 

I changed the command name, because ET is the standard alias for ETRANSMIT.  Make it whatever you want.

And I used an (alert) for the go-ahead -- it has a built-in requirement for hitting Enter or picking its OK button.

BUT your item 2 quoted above would be true only with a particular drawing order [such as if they were drawn in top-to-bottom order, or are the result of Exploding an Mtext object of multiple lines] -- the index numbers will be reverse drawing order if selected collectively such as in a window, or in pick order if selected individually.  A drawing order that would result in bottom-to-top for you will be reversed by the way my code steps through [counting down the index numbers], but if they're not positioned in an order that agrees with their drawn order, or not picked individually in the desired order, all bets are off UNLESS you want to add positional sorting.  That's possible, with more code, and raises questions about what to do if there could be more than one at the same Y coordinate, etc.

Kent Cooper, AIA
Message 7 of 8

GMangat
Participant
Participant

thank you for the assistance, the lisp works wonderfully.

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Similar to @paullimapa I use this global program you can change the size of the edit box for each string or just guess a big one like this example.

 

(setq ans (AH:getvalsm (list "Enter new text " "Existing " 40 39 str)))

SeaHaven_0-1727423562709.png

It can make the text box suit length of text as every line is read.

 

Just let me know if interested but above by Puallimapa looks good.

0 Likes