Author Topic: How to use mtext contents to change mleader contents?  (Read 3868 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
How to use mtext contents to change mleader contents?
« on: September 16, 2009, 12:14:39 PM »
Been working on this for a minute today, can't figure out how to use assoc code 1 from mtext for assoc code 304 for mleaders.  Anyone know?

Code: [Select]
(defun C:MTxt2Mleader ()
  (setq ent (entget (car (entsel "\nSelect SOURCE text: "))))
  (setq info (assoc 1 ent))
  (setvar "cmdecho" 0)
  (while
    (setq ent2 (entget (car (entsel "\nSelect MLEADER object: "))))
    (SETQ mlinfo (assoc 304 ent2))
    (setq ent2 (subst (assoc 304 INFO) (assoc 304 ent2) ent2))
    (entmod ent2)
    (setvar "cmdecho" 1)
    );end while
);end of defun

Returns:
; error: bad association list: (1 . "SAMPLE TEXT")

ronjonp

  • Needs a day job
  • Posts: 7527
Re: How to use mtext contents to change mleader contents?
« Reply #1 on: September 16, 2009, 12:55:47 PM »
Mleaders are much easier to manipulate via ActiveX...here's a small example:

Code: [Select]
(defun c:test(/ mleader txt)
  (if (and (setq txt (car (entsel "\nSelect text: ")))
   (setq mleader (car (entsel "\nSelect mleader: ")))
   (setq mleader (vlax-ename->vla-object mleader))
   (setq txt (vlax-ename->vla-object txt))
      )
    (progn (vla-put-textstring mleader (vla-get-textstring txt))
   (vla-update mleader)
    )
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to use mtext contents to change mleader contents?
« Reply #2 on: September 16, 2009, 12:58:10 PM »
Hi,

replace:
(subst (assoc 304 INFO) (assoc 304 ent2) ent2)
by
(subst (cons 304 INFO) (assoc 304 ent2) ent2)
Speaking English as a French Frog

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: How to use mtext contents to change mleader contents?
« Reply #3 on: September 16, 2009, 01:18:31 PM »
Mleaders are much easier to manipulate via ActiveX...here's a small example:

Code: [Select]
(defun c:test(/ mleader txt)
  (if (and (setq txt (car (entsel "\nSelect text: ")))
   (setq mleader (car (entsel "\nSelect mleader: ")))
   (setq mleader (vlax-ename->vla-object mleader))
   (setq txt (vlax-ename->vla-object txt))
      )
    (progn (vla-put-textstring mleader (vla-get-textstring txt))
   (vla-update mleader)
    )
  )
)


Worked like a charm! Thank you!

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: How to use mtext contents to change mleader contents?
« Reply #4 on: September 16, 2009, 01:20:02 PM »
Hi,

replace:
(subst (assoc 304 INFO) (assoc 304 ent2) ent2)
by
(subst (cons 304 INFO) (assoc 304 ent2) ent2)

Still got an error, think I tried that one earlier, but brains fried now...need to do this more often...

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How to use mtext contents to change mleader contents?
« Reply #5 on: September 16, 2009, 01:27:19 PM »
Just for completeness Dommy:

Code: [Select]
(defun C:MTxt2Mleader (/ ent text ent2)
  (if (setq ent (car (entsel "\nSelect SOURCE text: ")))
    (progn
      (setq text (cdr (assoc 1 (entget ent))))
      (while (setq ent2 (car (entsel "\nSelect MLEADER object: ")))
        (entmod
          (subst
            (cons 304 text)
              (assoc 304 (entget ent2)) (entget ent2))))))
  (princ))

PS: You don't need to set CMDECHO to 0, as you are not calling (command... anywhere  :wink:

ronjonp

  • Needs a day job
  • Posts: 7527
Re: How to use mtext contents to change mleader contents?
« Reply #6 on: September 16, 2009, 04:41:05 PM »
Mleaders are much easier to manipulate via ActiveX...here's a small example:

Code: [Select]
(defun c:test(/ mleader txt)
  (if (and (setq txt (car (entsel "\nSelect text: ")))
   (setq mleader (car (entsel "\nSelect mleader: ")))
   (setq mleader (vlax-ename->vla-object mleader))
   (setq txt (vlax-ename->vla-object txt))
      )
    (progn (vla-put-textstring mleader (vla-get-textstring txt))
   (vla-update mleader)
    )
  )
)


Worked like a charm! Thank you!

 :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC