乐筑天下

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

[编程交流] 对对象重新排序

[复制链接]

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:14:57 | 显示全部楼层 |阅读模式
大家好!有文本对象,每个图形都是一个单独的对象,其顺序如下:
 
1 6 3
4 7 2
5 8 9
 
应尽可能在程序上始终将其更改为以下程序:
 
1 2 3
4 5 6
7 8 9
 
我试图在X和Y上使用排序函数,但结果并非如此。有没有一种方法可以同时在两个轴上排序,或者有更简单的解决方案?这可能很明显,但我看不到)
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 06:22:20 | 显示全部楼层
你试过这个吗?
 
  1. (setq l '(4 7 8 2 1 6 3 5 9))
  2. (vl-sort l '<)
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:27:02 | 显示全部楼层
谢谢你们的回复!其实事情的实质是,事先不会知道文本的位置,在不同的情况下,它可以以不同的方式定位。这是整个问题的症结所在,并且有一个可预测的结果。我看到脚本可能会尝试自己添加它。
071502olaafad8allm4uf7.jpg
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 06:36:30 | 显示全部楼层
 
您可以尝试在代码中添加一些“模糊”,这样,如果文本略低于另一个文本,它仍将按行计算。此外,我在不同的路线上测试了它,但它似乎并不适用于所有路线,其他人可能能够解释为什么。。。
回复

使用道具 举报

171

主题

447

帖子

276

银币

中流砥柱

Rank: 25

铜币
860
发表于 2022-7-6 06:40:38 | 显示全部楼层
谢谢李先生,我现在有主意了。
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 06:49:32 | 显示全部楼层
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:51:22 | 显示全部楼层
 
See this explanation.
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 06:59:11 | 显示全部楼层
This was kind of fun...
 
What you need to keep in mind is that, in your drawing, it appears that your '1' is below '2&6' and your '9' is below your '8' so the order in which my program will sort will take hat into account and it wont look right as it sorts from upper left to lower right. I'm sure you can take it and mess around with it to fit your needs though
 
  1. (defun c:ArrangeText ( / textSS textList sortedTextList sortedPointList) (vl-load-com) (if (setq textSS (ssget "x" (list (cons 0 "TEXT")(cons 410 "Model"))))   (progn     (setq textList (mapcar 'vlax-ename->vla-object  (vl-remove-if 'listp (mapcar 'cadr (ssnamex textSS)))))     (setq sortedTextList (vl-sort textList '(lambda (x y) (< (atoi (vla-get-Textstring x)) (atoi (vla-get-Textstring y))))))     (setq sortedPointList (SortPoints (mapcar '(lambda (x) (vlax-get x "InsertionPoint")) textlist)))     (mapcar '(lambda (x y) (vlax-put x "InsertionPoint" y)) sortedTextList sortedPointList)     ))           )(defun SortPoints ( l ) (setq l (vl-sort l   '(lambda (x y)      (cond        ((= (cadr x)(cadr y))  (< (car x)(car y)))        ((> (cadr x)(cadr y)))        )      )   )) )
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:07:59 | 显示全部楼层
Thank you guys for responding! In fact of the matter is that will not be known in advance the position of text in different cases, it can be located in different ways. This is the whole problem and have a predictable outcome. I see the script may try to add it by yourself.
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 07:11:42 | 显示全部楼层
 
You can try to add some "fuzz" in the code so that if the text is slightly lower than the other it will still count as in line. Also, I tested it on different alignments, and it doesn't seem to work on all alignments, someone else may be able to explain why...
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:49 , Processed in 0.586187 second(s), 74 queries .

© 2020-2025 乐筑天下

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