将文字从autocad导出到ex
大家好。我是这个论坛的新手,也是LISP的新手,但我真的希望你们能帮我。
我的问题是,我需要创建一个lisp,它可以将所有文本从modelspace导出到excel,还应该有一个“计数器”函数,它告诉我当前单词重复了多少次。就像数据挖掘一样。
我在某处找到了这段代码,它实际上非常好。我唯一需要在这段代码中实现的是一个函数,该函数询问我在哪里保存文本文件?
谁能帮帮我吗
我不太确定这段代码的作者是谁。
(defun c:tsel (/ ss lst tss olst ofile)
(vl-load-com)
(if (setq ss (ssget '((0 . "*TEXT"))))
(progn
(setq lst
(mapcar
(function
(lambda (x)
(vla-get-TextString
(vlax-ename->vla-object x))))
(vl-remove-if 'listp
(mapcar 'cadr (ssnamex ss)))))
(foreach str (unique lst)
(if (setq tss
(ssget "_X"
(list '(0 . "*TEXT") (cons 1 str))))
(setq olst
(cons
(cons str (sslength tss)) olst))
(setq olst
(cons
(cons str 0.) olst))))
(setq ofile
(open
(strcat
(getvar "DWGPREFIX")
(substr
(getvar "DWGNAME") 1
(- (strlen
(getvar "DWGNAME")) 4)) "-StrCnt.txt") "a"))
(mapcar
(function
(lambda (x)
(write-line
(strcat (car x) "\t"
(vl-princ-to-string (cdr x))) ofile))) olst)
(close ofile)
(princ "\n<< Strings Written to File >>"))
(princ "\n<< Nothing Selected >>"))
(princ))
;; CAB
(defun unique (lst / result)
(reverse
(while (setq itm (car lst))
(setq lst (vl-remove itm lst)
result (cons itm result)))))
欢迎来到CADTutor。
首先,请阅读这篇关于代码格式的帖子,并编辑你的帖子。
关于您的任务,请尝试以下简单代码:
;; Text Extraction-Lee Mac
;; Extracts all Text & MText in Modelspace to a Text file,
;; with the number of occurrences of each string.
(defun c:txtext ( / a d f i l s x )
(cond
( (not (setq s (ssget "_X" '((0 . "*TEXT") (410 . "Model")))))
(princ "\nNo Text or MText found in Modelspace.")
)
( (not (setq f (getfiled "" "" "txt" 1)))
(princ "\n*Cancel*")
)
( (setq d (open f "w"))
(repeat (setq i (sslength s))
(setq x (cdr (assoc 1 (entget (ssname s (setq i (1- i)))))))
(if (setq a (assoc x l))
(setq l (subst (cons x (1+ (cdr a))) a l))
(setq l (cons(cons x 1) l))
)
)
(foreach x (vl-sort l '(lambda ( a b ) (< (car a) (car b))))
(write-line (strcat (car x) "\t" (itoa (cdr x))) d)
)
(close d)
)
( (princ (strcat "\nUnable to write to " f)) )
)
(princ)
)
(princ)
不客气,我真的很荣幸我的声誉比我高
正如您随后发现的那样,警报功能是显示简单对话框消息的最简单方式。
关于AutoLISP学习资源,有许多网站提供教程和代码示例,包括我自己的网站。根据我的经验,一些最好的学习材料可以在AutoCAD附带的Visual LISP IDE帮助文档中找到。而且,如果你陷入困境,有几个CAD编程论坛的成员非常乐意伸出援助之手。
以下是供您阅读的一小部分网站:
http://www.afralisp.net/index.php
http://www.lee-mac.com/
http://www.jefferypsanders.com/
http://ronleigh.com/autolisp/
谢谢你,也谢谢你。 如何在同名文件夹中创建文本文件?
我想使用这个lisp作为脚本从几个图形中提取文本
快速更换:
(alert
"here i can write the text"
)
使用:
(not (setq f (getfiled "" "" "txt" 1)))
这个条件实际上不再是必需的,因为上面的条件总是返回nil,但是上面的修改减少了您需要对现有代码进行的更改的数量。
As a quick change, replace:
(not (setq f (getfiled "" "" "txt" 1)))
With:
(not (setq f (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".txt")))
The condition is actually no longer required since the above will always return nil, but the above modification reduces the number of changes you need to make to the existing code.
页:
[1]