乐筑天下

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

[编程交流] Polyline vertext - set "name"

[复制链接]

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 17:41:44 | 显示全部楼层 |阅读模式
Hello everybody,
I want to define points in  autolisp, like this: select a polyline, and the first vertex to be set as P1, the second vertex P2......and so on...  vertex n to be Pn .... something possible? how? Any idea? Thanks!
回复

使用道具 举报

0

主题

375

帖子

385

银币

限制会员

铜币
-7
发表于 2022-7-5 17:46:58 | 显示全部楼层
You can do this
  1. (setq i 0)(foreach n lst (set (read (strcat "P" (itoa (setq i (1+ i))))) n) )
... but, IMO, you can always use (nth n lst) when you need Pn value...
回复

使用道具 举报

0

主题

4

帖子

4

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:49:40 | 显示全部楼层
try this :
 
 
  1. (defun c:test( / es ent str vtxlist c txtsize)(defun make_TEXT (content textstyle layer color coo degree textsize / txt_list);;entmake text (if (null textstyle) (setq textstyle "standard")) (setq txt_list (list (cons 0 "TEXT") (cons 1 content) (cons 7 textstyle) (cons 8 layer) (cons 62 color) (cons 10 coo) (cons 50 degree) (cons 40 textsize)))   (entmake txt_list) (entlast))(if (setq es (car (entsel "\nSelect Polyline >> "))) (progn  (setq ent (entget es))  (setq str "name");;;  (setq vtxlist '())  (mapcar '(lambda (x)   (if (eq (car x) 10)    (setq vtxlist (append vtxlist (list (cdr x))))   )           )  ent);mapcar  (setq c 1 txtsize 1)  (foreach vtx vtxlist   (make_text (strcat str (itoa c)) nil (getvar "clayer") 10 vtx 0 txtsize)   (setq c (1+ c))  ) ) (alert "CANCELED"))(princ))
回复

使用道具 举报

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 17:54:30 | 显示全部楼层
Hi Kraz,
I want to use P1 , P2...Pn to draw somethig else with them... shoult be somethig like polar function in autolisp, to define that point. To explain better, i want to draw lines from P1, P2...Pn to other points already defined with polar function - i don't need to add text in drawing for each vertex... i just want to set these points ...
Let's say i want to make a lisp that will draw vertical lines from every vertex of a polyline, perpendicular on a horizontal line - this is why i need P1, P2...Pn. I hope you understand me.
Thanks!
回复

使用道具 举报

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 17:55:56 | 显示全部楼层
Now i use a lisp that need to select every vertex of a polyline to define P1, P2, ..Pn. And i want to define these points only by selecting that polyline...
回复

使用道具 举报

0

主题

375

帖子

385

银币

限制会员

铜币
-7
发表于 2022-7-5 17:59:13 | 显示全部楼层
I thought I answered your question in previous post but if you want more, here it is
 
  1. (defun C:TEST ( / i ss) (if   (setq i 0 ss (ssget ":E:S" '((0 . "LWPOLYLINE"))))   (foreach n     (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0))))     (set (read (strcat "P" (itoa (setq i (1+ i))))) n) ; - here you can draw a line like (entmakex (list '(0 . "LINE") (cons 10 n) (cons 11 some_point)))   ) ))
However, I still think that your approach is wrong. You can draw those lines without setting (global) variables P1 ... Pn
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-5 18:00:57 | 显示全部楼层
You should be able to do what you're wanting (bigger picture) without declaring global variables... If you're going to use Visual LISP, then just go straight for the vlax-curve* functions (IMO). :wink:
回复

使用道具 举报

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 18:04:30 | 显示全部楼层
Thanks Stefan it's exactly what i want... You are right, is not a good approach , but i already have a big lisp that use in many places P1, P2.... Thanks!
回复

使用道具 举报

22

主题

326

帖子

185

银币

后起之秀

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

铜币
243
发表于 2022-7-5 18:08:15 | 显示全部楼层
So in the end of rountine, you should put
  1. (repeat i   (set (read (strcat "P" (itoa i))) nil )(setq i (1- i)))
or sth similar to clear global variables ...
回复

使用道具 举报

62

主题

466

帖子

404

银币

后起之秀

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

铜币
310
发表于 2022-7-5 18:10:52 | 显示全部楼层
maybe
 
  1. (defun c:test ( / e n ) (while   (not     (and (setq e (car (entsel "\nSelect polyline: ")))       (eq "LWPOLYLINE" (cdr (assoc 0 (setq e (entget e)))))       (setq n 0)     )   ) ) (foreach x e   (if (eq 10 (car x))     (set        (read          (strcat "p"            (itoa              (setq n (1+ n))           )         )       ) (cdr x)     )   ) ) (princ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-2 15:07 , Processed in 0.447108 second(s), 73 queries .

© 2020-2025 乐筑天下

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