How to get start and end points of an existing mleader

How to get start and end points of an existing mleader

dwattersAMXH5
Enthusiast Enthusiast
4,283 Views
34 Replies
Message 1 of 35

How to get start and end points of an existing mleader

dwattersAMXH5
Enthusiast
Enthusiast

hello, 

I am building a lisp to select mleaders and replace them with new mleaders in the same location (changing note in mleader, with data pulled from object data) 
to do this i am going to need to get the start and end point location of the existing leader to plug in to the command to build the new mleader. 
I will also use the start point to populate an nentselp to pull new object data from the object at the point. 

to better clarify - 
i have built a lisp to label a line with an mleader which pulls attributes out of object data.
the best way i can see to automatically update the mleader with new object data (other then doing a find and replace on the text) is to complete delete the original mleader and replace with a new mleader in its exact place which would pull update object data information. 


it will be easy to ssget by the layer because all of these are on a specific layer. and then run a for reach to pull the setq variables i need, delete old one, make new one. i am just not sure about how to get the start and end point data out of the existing mleader so that i can plug those values into the setq variables. 

 

 

can anyone explain the function to do this or at least point me in a direction so that i can do my own searching.

 

thanks for any help in this, 
i can post my starting lisp for the initial mleader if that helps 

0 Likes
Accepted solutions (1)
4,284 Views
34 Replies
Replies (34)
Message 2 of 35

