乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 47|回复: 7

[编程交流] Layername's to Mleader ;

[复制链接]

1

主题

23

帖子

22

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:31:21 | 显示全部楼层 |阅读模式
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?
 
  1. (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

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 07:40:28 | 显示全部楼层
  1. (vla-put-textstring        lead       [color=navy] (apply 'strcat (mapcar '(lambda (x) (strcat x "\\P")) str))[/color]        )
Remember to localized the lst variable or reset at every loop
 
  1. (defun c:LTL (spc p1 p2 str lead [i][b] lst[/b][/i])
  1. ...(setq [color=blue][i][b]lst nil[/b][/i][/color] p1 (getpoint "\n specify First Point :"))....
回复

使用道具 举报

1

主题

23

帖子

22

银币

初来乍到

Rank: 1

铜币
5
发表于 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
 
  1. ... (setq [color=blue][i][b]lst nil[/b][/i][/color] 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

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 07:59:45 | 显示全部楼层
 
Good for you
 
 
same as
  1. (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 lst  variable 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 for  next 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.
  1. (setq str lst [b][i][color="blue"]lst nil[/color][/i][/b])
 
as for this one
 
Yes, it can be done  Go ahead and show us the desired result.
回复

使用道具 举报

1

主题

23

帖子

22

银币

初来乍到

Rank: 1

铜币
5
发表于 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.
 
083124wrpxr2onrvorprcp.jpg
 
so it only counts the lines i select ..
 
please keep the code simple  
 
greetz John
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 08:16:34 | 显示全部楼层
  1. (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)))))))    [color="blue"] (if (setq f (assoc layer lst))        (setq lst (subst (list layer (1+ (cadr f))) f lst))        (setq lst (cons (list layer 1) lst)))   )[/color]  [color="blue"] (setq lst (vl-sort lst '(lambda (a b)             (< (car a)(car b)))))[/color] )   )    (progn      [color="blue"](setq str (mapcar '(lambda (j)   (strcat (itoa (cadr j)) "x " (car j))) lst))[/color]      (setq [color="blue"]lst nil[/color] 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
回复

使用道具 举报

1

主题

23

帖子

22

银币

初来乍到

Rank: 1

铜币
5
发表于 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

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 08:37:40 | 显示全部楼层
 
You are welcome, Glad i could help
 
 
http://www.cadtutor.net/forum/showthread.php?52127-Mapcar-lambda-Description
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 04:15 , Processed in 0.504088 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表