MLeader-generating LISP function not updating the new MLeader object

MLeader-generating LISP function not updating the new MLeader object

MauCabrera789
Enthusiast Enthusiast
888 Views
6 Replies
Message 1 of 7

MLeader-generating LISP function not updating the new MLeader object

MauCabrera789
Enthusiast
Enthusiast

I'm working on a function that extracts information from an MLeader (text box width, text contents, and location), creates a new MLeader with this information, and deletes the original MLeader.

 

The routine works in general, except there's an issue with the landing location of the newly-created MLeader. I'll describe the issue with images:

 

1) Original MLeader object (Note: landing attachment location is set to "Middle of Text", consistent with graphical display)

 

Capture(1).jpg

 

---

2) Running the function on this MLeader deletes the original and creates a new one, shown below. Note: the new MLeader displays as if attachment was "Middle of Top Line" yet properties show "Middle" still.

 

Capture(1)(1).jpg

 

---

3) Turns out this new MLeader just needs to be "refreshed" to get the attachment location to snap back to the middle of text as the properties show. To refresh it, all I have to do is go into the Text Editor (double click the text - image a), and without making any change, exit the Text Editor (click anywhere). After doing this, MLeader "refreshes" and landing attachment shows correctly (image b).

 

a)

Capture(2).jpg

 

b)

Capture.JPG

 

---

The issue is that manually refreshing leaders like this is very time consuming. How can I edit my LISP function to refresh the MLeader? I have tried (entupd newmleader) but it didn't work. Would appreciate any input or direction. See below for my code:

 

(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
(while 
	(and
		(< c (- len 1))
		(/= num 302)
	)
		(setq c (+ c 1))
		(setq element (nth c mleader))
		(setq num (car element))
)								; 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
(repeat m
	(setq mleader (vl-remove (nth 0 mleader) mleader))	; Removes items to expose arrowhead
)
(setq pt2 (cdr(assoc 10 mleader)))				; retrieves coords of arrowhead

(command "MLEADER" pt2 pt1 text) 				

(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 
	(setq newmleader (subst (cons 43 width) (assoc 43 newmleader) newmleader))
)

(princ)

) 								; defun

 

0 Likes
Accepted solutions (1)
889 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

I would give up on using autolisp on mleaders. Rather use the setpropertyvalue function or vla-* 

This works:

(command "MLEADER" "non" pt2 "non" pt1 text) ; turn off osnaps! (no relation to your current issue)
(setpropertyvalue (entlast) "TextLeftAttachmentType" 2)

0 Likes
Message 3 of 7

MauCabrera789
Enthusiast
Enthusiast

Thanks for your input.

 

I added the line as such, but the issue still remains: I still need to manually go into the MLeader text editor and exit out of that to refresh the MLeader so the landing attachment refreshes and shows correctly.

 

Any other ideas?

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

post dwg

0 Likes
Message 5 of 7

MauCabrera789
Enthusiast
Enthusiast

Here you go. 

 

I have set MLEADERSCALE to 20 (what I use), and set the current Text and MLeader style to the appropriate styles. 

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Setting a width this way seems to do the trick.

(setpropertyvalue (entlast) "MText/Width" 24)

 

Anyway, are you aware that you're losing the mtext paragraph formatting (centre) by this?

 

Message 7 of 7

MauCabrera789
Enthusiast
Enthusiast

Yes, setting that property did do the trick.

 

I switched it to: 

(setpropertyvalue (entlast) "MText/Width" width)

so the extracted width of the original MLeader is kept. The MLeader still gets refreshed.

 

Neat trick, I wonder why setting the value of that particular property caused the MLeader to get refreshed, maybe setting other properties have the same effect, but we at least know setting the property "TextLeftAttachmentType" didn't refresh the object.

 

Yes, I'm aware I may be losing some of the properties that the original MLeader held. Just wanted to make something quick that works for now, as time goes on and I use the function, I'll probably have to polish it as I discover unintended effects.

0 Likes