乐筑天下

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

[编程交流] SSGET - Polyline Select by Clo

[复制链接]

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 15:28:20 | 显示全部楼层 |阅读模式
I am have a selection that is to get closed polylines on the indicated layer.  The goal is if the closed polyline has 6 vertices then that polyline will be changed to another layer.
 
I need help with the middle bit.
 
  1. (defun c:Test ( / in ss en get vtx) (if (setq in -1 ss (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "*POLYLINE") (8 . "DIMLDR") [color=red](70 . 1)[/color])))   (while (setq en (ssname ss (setq in (1+ in))))     [color=purple]{count vertices of closed polyline}     {if vertex count = 6 change to another layer}[/color]     )   ) (princ) )
Does the selection at least appears that it will work?
 
Greg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 15:48:44 | 显示全部楼层
 
There are many ways to approach this:
 
If you are only working with 2D polylines (LWPOLYLINEs), then you can filter the polylines by number of vertices directly from the ssget filter list, using DXF group 90:
  1. ([color=BLUE]defun[/color] c:test1 ( [color=BLUE]/[/color] i s x )   ([color=BLUE]if[/color]       ([color=BLUE]setq[/color] s           ([color=BLUE]ssget[/color] [color=MAROON]"_C"[/color]              '( 7.244  2.071)              '(16.665 10.003)              '(                   (0 . [color=MAROON]"LWPOLYLINE"[/color])                   (8 . [color=MAROON]"DIMLDR"[/color])                   (90 . 6)                   (-4 . [color=MAROON]"&="[/color]) (70 . 1)               )           )       )       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))           ([color=BLUE]setq[/color] x ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))))           ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(8 . [color=MAROON]"PolylinesWith6Vertices"[/color]) ([color=BLUE]assoc[/color] 8 x) x))       )   )   ([color=BLUE]princ[/color]))
 
Note that DXF group 70 is bit-coded, therefore I have used the Bitwise Masked Equals operator in the filter list to essentially perform a (= 1 (logand 1 (cdr (assoc 70 )))) check. You can find more information about this technique here.
 
However, if you are working with a combination of both 2D lightweight polylines (LWPOLYLINEs) and 2D & 3D 'heavy' polylines (POLYLINEs), you would need to perform the check on the number of vertices from within the loop, as the number of vertices is not stored in the DXF data for a POLYLINE entity.
 
For this, you could use the following:
  1. ([color=BLUE]defun[/color] c:test2 ( [color=BLUE]/[/color] c e i s x )   ([color=BLUE]if[/color]       ([color=BLUE]setq[/color] s           ([color=BLUE]ssget[/color] [color=MAROON]"_C"[/color]              '( 7.244  2.071)              '(16.665 10.003)              '(                   (-4 . [color=MAROON]""[/color])                   (8 . [color=MAROON]"DIMLDR"[/color])                   (-4 . [color=MAROON]"&="[/color]) (70 . 1)               )           )       )       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))           ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)                 e ([color=BLUE]ssname[/color] s i)                 x ([color=BLUE]entget[/color] e)                 c 0           )           ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"POLYLINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 x)))               ([color=BLUE]while[/color] ([color=BLUE]=[/color] [color=MAROON]"VERTEX"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ([color=BLUE]setq[/color] e ([color=BLUE]entnext[/color] e))))))                   ([color=BLUE]setq[/color] c ([color=BLUE]1+[/color] c))               )               ([color=BLUE]setq[/color] c 6)           )           ([color=BLUE]if[/color] ([color=BLUE]=[/color] c 6)               ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(8 . [color=MAROON]"PolylinesWith6Vertices"[/color]) ([color=BLUE]assoc[/color] 8 x) x))           )       )   )   ([color=BLUE]princ[/color]))
 
Here, note the use of the additional bitwise test on the value of DXF group 70 when filtering POLYLINE entities to exclude 3D polygon meshes (DXF group 70 = 16) and polyface meshes (DXF group 70 = 64). This is equivalent to (zerop (logand 80 (cdr (assoc 70 ))))
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 16:01:00 | 显示全部楼层
I also liked this one :
 
  1. (1+ (vlax-curve-getendparam (vlax-ename->vla-object (car (entsel "\nSelect polyline: ")))))
http://forums.augi.com/showthread.php?48293-No-of-Vertices-in-a-PolyLine/page2
 
I'm not sure about the 1+ though...
 
but I admit , most of the time the only polylines I use in my field of work (electrical / instrumentation) are just plain square (and boring) 2D poly's so I don't really know what I'm talking about...
 
gr. Rlx
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 16:15:27 | 显示全部楼层
 
Lee, you are da man!  Thank you, sir!  Worked like a Rolex.
 
Greg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:20:39 | 显示全部楼层
You're welcome Greg, happy to help.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:29:18 | 显示全部楼层
Just an alternative and Lee you have given me the answer for some old code, using VL you can get the co-ordinates and how many adding the "is it a Polyline or a Lwpolyline" ? The number of x y or xyz points is divided by either 2 or 3. Will have a play. It will not work with some of the other objects that you have checked for.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 13:08 , Processed in 0.365108 second(s), 64 queries .

© 2020-2025 乐筑天下

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