Hello,
I am working on a LISP function that takes an existing multileader object in the drawing, extracts some information from it (such as its current textbox width, text contents, and location), recreates the multileader, and deletes the original multileader. (Don't worry about the actual practical uses of such a function).
I got it working in general. The only thing that I cannot get fully working is the landing location. I'll explain the problem with the following images:
1) Original multileader object, properties palette shows "Middle of Text" attachment, as seen on the multileader as desired.
---
2) Function is run on the multileader. This is how it's displayed right after running the function. The original one has been deleted and replaced with the one shown below.
Notice how the way the landing location is graphically displayed on the multileader suggests the landing location would be set to the "Middle of Top Line" setting, but properties palette shows otherwise, still "Middle of Text".---
3) Turns out, the multileader object just needs to be "refreshed" in order to display the attachment properly. In order to refresh it, I just double click on the text to go into the Text Editor (image a), and without making any change at all, I exit the Text Editor by clicking anywhere else outside of the text. By refreshing the MLeader like this, the landing location snaps back to the middle of text (image b).
a)
b)
---
The problem here is that refreshing the multileader in such a way is very time-consuming. I want to be able to engage the function and have the new MLeader be created with the attachment properly set.
This is the code I have written so far for this function:
(defun c:exampleFunction
() ; name function (setq mleadertemp
(entsel "\nPick MLeader")) ; pick MLeader (setq mleaderID
(car mleadertemp
)) ; entsel returns two values when selecting mleader, this extracts only first val (setq mleader
(entget mleaderID
)) ; association list for selected mleader
(setq text
(cdr(assoc 304 mleader
))) ; retrieves text content of mleader (setq width
(cdr(assoc 43 mleader
))) ; retrieves text width of mleader
(setq c
-1) ; set counter to -1 (setq len
(length mleader
)) ; len is length of mleader (setq num
1) ; association list element (< c (- len 1))
(/= num 302)
)
) ; c contains the nth element with LEADER
(repeat c
; Removes items from mleader assoc list (setq mleader
(vl-remove (nth 0 mleader
) mleader
)) ; Removes items to expose leader location )
(setq pt1
(cdr(assoc 10 mleader
))) ; retrieves coords of landing location (setq m
6) ; Removes items from mleader assoc list (setq mleader
(vl-remove (nth 0 mleader
) mleader
)) ; Removes items to expose arrowhead )
(setq pt2
(cdr(assoc 10 mleader
))) ; retrieves coords of arrowhead
(command "_.erase" mleadertemp
"") ; erase leader picked
(setq ent
(entlast)) ; Set entity to newly created MLeader (setq newmleader
(entget ent
)) ; newly created mleader to modify width (entmod ; modify width of new mleader )
) ; defun
I have attempted to use (entupd newmleader) at the end but I don't think it worked.
I should mention that I'm not very experienced with AutoLISP programming. I understand some underlying principles, but I find myself quite stuck at this point. Maybe somebody could point me in the right direction? Appreciate any input.