我经常使用文本对对象进行编号,以指定切割顺序。在过去,我拼凑了一些代码,可以快速增加或减少所有选定的数字文本,以防我出错和/或必须更改某些内容。这非常有效,但我经常发现我需要超越这一点,完全颠倒顺序。
以这段代码为起点,我认为这会非常简单,但我尝试对文本对象进行列表操作的事实完全让我感到厌烦。我对这类事情还是有点陌生。我想我应该得到一个所有选定文本的列表,对其排序,然后在对文本应用更改之前反转该列表。最高的数字与最低的数字交换,第二高的数字与第二低的数字交换,等等。
(“1”“2”)将变为(“2”“1”)
(“2”“1”“4”“5”“3”)将变为(“4”“5”“2”“1”“3”)
(“2”“8”“17”“4”)将变为(“17”“4”“2”“8”)
(“3”“5”“-4”)将变为(“3”“-4”“5”)
我不知道从哪里开始,也不知道使用什么流程。我的主要问题是,我不知道如何在不丢失到正确文本对象的链接的情况下对数据进行排序和编辑。任何帮助都会很棒。这是我尝试开始的快速递增/递减例程。
;Quick Increment/decrement;Increments/decrements all selected text integers by 1;I hacked this code together with help from an "increment in range" routine.;Original code can be found here https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/incriment-numbered-text/td-p/3614646?nobounce;Quick Increment(defun C:qi (/ textselection textobject old) (vl-load-com) (setq textselection (ssget '((0 . "TEXT")))) (repeat (sslength textselection) (setq textobject (vlax-ename->vla-object (ssname textselection 0)) old (vla-get-TextString textobject); initial text content ); setq (if (and (= (strlen old) (strlen (itoa (atoi old)))); text represents integer ; Blocks e.g. "12A", "4.5", "C37", and completely non-numerical ; text [except for next test], but allows negative integers. ; Also disallows e.g. "06", "008", so if those should be included... (if (= (strlen old) 1) (wcmatch old "#") T) ; blocks single non-numerical character e.g. "A" [passes prior test] ); and (vla-put-TextString textobject (itoa (+ (atoi old) 1))); replace ); if (ssdel (ssname textselection 0) textselection) ); repeat (princ) (setq sel1 (ssget "P")) (sssetfirst nil sel1)); defun;Quick decrement(defun C:qd (/ textselection textobject old) (vl-load-com) (setq textselection (ssget '((0 . "TEXT")))) (repeat (sslength textselection) (setq textobject (vlax-ename->vla-object (ssname textselection 0)) old (vla-get-TextString textobject); initial text content ); setq (if (and (= (strlen old) (strlen (itoa (atoi old)))); text represents integer ; Blocks e.g. "12A", "4.5", "C37", and completely non-numerical ; text [except for next test], but allows negative integers. ; Also disallows e.g. "06", "008", so if those should be included... (if (= (strlen old) 1) (wcmatch old "#") T) ; blocks single non-numerical character e.g. "A" [passes prior test] ); and (vla-put-TextString textobject (itoa (- (atoi old) 1))); replace ); if (ssdel (ssname textselection 0) textselection) ); repeat (princ) (setq sel1 (ssget "P")) (sssetfirst nil sel1)); defun