johmmeke 发表于 2022-7-6 07:31:21

Layername's to Mleader ;

hey all
 
I'm try to put the name of selected layers to a Mleader.
Keep getting; error bad argument type: lentitype ("layer1" "layer2" "layer3")
i think this is a correct string list, can i get it in a mleader with each string on the next line?
 

(defun c:LTL (/ spc p1 p2 str lead) (vl-load-com) ;; Tharwat 08. 07. 2011 (cond ((not acdoc)      (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))       ) ) (setq spc (if (> (vla-get-activespace acdoc) 0)             (vla-get-modelspace acdoc)             (vla-get-paperspace acdoc)         ) ) (while   (and   (setq p1 (getpoint "\n specify First Point :"))   (setq p2 (getpoint p1 "\n Specify Second point :"));;;(setq ss (ssget)) (progn   (repeat (setq i (sslength ss))   (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i)))))))   (if (not (member layer lst)) (setq lst (cons layer lst)))   )   (setq lst (acad_strlsort lst)) );;;(setq str lst);;;      )    (progn      (setq lead (vla-addmleader                   spc                   (vlax-make-variant                     (vlax-safearray-fill                     (safearray vlax-vbdouble '(0 . 5))                     (apply 'append (list p1 p2))                     )                   )                   0               )      )      (vla-put-textstring lead (cdr (assoc 8 (entget str))))    ) ) (princ))thx for the help
 
ps not native english

pBe 发表于 2022-7-6 07:40:28

(vla-put-textstring      lead       (apply 'strcat (mapcar '(lambda (x) (strcat x "\\P")) str))      )Remember to localized the lst variable or reset at every loop
 

(defun c:LTL (spc p1 p2 str lead lst)
...(setq lst nil p1 (getpoint "\n specify First Point :"))....

johmmeke 发表于 2022-7-6 07:51:25

pBe thx voor de help
now it works perfect
 
i am looking at the code
i don't understand this line
 

... (setq lst nil p1 (getpoint "\n specify First Point :"))....
setq and then 3 variable ?
sorry just start learning and i'm not that good at it
 
 
maybe some help on how to count the objects in my selection on each layer
 
Greetz john

pBe 发表于 2022-7-6 07:59:45

 
Good for you
 
 
same as

(setq lst nil)(setq p1 (getpoint "\n specify First Point :"))
 
But with the and condition we cannot code it that way, as it evaluates to nil at the first expression and will exit the loop.
 
There's nothing magical about that john, the way the original code was written (kudos to Tharwat) at every loop it checks the lstvariable for the selected entities layer name.
 
To explain to you the effect without resetting the lst variable
Lets say selected entities layer are "B1" and "C4"
(if
(not (member layer lst))
(setq lst (cons layer lst)))
 
same goes for C4 layer name.
 
("B1" "C4") as current value for lst variable
 
Now fornext loop, selected objects layers are "D5" and "E1"
 
Layers "D5" and "E1" will be included on the lst.
 
Current value of lst variable would be ("B1" "C4" "D5" "E1") but remember you did not select any objects on "B1" or "C4" layer. and you will get"B1" "C4" "D5" "E1" as string value for you mleader.hence the reset at the start of the loop.
 
But then again, we can always reset the lst variable here to avoid confusion on your part.

(setq str lst lst nil)
 
as for this one
 
Yes, it can be doneGo ahead and show us the desired result.

johmmeke 发表于 2022-7-6 08:08:44

pBE thx for the time you put in to explain this to me.
 
For the desired result..
i post a screen shot of it. To keep it simple i have given the layers the name of the colors the lines have, the elipse is my selection.
 

 
so it only counts the lines i select ..
 
please keep the code simple
 
greetz John

pBe 发表于 2022-7-6 08:16:34

(defun c:LTL (/ spc p1 p2 str lead f lst) (vl-load-com) ;; Tharwat 08. 07. 2011                ;; ;; modified by pBe sep 15 2012        ;;(cond ((not acdoc)      (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))       ) ) (setq spc (if (> (vla-get-activespace acdoc) 0)             (vla-get-modelspace acdoc)             (vla-get-paperspace acdoc)         ) ) (while   (and   (setq p1 (getpoint "\n specify First Point :"))   (setq p2 (getpoint p1 "\n Specify Second point :"))(setq ss (ssget)) (progn   (repeat (setq i (sslength ss))   (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i)))))))    (if (setq f (assoc layer lst))      (setq lst (subst (list layer (1+ (cadr f))) f lst))        (setq lst (cons (list layer 1) lst)))   ) (setq lst (vl-sort lst '(lambda (a b)             (< (car a)(car b))))) )   )    (progn      (setq str (mapcar '(lambda (j)   (strcat (itoa (cadr j)) "x " (car j))) lst))      (setq lst nil lead (vla-addmleader                   spc                   (vlax-make-variant                     (vlax-safearray-fill                     (safearray vlax-vbdouble '(0 . 5))                     (apply 'append (list p1 p2))                     )                   )                   0               )      )      (vla-put-textstring      lead      (apply 'strcat (mapcar '(lambda (x) (strcat x "\\P")) str))      )    ) ) (princ))
 
HTH

johmmeke 发表于 2022-7-6 08:23:44

Works perfect pBe, thx for the help
 
now gonna try to take your extra code and learn something from it.
that mapcar lamda is not that easy.
 
thx again,
greetz John

pBe 发表于 2022-7-6 08:37:40

 
You are welcome, Glad i could help
 
 
http://www.cadtutor.net/forum/showthread.php?52127-Mapcar-lambda-Description
页: [1]
查看完整版本: Layername's to Mleader ;