Author Topic: Attach mleader to existing text/mtext?  (Read 3053 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
Attach mleader to existing text/mtext?
« on: November 29, 2007, 10:51:44 AM »
I am trying to find a way to attach an mleader (Acad 2008) to an existing text or mtext object.  I don't see a way in the active-x object model to do this, and can't decipher the enames in the entity list.  Any pointers are appreciated.  The following code selects the text object and creates the leader, but I see no way to make the association between the two:
Code: [Select]
(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
  (cond
    ;;Select the text/mtext objects
    ((or
       (null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
       (= 0 (setq ssl (sslength ss1)))
     )
     nil ;nothing selected
    )
    (T
     (setq
       Textobj (vlax-ename->vla-object (ssname ss1 0))
       ActSpace (if (= 0 (getvar "cvport"))
  (vla-get-paperspace
    (vla-get-activedocument (vlax-get-acad-object))
  )
  (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object))
  )
)
       StartPt (getpoint "\nPick location for point of arrow head: ")
       TextPt (vla-get-insertionpoint textobj)
       TextPt (vlax-variant-value TextPt)
       TextPt (vlax-safearray->list TextPt)
       ptlist (vlax-make-safearray
  vlax-vbdouble
  '(0 . 5)
)
       ptlist (vlax-safearray-fill ptlist (append StartPt TextPt))
       MLObj (vla-addmleader
  ActSpace
  ptlist
  'LeaderIndex
)
     )
    )
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attach mleader to existing text/mtext?
« Reply #1 on: November 29, 2007, 11:00:35 AM »
I have no MLeader experience. Does this not work?
Code: [Select]
(vlax-put ldr_obj "Annotation" txt_obj)
« Last Edit: November 29, 2007, 11:02:31 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Attach mleader to existing text/mtext?
« Reply #2 on: November 29, 2007, 11:20:17 AM »
Does this do what you want?

Code: [Select]
(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
  (cond
    ;;Select the text/mtext objects
    ((or
       (null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
       (= 0 (setq ssl (sslength ss1)))
     )
     nil ;nothing selected
    )
    (T
     (setq
       Textobj (vlax-ename->vla-object (ssname ss1 0))
       ActSpace (if (= 0 (getvar "cvport"))
  (vla-get-paperspace
    (vla-get-activedocument (vlax-get-acad-object))
  )
  (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object))
  )
)
       StartPt (getpoint "\nPick location for point of arrow head: ")
       txt (vla-get-TextString Textobj)
       TextPt (vla-get-insertionpoint textobj)
       TextPt (vlax-variant-value TextPt)
       TextPt (vlax-safearray->list TextPt)
       ptlist (vlax-make-safearray
  vlax-vbdouble
  '(0 . 5)
)
       ptlist (vlax-safearray-fill ptlist (append StartPt TextPt))
       MLObj (vla-addmleader
  ActSpace
  ptlist
  'LeaderIndex
)
     )
     (vla-put-textstring mlobj txt)
     (vla-delete Textobj)
    )
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mkweaver

  • Bull Frog
  • Posts: 352
Re: Attach mleader to existing text/mtext?
« Reply #3 on: November 29, 2007, 01:05:51 PM »
I'll have to take a look at this and see if there is an equivalent property for the mleader object.

Thanks for the pointer.

I have no MLeader experience. Does this not work?
Code: [Select]
(vlax-put ldr_obj "Annotation" txt_obj)

mkweaver

  • Bull Frog
  • Posts: 352
Re: Attach mleader to existing text/mtext?
« Reply #4 on: November 29, 2007, 01:13:25 PM »
This will certainly put the text value into the new text for the leader, but it ignores all of the other properties for the text, like style, width, height, insertion/alignment points...  I know we can step through each of these properties transferring them as appropriate, I was just hoping to avoid that excercise. :|

Does this do what you want?

Code: [Select]
(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
  (cond
    ;;Select the text/mtext objects
    ((or
       (null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
       (= 0 (setq ssl (sslength ss1)))
     )
     nil ;nothing selected
    )
    (T
     (setq
       Textobj (vlax-ename->vla-object (ssname ss1 0))
       ActSpace (if (= 0 (getvar "cvport"))
  (vla-get-paperspace
    (vla-get-activedocument (vlax-get-acad-object))
  )
  (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object))
  )
)
       StartPt (getpoint "\nPick location for point of arrow head: ")
[color=red]       txt (vla-get-TextString Textobj)[/color]
       TextPt (vla-get-insertionpoint textobj)
       TextPt (vlax-variant-value TextPt)
       TextPt (vlax-safearray->list TextPt)
       ptlist (vlax-make-safearray
  vlax-vbdouble
  '(0 . 5)
)
       ptlist (vlax-safearray-fill ptlist (append StartPt TextPt))
       MLObj (vla-addmleader
  ActSpace
  ptlist
  'LeaderIndex
)
     )
[color=red]     (vla-put-textstring mlobj txt)
     (vla-delete Textobj)[/color]
    )
  )
)