Author Topic: MLEADER arrow coordinates  (Read 8583 times)

0 Members and 1 Guest are viewing this topic.

CHulse

  • Swamp Rat
  • Posts: 504
Re: MLEADER arrow coordinates
« Reply #15 on: April 29, 2020, 11:13:05 AM »
In my case, I was given a dwg with mleaders representing tree locations and tag numbers (about 1000 of them) from a client. So I didn't have a choice.
I'll revisit this, but I hope I don't ever need to use it again :)
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

dexus

  • Bull Frog
  • Posts: 207
Re: MLEADER arrow coordinates
« Reply #16 on: June 23, 2023, 05:44:09 AM »
I've read the topic a while ago, and experimented on my own, and came with this solution for myself:

Code: [Select]
(if (and (vl-catch-all-error-p (vl-catch-all-apply '(lambda (x) (vlax-invoke x 'getleaderlineindexes 1)) (list acadObj)))
    (= (vl-catch-all-error-message (vl-catch-all-apply '(lambda (x) (vlax-invoke x 'getleaderlineindexes 1)) (list acadObj)))
"AutoCAD.Application: Invalid index"))
       (setq sde_ml_indxlist (vlax-invoke acadObj 'getleaderlineindexes 0))
       (if (and (vl-catch-all-error-p (vl-catch-all-apply '(lambda (x) (vlax-invoke x 'getleaderlineindexes 0)) (list acadObj)))
   (= (vl-catch-all-error-message (vl-catch-all-apply '(lambda (x) (vlax-invoke x 'getleaderlineindexes 0)) (list acadObj)))
       "AutoCAD.Application: Invalid index"))
(setq sde_ml_indxlist (vlax-invoke acadObj 'getleaderlineindexes 1))
(setq sde_ml_indxlist (vl-sort (append (vlax-invoke acadObj 'getleaderlineindexes 0)
(vlax-invoke acadObj 'getleaderlineindexes 1)) '<))))

This way I can retrieve lineindexes that answer to either ”0”, or ”1”, or both at the same time (when mleader has leaders in both directions).

1st I check if mleader fails to deliver "1"-leaderlineindexes. If it fails, it means it can only deliver "0"-leaderlineindexes. It retrieves "0"-leaderlineindexes.
Than I check vice-versa.
If both these fail-verifications fail, this means that both deliveries "0" and "1" leaderlineindexes is possible.
So, as 3rd option, my routine retrieves all "0" and "1" leaderlineindexes.
It also sort's them in ascending order.

The only thing my routine doesn't handle properly, is the case when mleader doesn't have leaders at all... But well, I don't run my routing on such mleaders  :whistling:

Nice, this was exactly what I was looking for. Thank you!
I moved some things around and added a check for multileaders without any leaders.
Here is the result for anyone who tries to get all the leader information:

Code - Auto/Visual Lisp: [Select]
  1. (defun getLeaderIndexes (obj / _invalidIndex-p)
  2.   ; -----------------------------------
  3.   ; getLeaderIndexes
  4.   ; -----------------------------------
  5.   ; Returns a list of all valid indexes of a multileader
  6.   ; Input: vla-object of the multileader
  7.   ; Output: list of all valid indexes
  8.   ; -----------------------------------
  9.   ; Source:      https://www.theswamp.org/index.php?topic=55023.msg614986#msg614986
  10.   ; By:          Kycau (29-04-2020)
  11.   ; Modified by: dexus (23-06-2023)
  12.  
  13.   (defun _invalidIndex-p (obj in) ; Check if index is not valid
  14.     (and
  15.       (vl-catch-all-error-p (vl-catch-all-apply (function (lambda (x) (vlax-invoke x 'getleaderlineindexes in))) (list obj)))
  16.       (= (vl-catch-all-error-message (vl-catch-all-apply (function (lambda (x) (vlax-invoke x 'getLeaderLineIndexes in))) (list obj)))
  17.         "AutoCAD.Application: Invalid index"
  18.       )
  19.     )
  20.   )
  21.  
  22.   (cond
  23.     ((= (vla-get-leaderCount obj) 0) nil) ; No leaders
  24.     ((_invalidIndex-p obj 1) (vlax-invoke obj 'getLeaderLineIndexes 0)) ; Only leaders found in 0
  25.     ((_invalidIndex-p obj 0) (vlax-invoke obj 'getLeaderLineIndexes 1)) ; Only leaders found in 1
  26.     ((vl-sort (append (vlax-invoke obj 'getLeaderLineIndexes 0) (vlax-invoke obj 'getLeaderLineIndexes 1)) '<)) ; Both
  27.   )
  28. )