Author Topic: MLeader-generating LISP function not updating newly-created MLeader object  (Read 1114 times)

0 Members and 1 Guest are viewing this topic.

Mau Cabrera

  • Mosquito
  • Posts: 3
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:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:exampleFunction ()                                     ; name function
  2. (setq mleadertemp (entsel "\nPick MLeader"))            ; pick MLeader
  3. (setq mleaderID (car mleadertemp))                              ; entsel returns two values when selecting mleader, this extracts only first val
  4. (setq mleader (entget mleaderID))                               ; association list for selected mleader
  5.  
  6. (setq text (cdr(assoc 304 mleader)))                            ; retrieves text content of mleader
  7. (setq width (cdr(assoc 43 mleader)))                            ; retrieves text width of mleader
  8.  
  9. (setq c -1)                                             ; set counter to -1
  10. (setq len (length mleader))                     ; len is length of mleader
  11. (setq num 1)                                    ; association list element
  12.         (and
  13.                 (< c (- len 1))
  14.                 (/= num 302)
  15.         )
  16.                 (setq c (+ c 1))
  17.                 (setq element (nth c mleader))
  18.                 (setq num (car element))
  19. )                                                       ; c contains the nth element with LEADER
  20.                                                        
  21. (repeat c                                                                               ; Removes items from mleader assoc list
  22.         (setq mleader (vl-remove (nth 0 mleader) mleader))      ; Removes items to expose leader location
  23. )
  24. (setq pt1 (cdr(assoc 10 mleader)))                                      ; retrieves coords of landing location
  25. (setq m 6)                                                                              ; Removes items from mleader assoc list
  26.         (setq mleader (vl-remove (nth 0 mleader) mleader))      ; Removes items to expose arrowhead
  27. )
  28. (setq pt2 (cdr(assoc 10 mleader)))                                      ; retrieves coords of arrowhead
  29.  
  30. (command "MLEADER" pt2 pt1 text)                               
  31.  
  32. (command "_.erase" mleadertemp "")                                      ; erase leader picked
  33.  
  34. (setq ent (entlast))                                                            ; Set entity to newly created MLeader
  35. (setq newmleader (entget ent))                                          ; newly created mleader to modify width
  36. (entmod                                                                         ; modify width of new mleader
  37.         (setq newmleader (subst (cons 43 width) (assoc 43 newmleader) newmleader))
  38. )
  39.  
  40.  
  41. )                                                                                       ; defun
  42.  

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.

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

Mau Cabrera

  • Mosquito
  • Posts: 3
Thank you tombu for posting that link, indeed I did post the same question over at the AutoDesk forums.

By the way, it's been solved over there by the user Z9E3zK5E.