Bill Tillman 发表于 2022-7-5 22:12:48

使用带编号的Lis格式化多行文字

我正在使用LISP在图形的注释部分添加一些文本,并希望使用编号列表。在搜索如何格式化字符串以添加数字时,我只找到了有限的信息。当列表在页面上时,我需要它看起来像这样
 
到目前为止,我发现pxi可以做这样的事情,但我还没有找到在需要时打开和关闭它的正确方法。

hanhphuc 发表于 2022-7-5 22:19:50

嗨,比尔,
多行文字确实有编号,但不能像你的#3段那样压缩。
我不确定系统变量是否要控制?
我还需要知道
 
[这是备选方案]
我将创建包含2列x几行的acad表
左列用于为文本编号,右列用于较长的文本。
在所需单元格中填写文本后,
分解表格,通过简单的例程删除分解的行。
 
0.02年款

Bill Tillman 发表于 2022-7-5 22:23:33

谢谢我已经了解了AutoCAD如何通过创建多行文字列表并查看其属性来格式化带编号的多行文字列表。请参阅随附的屏幕截图。如果我正确地遵循这一点,我首先需要知道列表中的项目数。这是我臭名昭著的自动化过程,所以周围没有用户点击鼠标或输入文本。列表中的项目数始终会因创建的图形类型而异。所以我想我可以先通过可选特性,为每个要包含的特性增加一个计数器,这样我就可以格式化字符串。。。。但我仍然认为必须有一个更简单的方法。
 
顺便说一句,根据您使用的屏幕分辨率,上面的列表将以不同的方式显示。我可能对此感到震惊,但多行文字确实会压缩,也就是说,如果其中一个段落需要换行,它会缩进文本,就像我所展示的那样。这正是我想要的,在使用多行文字打印字符串之前,我只需要弄清楚如何格式化字符串。

BlackBox 发表于 2022-7-5 22:27:22

账单
 
只需按您想要的方式设置多行文字,然后浏览多行文字对象的TextString属性。
 
例子:
 

\pxi-3,l3,t3;1.Note #1\P2.Note #2\P3.Note #3 and this paragraph shows how the text will be formatted correctly and wrap the desired way with an indent on the left side to align with the other text using a numbered list.\P4.Note #4

Bill Tillman 发表于 2022-7-5 22:31:26

也许不是。。。。哇,黑匣子,看起来你那里有东西。现在,是pxi-3,l3在我使用的示例中有点混乱,因为它有三个项目。我只是在列表中添加了一些项目,并注意到pxi-3保持不变。所以,看起来我所要做的就是重新安装我之前使用的计数器。。。。该死的,我真的希望多行文字能帮我处理自动增量。这并不容易,但我想我现在能做到。谢谢

BlackBox 发表于 2022-7-5 22:39:43

试试看。。。在这里工作:
 

(vl-load-com)

(defun _AddNumberedListToMText (oMText lst / i)
(setq i 0)
(vla-put-textstring
   oMText
   (strcat
   "\\pxi-3,l3,t3;"
   (vl-string-right-trim
       "\\P"
       (apply
         'strcat
         (mapcar
         (function
             (lambda (x)
               (strcat (itoa (setq i (1+ i))) ".\t" x "\\P")
             )
         )
         lst
         )
       )
   )
   )
)
)

 
 
快速演示,不支持撤消;我知道这是自动完成的,因此上面的子功能是:
 

