morgos 发表于 2022-7-5 15:32:27

谢谢大家,
上周我忙于做其他事情,
我的意图是从文本文件“插入点就是点本身”中插入一些点的Z值(作为文本),
我成功了,
李的代码和其他人的评论都很有帮助,
再次感谢大家,
这是我最后的代码,为了CadTutor的每个人的利益,
 
 
 

(defun c:spot ( / pt1 file1)
(if (not (tblsearch "Layer" "TEXT"))
(command "-layer" "m" "TEXT" "")
)

(setq file1 (open "E:\\Morgos\\AutoCadd\\sh.csv" "r"))
(setq pt1 (read-line file1))
(while
(/= pt1 nil)
(setq pt (read-line file1))
(setq sx (substr pt 1 9))
(setq sy (substr pt 13 22))
(setq sz (substr pt 26 31))

(setq fx (atof sx))
(setq fy (atof sy))
(setq fz (atof sz))
(setq Lpt (list fx fy fz))
(entmake (list '(0 . "MTEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbMText")
'(8 . "TEXT")
(cons 10 Lpt)
'(40 . 2.5)
(cons 1 sz)
'(50 . 0.0)
'(7 . "STANDARD")
'(71 . 0)
'(72 . 0)
'(73 . 0)
) ;_ end list
) ;_ end entmake
) ;_ end while
(princ)
) ;_ end defun

Lee Mac 发表于 2022-7-5 15:37:29

谢谢Morgos,这是最后一篇慷慨的帖子

Chiron 发表于 2022-7-5 15:39:26

顺便问一下,我们如何使用make text函数插入当前“TEXTWIDTH”的文本?

(defun make_text(txt_pt txt_val)
(entmake (list '(0 . "TEXT")
                '(8 . "0")
                (cons 10 txt_pt)
                (cons 40 (max 2.5 (getvar "TEXTSIZE")))
                (cons 1 txt_val)
                '(50 . 0.0)
                '(7 . "STANDARD")
                '(71 . 0)
                '(72 . 1)
                '(73 . 2)
                (cons 11 txt_pt))))

Chiron 发表于 2022-7-5 15:41:42

我已经解决了:(assoc 41(tblsearch“Style”(getvar“textstyle”))
但我还有另一个问题:它与shx字体不兼容。文本是用错误的位置创建的,文本在双击后被更正。

guitarguy1685 发表于 2022-7-5 15:44:28

首先,thx用于代码Leemac。我有个问题。在线上
 
“(8.“文本”);为不同的图层更改此选项(在引号中键入图层名称)
 
我尝试使用(getvar“CLAYER”)而不是“TEXT”,我得到了以下错误
 
命令:;错误:错误的DXF组:(8 GETVAR“CLAYER”)
 
我可以在这里不使用getvar吗?

CAB 发表于 2022-7-5 15:47:52

使用(cons 8(getvar“CLAYER”))
或者省略这行代码&它将默认为当前层。

guitarguy1685 发表于 2022-7-5 15:50:56

谢谢你,好先生。这就成功了。在过去的两年里,我没有写过任何Lisp程序的东西,我忘了很多!

BIGAL 发表于 2022-7-5 15:53:42

我花了0.05美元,我会把make text defun添加到一个自动加载的lsp例程中,这个例程包含了你所有常用的库,这样你只需要做一行调用就可以使用它。(make\u text(txt\u pt txt\u val))。另一个(insertblock ins\u pt blkname x y ro)
 
例如,我有一个“getval”defun,它弹出一个漂亮的拨号框进行输入,而不是使用getxxxx,它会在屏幕中间弹出消息等。(谢谢AlanJT)

dilan 发表于 2022-7-5 15:58:09

你好
在我的程序中,我使用在光标上插入文本,但存在一个问题。
程序完全执行一次,第二次仅在输入文本高度后完成。我不明白为什么。
以下是发生此错误的部分代码:
(if
       (setq *ht*
         (cond
         ((getdist (strcat "\nSpecify the height of the text <" (if *ht* (rtos *ht* 2 3) "") ">:")))
         (*ht*)
         )
       )
       (progn
         (setq e
         (entmakex
             (list
               '(0 . "MTEXT")
               '(100 . "AcDbEntity")
               '(100 . "AcDbMText")
               (cons 8 "Area")
               (cons 62 256)
               (cons 10 '(0 0 0))
               (cons 7 (getvar 'textstyle))
               (cons 40 *ht*)
               (cons 41 0)
               (cons 1
                     (strcat
                     "Land area is : " oar decl
               )
               )
             )
         )
         )
         (setq e (vlax-ename->vla-object e))
         (grread t)
          (while (not enter)
         (princ "\nSpecify the insertion point of the text...")
         (setq grp (grread T 5 0)
               reason (car grp)
               value (cadr grp)
         )
         (cond
             ((or (member reason '(11 12 25)) (= value 13) (= value 32)) (vla-delete e) (setq enter t))
             ((= reason 5) (vlax-put e 'InsertionPoint (trans value 1 0)))
             ((= reason 3) (setq enter t))
         )
         )
       )
       (princ
         (strcat
         "\n\tLand area is : " oar decl
               
         )
       )
    )
请告诉我为什么会出现这个问题。
非常感谢。

hanhphuc 发表于 2022-7-5 16:01:28

 
嗨,也许“enter”变量没有本地化?
(defun c:test (/ enter )
...
...
(while ( not enter )
...
...

 
或者在while循环后尝试此操作。。
9
页: 1 [2]
查看完整版本: 从lisp插入文本