dwattersAMXH5
Enthusiast
Enthusiast
(defun C:MLDR2LDR (/ ss data leader-10-list start-pt last-pt one-before-the-last-pt
                     lyr curlyr)
  (setvar "cmdecho" 0)
  (setq curlyr (getvar "clayer"))
  (command "UNDO" "mark") ;undo mark
  (prompt "Enter all for Selection: ")
  (setq ITEMS (ssget '((0 . "MULTILEADER")))) ;select items
  (setq i (sslength ITEMS)) ;counter
  (while (> i 0) ;while items left
    (defun massoc	(key EntData / x nlist)
      (foreach x EntData
        (if (eq key (CAR x))
         (setq nlist (cons (cdr x) nlist))
        ) ;_ end of if 
      ) ;_ end of foreach 
      (reverse nlist)
    ) ;_ end of DEFUN
    (setq i (1- i)) ;decrement counter
    (setq EN (ssname ITEMS i)) ;get name
    (setq data (entget EN)) ;entity info
    (setq lyr (cdr (assoc 8 data)))
    (setq leader-10-list (massoc 10 data))
    (setq start-pt (nth 2 leader-10-list)) ;_ 3dr
    (setq last-pt (nth 0 leader-10-list)) ;_1st
    (setq one-before-the-last-pt (nth 1 leader-10-list)) ;_ 2nd

so if I'm understanding this right - 

  (setq ITEMS (ssget '((0 . "MULTILEADER")(8."LAYER NAME"))) ;select items
  (setq i (sslength ITEMS)) ;counter
  (while (> i 0) ;while items left
    (defun massoc	(key EntData / x nlist)
      (foreach x EntData
        (if (eq key (CAR x))
         (setq nlist (cons (cdr x) nlist))
        ) ;_ end of if 
      ) ;_ end of foreach 
      (reverse nlist)
    ) ;_ end of DEFUN
    (setq i (1- i)) ;decrement counter
    (setq EN (ssname ITEMS i)) ;get name
    (setq data (entget EN)) ;entity info
    (setq lyr (cdr (assoc 8 data)))
    (setq leader-10-list (massoc 10 data))
    (setq pt1 (nth 2 leader-10-list)) ;_ 3dr
    (setq pt2 (nth 0 leader-10-list)) ;_1st
(setq str "whatever i want to say")
(command "erase") (command "mleader" pt1 pt2 str)


should select the correct 10 code for start and second point and erase and build a new mleader for each leader? 

any chance someone can explain the 10 code a little better? 

0 Likes
Message 3 of 35

ronjonp
Advisor
Advisor
Accepted solution

From my experience with mleaders, I've found the using the vla-* functions are much easier to use than DXF data. You can get the leader points with vla-GetLeaderLineVertices. Some examples HERE.

0 Likes
Message 4 of 35

dwattersAMXH5
Enthusiast
Enthusiast

THANK YOU!  i knew there had to be a better way, i just couldn't find the function to learn lol. i've only ever used dxf data for setting limits on ssget, so trying to use it for this wasn't my ideal path. 

0 Likes
Message 5 of 35

ronjonp
Advisor
Advisor

@dwattersAMXH5 wrote:

THANK YOU!  i knew there had to be a better way, i just couldn't find the function to learn lol. i've only ever used dxf data for setting limits on ssget, so trying to use it for this wasn't my ideal path. 


Glad to help.

0 Likes
Message 6 of 35

dwattersAMXH5
Enthusiast
Enthusiast

if you wouldnt mind - 
can you explain vla-getleaderlinevertices a bit,
so when i call a CAR or CDR on the (vlax-invoke o 'getleaderlinevertices 0) will it return x,y,z?  
so if i have a standard mleader with a start and end point i could make a setq of (car '((vlax-invoke o 'getleaderlinevertices 0)) to get point 1, and a setq of (cdr '(...)) to get point 2? 

or is it CAR going to just return the first X? 

0 Likes
Message 7 of 35

dwattersAMXH5
Enthusiast
Enthusiast
(defun C:RELFQ (/)
  (vl-load-com)
  (setq ITEMS (ssget '((0 . "MULTILEADER")(8 . "TEXT_FQNID"))) ;select items
  (setq i (sslength ITEMS)) ;counter
  (while (> i 0) ;while items left
    (setq obj (vlax-ename->vla-object (items))
    (setq ptlist (vlax-invoke obj 'getleaderlinevertices 0))
    (setq pt1 (car '(ptlist))
    (setq pt2 (cdr '(ptlist))
    (setq str "string for mleader")
    (command "delete")
    (command "mleader" pt1 pt2 str)
  );while
  (setvar "cmdecho" 1)
  (princ)
) ;defun

like this basically? 

0 Likes
Message 8 of 35

ronjonp
Advisor
Advisor

The list is 'flat' .. ie, the first second and 3rd items are X Y Z. You need to group them like so if you want to use 'car' and 'cadr' to get the points.

(defun group3 (lst / r)
  (while lst (setq r (cons (list (car lst) (cadr lst)) r)) (setq lst (cdddr lst)))
  (reverse r)
)
(vlax-invoke (vlax-ename->vla-object (car (entsel))) 'getleaderlinevertices 0)
;; getleaderlinevertices returns
(11.5718 20.9301 0.0 24.5069 36.1893 0.0)
(setq l (group3 '(11.5718 20.9301 0.0 24.5069 36.1893 0.0)))
;; group3 returns
((11.5718 20.9301) (24.5069 36.1893))

 

0 Likes
Message 9 of 35

dwattersAMXH5
Enthusiast
Enthusiast

ok so this is quickly going over my head lol 
so heres my lisp to make a mleader with the info i want. 

actually it enters model space,sets the right layer, makes the label, exits model space, and goes back to 0 layer.

(defun c:LFQ (/)
(command "mspace") ;enter model space 
(command "clayer" "TEXT_FQNID") ;set current layer 
  (princ "\nSelect SOURCE object: ")
  (setq source_obj (car (nentsel)))
  (if (null source_obj)
    (prompt "\nNo source object selected.")
    (progn
      (setq lst (ade_odgettables source_obj))
      (setq fqnid (ade_odgetfield source_obj lst "FQN_ID" 0))
      (setq clength (rtos (ade_odgetfield source_obj lst "CALCULATED" 0) 2 2))
      (setq fibercnt (rtos (ade_odgetfield source_obj lst "NUMBEROFFI" 0) 2 0))
      (setq wrkord (ade_odgetfield source_obj lst "WORKORDERI" 0))
      (setq fqnidstr (strcat "\nFQNID#: " fqnid))
      (setq clengthstr (strcat "\nLENGTH: " clength " FT"))
      (setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt))
      (setq wrkordstr (strcat "\nWORK ORDER: " wrkord))
      (setq ctype (lisped  "1"))
      (setq ctypestr (strcat ctype "-2\" %%C HDPE"))
      (setq str (strcat ctypestr fqnidstr clengthstr fibercntstr wrkordstr))
      (command "mleader" pause pause str)
      (command "pspace")
    );progn
    );if
    (command "clayer" "0")
)

i want to keep the code close to this if possible - 

but rather then picking the source object off the bat i want to 

(setq mldr (ssget "X" '((0 . "MULTILEADER")(8 . "TEXT_FQNID")))) ; select mleaders

get all mleaders on text_fqnid layer 

I THINK that should look something like this 

(defun c:RELFQ (/)
(vl-load-com)
(command "clayer" "TEXT_FQNID") ;set current layer
(setq mldr (ssget "X" '((0 . "MULTILEADER")(8 . "TEXT_FQNID")))) ; select mleaders
(setq i (sslength mldr))



(while (> i 0)
;;(setq pt1 "point 1 of mleader") ;;turn the points location into a variable that can be plugged in later in (x,y) format
;;(setq pt2 "Point 2 of mleader")
;;magic


(setq source_obj (car (nentselp pt1))) ;the first point of the mleader will always be o-snaped at the object we want to pull data from
  (if (null source_obj)
    (prompt "\nNo source object selected.")
    (progn
      (setq lst (ade_odgettables source_obj))
      (setq fqnid (ade_odgetfield source_obj lst "FQN_ID" 0))
      (setq clength (rtos (ade_odgetfield source_obj lst "CALCULATED" 0) 2 2))
      (setq fibercnt (rtos (ade_odgetfield source_obj lst "NUMBEROFFI" 0) 2 0))
      (setq wrkord (ade_odgetfield source_obj lst "WORKORDERI" 0))
      (setq fqnidstr (strcat "\nFQNID#: " fqnid))
      (setq clengthstr (strcat "\nLENGTH: " clength " FT"))
      (setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt))
      (setq wrkordstr (strcat "\nWORK ORDER: " wrkord))
      (setq ctype (lisped  "1"))
      (setq ctypestr (strcat ctype "-2\" %%C HDPE"))
      (setq str (strcat ctypestr fqnidstr clengthstr fibercntstr wrkordstr))
      (command "mleader" pt1 pt2 str)
    );progn
    );if
    );while
);defun




0 Likes
Message 10 of 35

ronjonp
Advisor
Advisor

Sorry I'm not familiar with 'ade_odgettables' .. one thing I see is you need to learn how to iterate a selection set by converting it a list of items ... here's a simple example.

(defun c:foo (/ _ss2objlist s)		; Localize variables after the /
  ;; Function to convert a selection set to a list of vla-object
  (defun _ss2objlist (l)
    (if	l
      (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex l))))
    )
  )
  ;; If we select some multileaders that are not on a locked layer ( 's' is the variable localized above )
  (if (setq s (ssget ":L" '((0 . "multileader"))))
    ;; Then convert the selection to a list of objects 
    (foreach object (_ss2objlist s)
      ;; and iterate the list using 'foreach' changing each 'object' within the loop to color red
      (vla-put-color object 1)
    )
  )
  ;; SSSSHHHHHHH
  (princ)
)
0 Likes
Message 11 of 35

dwattersAMXH5
Enthusiast
Enthusiast

 'ade_odgettables' doesnt really have anything to do with getting the start and end points for the mleader, 

heres what is going on there, basically just pulling information out of an object data table to populate the text in the mleader 

(setq source_obj (car (nentselp pt1))) ;;; this is where i need the points from vla-getleaderlinevertices
  (if (null source_obj)
    (prompt "\nNo source object selected.")
    (progn
      (setq lst (ade_odgettables source_obj));;get the name of the object data tables for a selection
      (setq fqnid (ade_odgetfield source_obj lst "FQN_ID" 0)) ;;get object data field "FQN_ID" from table called with lst 
      (setq clength (rtos (ade_odgetfield source_obj lst "CALCULATED" 0) 2 2));;get object data field "calculated from lst table and turn real to string 
      (setq fibercnt (rtos (ade_odgetfield source_obj lst "NUMBEROFFI" 0) 2 0));; same as above but with "numberoffi" field
      (setq wrkord (ade_odgetfield source_obj lst "WORKORDERI" 0));;get field for "workordferi" field in lst table 
      (setq fqnidstr (strcat "\nFQNID#: " fqnid)) ;;the rest strcats each line together 
      (setq clengthstr (strcat "\nLENGTH: " clength " FT"))
      (setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt))
      (setq wrkordstr (strcat "\nWORK ORDER: " wrkord))
      (setq ctype (lisped  "1")) ;;this calls for the user to specify the quanity of an item 
      (setq ctypestr (strcat ctype "-2\" %%C HDPE")) ;;strcats the user defined quantity 
      (setq str (strcat ctypestr fqnidstr clengthstr fibercntstr wrkordstr)) ;; puts everything together 
      (command "mleader" pt1 pt2 str) ;; this is where i need the points from vla-getleaderlinevertices
    );progn
    );if
0 Likes
Message 12 of 35

ronjonp
Advisor
Advisor

Try this:

(if (setq pts (vlax-invoke source_obj 'getleaderlinevertices 0))
  (command "_.mleader"
	   (list (car pts) (cadr pts) (caddr pts))
	   (list (car (setq pts (cdddr pts))) (cadr pts) (caddr pts))
	   str
  )
)
0 Likes
Message 13 of 35

dwattersAMXH5
Enthusiast
Enthusiast

Is that in conjunction to 

(defun _ss2objlist (l)
  (if	l
    (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex l))))
  )
)
(if (setq s (ssget ":L" '((0 . "multileader")(8 . "TEXT_FQNID"))))
(foreach object (_ss2objlist s)

 

 

i think this is really close excpet source_obj isnt a leader its a line the leader is pointing to. 
if i call s from the selection set in place of source_obj will that generate what we are looking for? 

here is where i am sitting 

(defun c:RELFQ (/)
(vl-load-com)
(command "clayer" "TEXT_FQNID") ;set current layer
(setq mldr (ssget "X" '((0 . "MULTILEADER")(8 . "TEXT_FQNID")))) ; select mleaders
(setq i (sslength mldr))




(defun _ss2objlist (l) (if l (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex l)))) ) ) (if (setq s (ssget ":L" '((0 . "multileader")(8 . "TEXT_FQNID")))) (foreach object (_ss2objlist s) (if (setq pts (vlax-invoke s 'getleaderlinevertices 0)) (setq pt1 (list (car pts) (cadr pts) (caddr pts))) (setq pt2 (list (car (setq pts (cdddr pts))) (cadr pts) (caddr pts))) )



(setq source_obj (car (nentselp pt1))) ;;; this is where i need the points from vla-getleaderlinevertices (if (null source_obj) (prompt "\nNo source object selected.") (progn (setq lst (ade_odgettables source_obj));;get the name of the object data tables for a selection (setq fqnid (ade_odgetfield source_obj lst "FQN_ID" 0)) ;;get object data field "FQN_ID" from table called with lst (setq clength (rtos (ade_odgetfield source_obj lst "CALCULATED" 0) 2 2));;get object data field "calculated from lst table and turn real to string (setq fibercnt (rtos (ade_odgetfield source_obj lst "NUMBEROFFI" 0) 2 0));; same as above but with "numberoffi" field (setq wrkord (ade_odgetfield source_obj lst "WORKORDERI" 0));;get field for "workordferi" field in lst table (setq fqnidstr (strcat "\nFQNID#: " fqnid)) ;;the rest strcats each line together (setq clengthstr (strcat "\nLENGTH: " clength " FT")) (setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt)) (setq wrkordstr (strcat "\nWORK ORDER: " wrkord)) (setq ctype (lisped "1")) ;;this calls for the user to specify the quanity of an item (setq ctypestr (strcat ctype "-2\" %%C HDPE")) ;;strcats the user defined quantity (setq str (strcat ctypestr fqnidstr clengthstr fibercntstr wrkordstr)) ;; puts everything together (command "mleader" pt1 pt2 str) ;; this is where i need the points from vla-getleaderlinevertices );progn );if );foreach );if );defun

 

0 Likes
Message 14 of 35

dwattersAMXH5
Enthusiast
Enthusiast
(defun C:RELFQ (/)
  (setvar "cmdecho" 0)
  (command "clayer" "TEXT_FQNID")
  (prompt "Selecting all Mleaders on layer : \"TEXT_FQNID\"")
  (setq ITEMS (ssget "X" (list '(0 . "MULTILEADER")'(8 . "TEXT_FQNID"))))
  (setq i (sslength ITEMS))
  (while (> i 0)
    (defun massoc	(key EntData / x nlist)
      (foreach x EntData
        (if (eq key (CAR x))
         (setq nlist (cons (cdr x) nlist))
        )
      )
      (reverse nlist)
    )
    (setq i (1- i))
    (setq EN (ssname ITEMS i))
    (setq data (entget EN))
    (setq lyr (cdr (assoc 8 data)))
    (setq leader-10-list (massoc 10 data))
    (setq pt1 (nth 2 leader-10-list))
    (setq pt2 (nth 1 leader-10-list))
    (setq pt3 '(pt1))
    (setq source_obj (nentselp pt3))
      (if (null source_obj)
        (prompt "\nNo source object selected.")
        (progn
          (setq tbl (ade_odgettables source_obj))
          (setq fqnid (ade_odgetfield source_obj tbl  "FQN_ID" 0))
          (setq clength (rtos (ade_odgetfield source_obj tbl "CALCULATED" 0) 2 2))
          (setq fibercnt (rtos (ade_odgetfield source_obj tbl "NUMBEROFFI" 0) 2 0))
          (setq wrkord (ade_odgetfield source_obj tbl "WORKORDERI" 0))
          (setq fqnidstr (strcat "\nFQNID#: " fqnid))
          (setq clengthstr (strcat "\nLENGTH: " clength " FT"))
          (setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt))
          (setq wrkordstr (strcat "\nWORK ORDER: " wrkord))
          (setq str (strcat fqnidstr clengthstr fibercntstr wrkordstr))
          (command "erase" EN "")
          (command "mleader" pt1 pt2 str)
        );progn
      );if
  );while
  (setvar "cmdecho" 1)
  (command "clayer" "0")
  (alert "RELFQ : COMPLETE")
  (princ)
) ;defun

I ended up getting this to work except nentselp doesnt want to play nice with it yet. it does get all the points to build the new mleader though. 

0 Likes
Message 15 of 35

ronjonp
Advisor
Advisor

I'm still confused on what you are trying to accomplish .. First it was a single selection, then multiple .. then you reverted back to DXF codes?

 

FWIW here's a quick example using the 'accepted solution' with some comments. Remember to localize variables too...

(defun c:relfq (/	   clength    clengthstr data	    en	       fibercnt	  fibercntstr
		fqnid	   fqnidstr   i		 items	    leader-10-list	  lyr
		pt1	   pt2	      pt3	 pts	    source_obj str	  tbl
		wrkord	   wrkordstr
	       )			; <- This is variable localization and it's important
  ;; No need to define massoc in a while loop .. only do it once
  ;; This also is not needed anymore if you use 'getleaderlinevertices
  (defun massoc	(key entdata / x nlist)
    (foreach x entdata
      (if (eq key (car x))
	(setq nlist (cons (cdr x) nlist))
      )
    )
    (reverse nlist)
  )
  (setvar "cmdecho" 0)
  (command "clayer" "TEXT_FQNID")
  (prompt "Selecting all Mleaders on layer : \"TEXT_FQNID\"")
  (setq items (ssget "X" (list '(0 . "MULTILEADER") '(8 . "TEXT_FQNID"))))
  (setq i (sslength items))
  (while (> i 0)
    (setq i (1- i))
    (setq en (ssname items i))
    (setq data (entget en))		; <- This is not needed with 'getleaderlinevertices
    (setq lyr (cdr (assoc 8 data)))	; <- This is not used anywhere?
    (setq leader-10-list (massoc 10 data)) ; <- This is not needed with 'getleaderlinevertices
    (setq pts (vlax-invoke (vlax-ename->vla-object en) 'getleaderlinevertices 0))
    (setq pt1 (list (car pts) (cadr pts) (caddr pts)))
					; <- First three elements in 'getleaderlinevertices
    (setq pt2 (list (car (setq pts (cdddr pts))) (cadr pts) (caddr pts)))
					; <- Next three elements in 'getleaderlinevertices
    (setq pt3 '(pt1))			; <- Why the quoted point .. this will return (PT1) which is NOT a point?
    (setq source_obj (nentselp pt3)); <- This should not ever work because the point format is incorrect .. I think you mean (setq source_obj (nentselp pt1))
    (if	(null source_obj)
      (prompt "\nNo source object selected.")
      (progn (setq tbl (ade_odgettables source_obj))
	     (setq fqnid (ade_odgetfield source_obj tbl "FQN_ID" 0))
	     (setq clength (rtos (ade_odgetfield source_obj tbl "CALCULATED" 0) 2 2))
	     (setq fibercnt (rtos (ade_odgetfield source_obj tbl "NUMBEROFFI" 0) 2 0))
	     (setq wrkord (ade_odgetfield source_obj tbl "WORKORDERI" 0))
	     (setq fqnidstr (strcat "\nFQNID#: " fqnid))
	     (setq clengthstr (strcat "\nLENGTH: " clength " FT"))
	     (setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt))
	     (setq wrkordstr (strcat "\nWORK ORDER: " wrkord))
	     (setq str (strcat fqnidstr clengthstr fibercntstr wrkordstr))
	     (command "erase" en "")
	     (command "_.mleader" pt1 pt2 str)
      )					;progn
    )					;if
  )					;while
  (setvar "cmdecho" 1)
  (command "clayer" "0")
  (alert "RELFQ : COMPLETE")
  (princ)
)

 

0 Likes
Message 16 of 35

dwattersAMXH5
Enthusiast
Enthusiast

yea i know it wasnt working 

(setq source_obj (nentselp '(pt1)))

returned  - error: bad argument type: 2D/3D point: (PT1)

 

had tested this last because first running  : 

 

(setq source_obj (nentselp pt1))

returned - error: bad argument type: numberp: nil

0 Likes
Message 17 of 35

ronjonp
Advisor
Advisor

Well glad you got it sorted.

0 Likes
Message 18 of 35

dwattersAMXH5
Enthusiast
Enthusiast

thank you, your code works perfect - 

nentselq is causing the problem because its not finding anything at pt1 (the mleader start location which is o-snapped to the line it should be finding)

i don't get whats going on there except that when i run a test and prnt pt1 
i get (2.61436e+06 1.26179e+06 0.0)

and the real point where the mleader is being placed is 2614364.09040, 1261791.96721, 0.0 
maybe nentselp is trying to use the scientific (2614360.00, 1261790.00, 0.0) and causing a rounding?

but if mleader used the correct value (2614364.09040) i dont see why nentselp would use the "rounded" scientific value (2614360.00)

 

 

0 Likes
Message 19 of 35

ronjonp
Advisor
Advisor

That's just a visual output based on units and precision. The point being used is full precision. What you might need to do to get that object is use a crossing window with ssget and a fuzz value to get more accurate results. Post a sample drawing.

0 Likes
Message 20 of 35

dwattersAMXH5
Enthusiast
Enthusiast

yea thats what i thought on the precision, but i got to the point where i was like "well maybe nentselp just does its own thing and isnt taking my point right" because i wasnt seeing any other reason for it not to work correctly, lol. 

 

This is the lisp i am using to test that the (nentselp pt1) worked and if it was accessing the item at that point which was returning pt1 and nil 

(defun c:relfqtest (/	   clength    clengthstr data	    en	       fibercnt	  fibercntstr
		fqnid	   fqnidstr   i		 items	    leader-10-list	  lyr
		pt1	   pt2	      pt3	 pts	    source_obj str	  tbl
		wrkord	   wrkordstr
	       )			; <- This is variable localization and it's important
  (setvar "cmdecho" 0)
  (command "clayer" "TEXT_FQNID")
  (prompt "Selecting all Mleaders on layer : \"TEXT_FQNID\"")
  (setq items (ssget "X" (list '(0 . "MULTILEADER") '(8 . "TEXT_FQNID"))))
  (setq i (sslength items))
  (while (> i 0)
    (setq i (1- i))
    (setq en (ssname items i))
    (setq pts (vlax-invoke (vlax-ename->vla-object en) 'getleaderlinevertices 0))
    (setq pt1 (list (car pts) (cadr pts) (caddr pts)))
					; <- First three elements in 'getleaderlinevertices
    (setq pt2 (list (car (setq pts (cdddr pts))) (cadr pts) (caddr pts)))
					; <- Next three elements in 'getleaderlinevertices
    (setq source_obj (nentselp pt1))
    (if	(null source_obj)
      (prompt "\nNo source object selected.")
      (progn (setq tbl (ade_odgettables source_obj))
	     (setq fqnid (ade_odgetfield source_obj tbl "FQN_ID" 0))
			 (print pt1)
			 (print fqnid)
      )					;progn
    )					;if
  )					;while
  (setvar "cmdecho" 1)
  (alert "RELFQ : COMPLETE")
  (princ)
)

attached is a sample drawing. 

in real use the line will be xreffed but nentselp should work the same over an xref or a block as in this dwg. 

 

(defun c:LFQ (/)
(command "mspace") ;enter model space
(command "clayer" "TEXT_FQNID") ;set current layer
(princ "\nSelect SOURCE object: ")
(setq source_obj (car (nentsel)))
(if (null source_obj)
(prompt "\nNo source object selected.")
(progn
(setq lst (ade_odgettables source_obj))
(setq fqnid (ade_odgetfield source_obj lst "FQN_ID" 0))
(setq clength (rtos (ade_odgetfield source_obj lst "CALCULATED" 0) 2 2))
(setq fibercnt (rtos (ade_odgetfield source_obj lst "NUMBEROFFI" 0) 2 0))
(setq wrkord (ade_odgetfield source_obj lst "WORKORDERI" 0))
(setq fqnidstr (strcat "FQNID#: " fqnid))
(setq clengthstr (strcat "\nLENGTH: " clength " FT"))
(setq fibercntstr (strcat "\nFIBER SIZE: " fibercnt))
(setq wrkordstr (strcat "\nWORK ORDER: " wrkord))
(setq str (strcat fqnidstr clengthstr fibercntstr wrkordstr))
(command "mleader" pause pause str)
(command "pspace")
);progn
);if
(command "clayer" "0")
)

this is the lisp to make an initial mleader 

0 Likes