Author Topic: need someone to add to this "text change" code  (Read 1328 times)

0 Members and 1 Guest are viewing this topic.

Robert_s

  • Guest
need someone to add to this "text change" code
« on: October 13, 2009, 11:58:57 AM »
Hello

I've this code for more than 15 years now. I think its time for more enhancements.

Can one of the gurus please..
1. Make it work for attributes too.
2. For TxtChg -  when a window selection is made the "line by line"
  is not in order (random). Let it sort correctly. Select the top or first line
  first then go down. Make selection in proper order. from top to bottom,
  left to right, etc.

;  TxtChg - Replace selected text lines with new text, line by line
;
;  TxtChgAll - Replace all selected text lines with one new text line
;
(defun gtext ()
 (setq c 0 co 0 ss (ssget) ssl (sslength ss))(print)
)
;
(defun stng ()
 (if ss
  (progn
   (while (setq en (ssname ss c))
    (setq el (entget en))
    (setq ty (cdr (assoc 0 el)))
    (setq el1 (cdr (assoc 1 el)))
    (if (= ty "TEXT")
     (progn
      (if rl
       (progn
        (redraw en 3)
        (princ (strcat"      <" el1 "> "))
        (setq nt (getstring 1 "\n New text: "))
        (if (= nt "") (setq nt el1))
       )
      )
      (setq el (subst (cons 1 nt) (assoc 1 el) el))
      (entmod el)
      (setq co (1+ co))
      (if rl (setq nt ""))
     )
    )
    (setq c (1+ c))    ;else next entity
   )                   ;while
  )
 )
 (princ co) (princ " lines changed ")
 (if (null rl)
  (princ (strcat "to  " (chr 34) nt (chr 34)))
 )
)
;
(defun c:TxtChgeAll (/ c co ss nt en ty el)
 (gtext)
 (setq rl nil nt (getstring 1 "\nNew text:  "))
 (if (not (= nt "")) (stng))
 (princ)
)
;
(defun c:TxtChg (/ rl c co ss nt en ty el)
 (setq rl 1) (gtext) (stng) (princ)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: need someone to add to this "text change" code
« Reply #1 on: October 13, 2009, 12:33:03 PM »
1. - For the ability to select attributes and text with an ssget fashion, look here: [ http://www.theswamp.org/index.php?topic=19886.0 ]

2. - For this, it will be a two step process.  First you get the entity and the insertion ( or text alignment ) point.  Then you sort by the points, by which ever axis you want to sort by.  Then you edit the list by that order.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: need someone to add to this "text change" code
« Reply #2 on: October 13, 2009, 01:48:44 PM »
Tim,

Thanks! Do you have a link I can look for number 2?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: need someone to add to this "text change" code
« Reply #3 on: October 13, 2009, 02:06:17 PM »
You're welcome.

Not off hand, but just step through the selection set, and make a list of the ename and point ' ( ename 0. 0. 0. ) '.  The point will be either dxf code 10 or 11, based on dxf codes 70 ( not sure exactly which ones ).  Then you can use ' vl-sort ' to sort the list by the points.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.