(defun c:FOO (/ ss)
(if (setq ss (ssget ":S:E:L" '((0 . "MTEXT"))))
   (_AddNumberedListToMText
   (vlax-ename->vla-object (ssname ss 0))
   '("Note #1"
       "Note #2"
       "Note #3 and this paragraph shows how the text will be formatted correctly and wrap the desired way with an indent on the left side to align with the other text using a numbered list."
       "Note #4"
      )
   )
)
(princ)
)

 
 
 
[编辑]-从技术上讲,它取代了现有的文本字符串,并且不会“添加”到其中,因此一如既往,从中获取您喜欢的内容。只是想澄清一下。

Bill Tillman 发表于 2022-7-5 22:42:00

再次感谢黑匣子。我想我需要更多的人手来拿这个。下面是我用来构建字符串的代码:

(setq Features "\\LSELECTED FEATURES\\l\\P\\pxi-3,l3,t3;"
       fcount 1)
(if (= field1 "Y")
   (setq Features(strcat Features (itoa fcount) ".Feature Field1\\P"
         fcount (1+ fcount)   
         )
   )

(if (= field2 "Y")
   (setq Features(strcat Features (itoa fcount) ".Feature Field2\\P")
         fcount (1+ fcount)
         )
   )

   (if (= field3 "Y")
   (setq Features(strcat Features (itoa fcount) ".Feature Field3\P")
             fcount (1+ fcount)
         )
   )

(if (= field4 "Y")
   (setq Features(strcat Features (itoa fcount) ".Feature Field4\\P")
         fcount (1+ fcount)
         )
   )
.
and so on, and so on.....
.

(command "._MTEXT" '(8.6875 7.6875) '(10.40625 3.5) Features "")

注意,我构建了一个字符串,而不是一个列表。全部完成后,字符串中将包含1到16行项目。这是可行的,但我并没有得到一个真正的编号列表。您的示例适用于选择集。。。。我不知道如何将其转换为完全无人操作。我开始倾向于使用ENTMAKE方法来实现这一点。。。!

BlackBox 发表于 2022-7-5 22:45:20

 
首先,第二个产品只是提供子功能概念的手动演示,而不是供您的生产使用。
 
第二,我真的希望你从一开始就提供代码,因为这样可以节省我的时间等。请在可能的情况下继续。至于您的代码,字段1 IF语句的“then”表达式中似乎有一个错位的paren,字段3 IF语句的“then”表达式中似乎有一个反斜杠,因为这个轻微的修改在这里起作用:
 

(setq Features "\\LSELECTED FEATURES\\l\\P\\pxi-3,l3,t3;"
   fcount   1
)
(if (= field1 "Y")
(setq Features (strcat Features (itoa fcount) ".Feature Field1\\P")
       fcount (1+ fcount)
)
)
(if (= field2 "Y")
(setq Features (strcat Features (itoa fcount) ".Feature Field2\\P")
       fcount   (1+ fcount)
)
)
(if (= field3 "Y")
(setq Features (strcat Features (itoa fcount) ".Feature Field3\\P")
       fcount   (1+ fcount)
)
)
(if (= field4 "Y")
(setq Features (strcat Features (itoa fcount) ".Feature Field4\\P")
       fcount   (1+ fcount)
)
)
;|
and so on, and so on.....
|;
(command "._MTEXT" '(8.6875 7.6875) '(10.40625 3.5) Features "")

 
 
 
干杯

Bill Tillman 发表于 2022-7-5 22:51:38

谢谢,很抱歉给您带来了困惑。我认为ENTMAKE可能会这样做。。。
 

(defun C:TEST (/ str)
(doit "SELECTED FEATURES:\\P\\pxi-3,l3,t3;1.\tTHIS IS LINE ITEM #1\\P2.\tTHIS IS LINE ITEM #2\\P3.\tTHIS IS LINE ITEM #3 AND IT'S A LOT LONGER STRING OF TEXT THAN THE OTHER ITEMS\\P4.\tTHIS IS THE LAST LINE ITEM")

(defun doit (str)

(entmake
   (list
   (cons 0 "MTEXT")
   (cons 100 "AcDbEntity")
   (cons 67 0)
   (cons 410 "Model")
   (cons 8 "Text2")
   (cons 100 "AcDbMText")
   (cons 10 '(8.32062 8.01356 0.0))
   (cons 40 0.08)
   (cons 41 4.16978)
   (cons 46 0.0)
   (cons 71 1)
   (cons 72 5)
   (cons 1 str)
   (cons 7 "DIM")
   (cons 210 '(0.0 0.0 1.0))
   (cons 11 '(1.0 0.0 0.0))
   (cons 42 3.8781)
   (cons 43 0.792381)
   (cons 50 0.0)
   (cons 73 1)
   (cons 44 1.0)
   )
)
(princ)
)

这是有效的,它实际上正在建立我正在寻找的编号列表。我只需要在位置(x,y,z)上做一些工作来放置它,并在正确构建传递给它的字符串上做更多的工作。我想我仍然需要使用计数器来正确构建字符串。午饭后我会继续这样做。

hanhphuc 发表于 2022-7-5 22:58:18

是 啊好提示!
你们什么都知道。谢谢你给了我正确的方向!
谢谢你,比尔
页: [1] 2
查看完整版本: 使用带编号的Lis格式化多行文字