poffenberger 发表于 2022-7-5 16:12:52

帮助lisp将文本移动到

我需要lisp的帮助来将多(3)行文本移动到一个点或一个插入点。前几天,我得到了一个很棒的人的帮助,他指导我使用点管理器,然后使用lisp将文本移动到点,效果很好。我想以某种方式合并类似的逻辑,将(3)行文本(多(3)行文本)移动到相对于每组(3)行文本字符串的公共点。请参阅附件中的视觉叙述。任何帮助都将不胜感激。我还将与大家分享txt2pt代码,希望它能在这种情况下发挥作用。
 
我要提前感谢大家,
 
保罗
移动绿色文本。图纸
移动绿色文本。pdf
txt2pt。LSP
PtManagerV2-4。lsp

ronjonp 发表于 2022-7-5 16:17:26

 
根据您的示例图纸。。试试这个:
(defun c:foo (/ p t1 t2 t3 x y)
;; RJP - 07.07.2017
;; Load visual lisp
(vl-load-com)
;; This is a the y offset for text based on example drawing
;; (setq y 0.145833)
(cond
   ;; If no text on layer "OLI_IDTEXT" are in the drawing exit and prompt
   ((null (setq t1 (ssget "_x" '((0 . "text") (8 . "OLI_IDTEXT")))))
    (print "'OLI_IDTEXT' text not found!")
   )
   ;; If no text on layer "OLI_ANTEXT" are in the drawing exit and prompt
   ((null (setq t2 (ssget "_x" '((0 . "text") (8 . "OLI_ANTEXT")))))
    (print "'OLI_ANTEXT' text not found!")
   )
   ;; Rock and roll.. compile a list of all the green text to be moved as a list of ((<alignment_point> . ename)...)
   ((setq
      t2 (mapcar '(lambda (x) (cons (cdr (assoc 11 (entget x))) x)) (mapcar 'cadr (ssnamex t2)))
    )
    ;; Changed to be a 2X factor of the text height in drawing
    (setq y (* 2. (cdr (assoc 40 (entget (cdr (car t2)))))))
    ;; Foreach base text
    (foreach base (mapcar 'cadr (ssnamex t1))
      ;; Grab the alignment point to move to
      (setq p (cdr (assoc 11 (entget base))))
      (if
;; Sort the 'green text' list by distance
(and (setq t3 (vl-sort t2 '(lambda (a b) (< (distance p (car a)) (distance p (car b))))))
      ;; and check that we have at least 3 items in the sorted list
      (>= (length t3) 3)
);; For the first 3 items in sorted green text list ( closest to base text )
(foreach x (list (car t3) (cadr t3) (caddr t3))
    ;; Move the text using the base text x value and incrementing the y value by 2X the text height
    (vlax-invoke
      (vlax-ename->vla-object (cdr x))
      'move
      (car x)
      (setq p (list (car p) (+ y (cadr p)) 0.0))
    )
    ;; Remove the item from the 'green text' list so it won't get processed twice
    (setq t2 (vl-remove x t2))
)
      )
    )
   )
)
;; Shhhh
(princ)
)

poffenberger 发表于 2022-7-5 16:21:27

朗琼普,
谢谢你的回复。
我将您的代码粘贴到visual lisp编辑器中,并保存到。lsp文件。加载的应用程序没有任何错误。在命令行的绘图中,我键入了foo,然后什么都没有。。。没有提示,没有错误。如果我的过程出错,请告诉我。通过对论坛的研究,我认为c之后的foo是命令名吗?
 
谢谢
保罗

ronjonp 发表于 2022-7-5 16:22:31

你在“移动绿色文本”测试图纸上运行了吗?这对我很有效。

poffenberger 发表于 2022-7-5 16:27:39

你太棒了!!
 
我不熟悉这个编码,所以我想问你两件事?
在1-10的范围内(10是最难的),这有多困难?
 
关于起点有什么建议吗?宏的Lisp脚本。他们是否按逻辑顺序排队学习。
 
再次感谢你所做的一切。
 
保罗

Roy_043 发表于 2022-7-5 16:29:11

@罗恩琼普:
这里似乎有一个拼写错误:
您可能只想从t2中删除前3个t3项。

poffenberger 发表于 2022-7-5 16:34:17

Roy_043,
 
这个程序似乎很有效,我有什么遗漏吗?

ronjonp 发表于 2022-7-5 16:37:04

 
罗伊是正确的有一个拼写错误(实际上是一对夫妇)(固定以上)。。它工作正常的原因是因为没有从“t2”列表中删除任何内容,因为我将整个列表称为“t3”,而不是“t3”的单个元素。难度对我来说,我会给它打2分。
在学习的过程中,只要继续努力理解给你的是什么样的常规。。我将对上面的代码进行注释,以便您可以从中学习。

poffenberger 发表于 2022-7-5 16:38:57

朗琼普,
 
我在移动绿色文本dwg文件中出错。出于某种原因,我将dwg缩放了1.5倍,因此您的例行程序可以正常工作,但4行文本之间的距离太大。请以适当的比例查找所附的dwg,我可以麻烦您在移动红色文本图形上重复您的魔术吗。
 
再次感谢
移动红色文本。图纸

ronjonp 发表于 2022-7-5 16:42:12

将:(setq y 0.218751)更改为(setq y 0.145833)。。我还评论了上面的代码,请看一看。
 
事实上我修改了上面的代码,所以它将使用文本高度的2倍作为Y间距,所以现在应该无关紧要了。我真不敢相信你以前会手动操作!
页: [1] 2
查看完整版本: 帮助lisp将文本移动到