对对象重新排序
大家好!有文本对象,每个图形都是一个单独的对象,其顺序如下:1 6 3
4 7 2
5 8 9
应尽可能在程序上始终将其更改为以下程序:
1 2 3
4 5 6
7 8 9
我试图在X和Y上使用排序函数,但结果并非如此。有没有一种方法可以同时在两个轴上排序,或者有更简单的解决方案?这可能很明显,但我看不到) 你试过这个吗?
(setq l '(4 7 8 2 1 6 3 5 9))
(vl-sort l '<)
谢谢你们的回复!其实事情的实质是,事先不会知道文本的位置,在不同的情况下,它可以以不同的方式定位。这是整个问题的症结所在,并且有一个可预测的结果。我看到脚本可能会尝试自己添加它。
您可以尝试在代码中添加一些“模糊”,这样,如果文本略低于另一个文本,它仍将按行计算。此外,我在不同的路线上测试了它,但它似乎并不适用于所有路线,其他人可能能够解释为什么。。。 谢谢李先生,我现在有主意了。
See this explanation. 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
(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))) ) ) )) ) 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.
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...
页:
[1]
2