transfers the content of a text to otherS

transfers the content of a text to otherS

diegolopezsilanes
Advocate Advocate
871 Views
3 Replies
Message 1 of 4

transfers the content of a text to otherS

diegolopezsilanes
Advocate
Advocate

hello guys, I'm trying to modify a program that should transfers the content of a text to other text fields regardless of whether the recipients are text or multiple text

But I'm having problems with the conditional that discriminates between both types of target entities, only works for multiple text.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:txtransfer() ;;copy tx content from a field to others
(setvar "cmdecho" 0)
(setq oldcmd (getvar "pickbox"))
(setvar "pickbox" 15)
(setq eset1(ssget '((-4 . "<or")(0 . "text") (0 . "mtext")(-4 . "or>"))))
(setq pre (cdr (assoc 1 (entget (ssname eset1 0)))))
(setq ss (ssget))
(setq i -1)
(while (setq en (ssname ss (setq i (1+ i))))
 (setq enlist(entget en))
 (if 
;;;;;;;Here is the conditional with the problem
(or
(equal "text" (cdr(assoc 0 enlist)))
(equal  "mtext" (cdr(assoc 0 enlist)))
);;or
;;;;;;;Here is the conditional with the problem
 (progn
(setq str(strcat pre))
(setq enlist(subst (cons 1 str)(assoc 1 enlist) enlist))
(entmod enlist)
 );progn
);if
(setq ernote "select text only please.")
 );while
(setq ernote "nothing selected.")
 (setvar "cmdecho" 1)
 (princ "\n \n ")
 (princ ernote)
(setvar "pickbox" oldcmd )
 (princ pre)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

Thanks for all

 

 

Here is the initial code I am working with:

 

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:txtransfer() ;;copy tx content from a field to others
(setvar "cmdecho" 0)
(setq oldcmd (getvar "pickbox"))
(setvar "pickbox" 15)
(setq eset1(ssget '((-4 . "<or")(0 . "text") (0 . "mtext")(-4 . "or>"))))
(setq pre (cdr (assoc 1 (entget (ssname eset1 0)))))
(setq ss (ssget))
(setq i -1)
(while (setq en (ssname ss (setq i (1+ i))))
 (setq enlist(entget en))
;;;here no conditional (if (= "mtext" (cdr(assoc 0 enlist)))
;;;here no conditional (progn (setq str(strcat pre)) (setq enlist(subst (cons 1 str)(assoc 1 enlist) enlist)) (entmod enlist) );progn );if (setq ernote "select text only please.") );while (setq ernote "nothing selected.") (setvar "cmdecho" 1) (princ "\n \n ") (princ ernote) (setvar "pickbox" oldcmd ) (princ pre) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

 

0 Likes
Accepted solutions (1)
872 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor
Accepted solution

hi,

 

check this one, it's little shorter.

 

the first (ssget) uses ":S" argument that limit selection to 'one' entity

why 'one'? cause it's only be one if you use pick option once. anyhow the program than takes only the first entity

in the selection set.

the second (ssget) let you freely select any object but filter out the texts entities.

then there is no need to check if the entities selected is text (or mtext)

 

also note the check on the (ssget)  function, if noting is selected then the program is finished, this is a normal behaviour of any standard AutoCAD command that use select objects.

 

enjoy

moshe

 

(defun c:cpytxtval (/ ss0 ss1 i ent0 ent1 elist1 sorText) ;; copy text value
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (princ "\nSelect source text.")
 (if (setq ss0 (ssget ":S" '((0 . "text,mtext")))) ; select single text entity
  (progn
   (redraw (setq ent0 (ssname ss0 0)) 3) ; highlight source text
   (setq sorText (cdr (assoc 1 (entget ent0))))

   (princ "\nSelect target text(s)")
   (if (setq ss1 (ssget '((0 . "text,mtext")))) ; let user select only text entities
    (progn
     (setq i -1)
     (while (setq ent1 (ssname ss1 (setq i (1+ i))))
      (setq elist1 (entget ent1))
      (setq elist1 (subst (cons '1 (strcase sorText)) (assoc '1 elist1) elist1))
      (entmod elist1)
     ); while
    ); progn
   ); if
  ); progn
 ); if

 (redraw ent0 4); de highlight source text
 (command "._undo" "_end")
 (setvar "cmdecho" 1)
); c:cpytxtval
Message 3 of 4

diegolopezsilanes
Advocate
Advocate

uou Moshe, its a lesson of how to make this things, highlight , error handl ..
thanks a lot for the reply and the lesson.

0 Likes
Message 4 of 4

Moshe-A
Mentor
Mentor

you are right there could be en error with the de highlight

here is the fix

 

(defun c:cpytxtval (/ ss0 ss1 i ent0 ent1 elist1 sorText) ;; copy text value
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (princ "\nSelect source text.")
 (if (setq ss0 (ssget ":S" '((0 . "text,mtext")))) ; select single text entity
  (progn
   (redraw (setq ent0 (ssname ss0 0)) 3) ; highlight source text
   (setq sorText (cdr (assoc 1 (entget ent0))))

   (princ "\nSelect target text(s)")
   (if (setq ss1 (ssget '((0 . "text,mtext")))) ; let user select only text entities
    (progn
     (setq i -1)
     (while (setq ent1 (ssname ss1 (setq i (1+ i))))
      (setq elist1 (entget ent1))
      (setq elist1 (subst (cons '1 (strcase sorText)) (assoc '1 elist1) elist1))
      (entmod elist1)
     ); while
    ); progn
   ); if

   (redraw ent0 4); de highlight source text
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
); c:cpytxtval