Jump to content

How can this code be modified to not only match text but also to match the source text's match prop?


AeJay

Recommended Posts

Basically I just wanted to have this code by Lee to essentially have the match prop as well. Someone replied to me in the original thread but I can't seem to get it to work.

Lee's code:

(defun c:mt  (/ cEnt mEnt)
 (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
          (member (cdr (assoc 0 (entget cEnt)))
                  '("TEXT" "MTEXT" "ATTRIB")))
   (progn
     (redraw cEnt 3)
     (while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))
                 (member (cdr (assoc 0 (entget mEnt)))
                         '("TEXT" "MTEXT" "ATTRIB")))
       (entmod (subst (assoc 1 (entget cEnt))
                      (assoc 1 (entget mEnt))
                      (entget mEnt))))
     (redraw cEnt 4))
   (princ "\n<!> Incorrect Selection <!>"))
 (princ))



(defun c:mt2  (/ cEnt mEnt sLst)
 (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
          (member (cdr (assoc 0 (entget cEnt)))
                  '("TEXT" "MTEXT" "ATTRIB")))
   (progn
     (redraw cEnt 3)
     (if (setq ss (ssget "_X" '((-4 . "<NOT") (0 . "TEXT,MTEXT,INSERT") (-4 . "NOT>"))))
       (mapcar '(lambda (x) (redraw x 2)) (setq sLst (mapcar 'cadr (ssnamex ss)))))
     (while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))
                 (member (cdr (assoc 0 (entget mEnt)))
                         '("TEXT" "MTEXT" "ATTRIB")))
       (entmod (subst (assoc 1 (entget cEnt))
                      (assoc 1 (entget mEnt))
                      (entget mEnt)))))
   (princ "\n<!> Incorrect Selection <!>"))
 (command "_regenall")
 (princ))



(defun c:mt3  (/ cEnt ss)
 (vl-load-com)
 (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
          (member (cdr (assoc 0 (entget cEnt)))
                  '("TEXT" "MTEXT" "ATTRIB")))
   (progn
     (redraw cEnt 3)
     (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
       (foreach x  (vl-remove-if 'listp
                     (mapcar 'cadr (ssnamex ss)))
         (entmod (subst (assoc 1 (entget cEnt))
                        (assoc 1 (entget x))
                        (entget x))))))
   (princ "\n<!> Incorrect Selection <!>"))
 (command "_regenall")
 (princ))

 

Link to comment
Share on other sites

I tried modifying it (code below) but then despite successfully loading the .lsp via appload and using the correct shortcut name of mt3. It says it is an unknown command.

(defun c:mt3  (/ cEnt ss textColor)
  (vl-load-com)
  (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
           (member (cdr (assoc 0 (entget cEnt)))
                   '("TEXT" "MTEXT" "ATTRIB")))
    (progn
      (setq textColor (cdr (assoc 62 (entget cEnt)))) ;; get the text color
      (redraw cEnt 3)
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (foreach x  (vl-remove-if 'listp
                      (mapcar 'cadr (ssnamex ss)))
          (entmod (subst (assoc 1 (entget cEnt))
                         (assoc 1 (entget x))
                         (subst (cons 62 textColor) (assoc 62 (entget x)) (entget x)))))) ;; update the text color
    (princ "\n<!> Incorrect Selection <!>"))
  (command "_regenall")
  (princ)))

 

Link to comment
Share on other sites

This code loads and functions correctly but it still just copies the text and not the text's color as well. Please help.

(defun c:matchTextAndProp (/ cEnt ss textColor)
  (vl-load-com)
  (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
           (member (cdr (assoc 0 (entget cEnt)))
                   '("TEXT" "MTEXT" "ATTRIB")))
    (progn
      (setq textColor (cdr (assoc 62 (entget cEnt)))) ;; get the text color
      (redraw cEnt 3)
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (foreach x  (vl-remove-if 'listp
                      (mapcar 'cadr (ssnamex ss)))
          (entmod (subst (assoc 1 (entget cEnt))
                         (assoc 1 (entget x))
                         (subst (cons 62 textColor) (assoc 62 (entget x)) (entget x)))))) ;; update the text color
    (princ "\n<!> Incorrect Selection <!>")))
  (command "_regenall")
  (princ))

 

Link to comment
Share on other sites

This too won't still work to copy the source's text color :(
 

(defun c:matchTextAndProp (/ cEnt ss textColor)
  (vl-load-com)
  (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
           (member (cdr (assoc 0 (entget cEnt)))
                   '("TEXT" "MTEXT" "ATTRIB")))
    (progn
      (setq textColor (cdr (assoc 62 (entget cEnt))))
      (redraw cEnt 3)
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (foreach x  (vl-remove-if 'listp
                      (mapcar 'cadr (ssnamex ss)))
          (entmod (subst (assoc 1 (entget cEnt))
                         (assoc 1 (entget x))
                         (entmod (subst (cons 62 textColor) (assoc 62 (entget x)) (entget x)))))))
    )
  (command "_regenall")
  (princ))

 

Link to comment
Share on other sites

One of the things with color is if its bylayer then it does not have a color in the entget, no 62, so if its nil then you need to get the Layer color.

Test

(entget (car (entsel "\nPick text ")))

 

Example

(setq col (vla-get-color (vlax-ename->vla-object e)))
	 (if (= col 256)
	 (setq col (cdr (assoc 62 (tblsearch "LAYER" lay))))
	)

 

  • Like 1
Link to comment
Share on other sites

Fixed it. Here is a code:

cc: gileCAD

(defun c:matchTextAndProp (/ cEnt elst text color ss i)
  (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
           (member (cdr (assoc 0 (entget cEnt)))
                   '("TEXT" "MTEXT" "ATTRIB")
           )
      )
    (progn
      (setq elst  (entget cEnt)
            text  (assoc 1 elst)
            color (cond ((assoc 62 elst))
                        (T '(62 . 256))
                  )
      )
      (redraw cEnt 3)
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (repeat (setq i (sslength ss))
          (setq elst (entget (ssname ss (setq i (1- i)))))
          (entmod
            (subst text
               (assoc 1 elst)
               (if (assoc 62 elst)
                 (entmod (subst color (assoc 62 elst) elst))
                 (append elst (list color))
              )
            )
          )
        )
      )
    )
  )
  (command "_regenall")
  (princ)
)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...