本帖最后由 xiaolong1487 于 2017-10-25 08:54 编辑
这个是test.txt的内容,图层名,颜色。需要什么自己加,自己改
a001 1
a002 2
a003 3
 - ;;84.17 [功能] 读文本文件到表 (快于 AutoLISP read-line函数)
- ;;用法: (vldos-readfile FilenameToRead[STRING] )
- ;; 参数1: 文本文件全路径名. (包括后缀名)
- ;; 只有文本文件才能返回正确结果.
- ;;返回值: 返回包括文件内容的表 or NIL
- (Defun vldos-readfile
- (Fil / string->list FilObj FilPth FilSys OpnFil All)
- (Defun string->list (String / ID Rtn)
- (if (null (setq ID (vl-string-search "\r\n" String)))
- (setq Rtn (list String))
- (progn
- (while ID
- (setq Rtn (cons (substr String 1 ID) Rtn)
- String (substr String (+ 3 ID))
- ID (vl-string-search "\r\n" String)
- )
- )
- (setq Rtn (reverse (cons String Rtn)))
- )
- )
- Rtn
- )
- (if (AND (setq FilPth (findfile Fil))
- (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
- )
- (progn
- (setq FilObj (vlax-invoke FilSys "GetFile" FilPth)
- OpnFil (vlax-invoke FilObj "OpenAsTextStream" 1 0)
- All (string->list (vlax-invoke OpnFil "readall"))
- )
- (vlax-invoke OpnFil "Close")
- (vlax-release-object OpnFil)
- (vlax-release-object FilObj)
- (vlax-release-object FilSys)
- )
- )
- All
- )
- ;|
- ;;http://www.xdcad.net/forum/thread-669166-1-2.html By XDSoft
- 功能 对字符串进行正则表达式匹配测试.
- pat = 正则表达式模式 ,对应vbs正则表达式的模式(expression)。说明: \\号要用\\\\替代.
- str = 字符串
- key = "i" "g" "m" , "i"不区分大小写(Ignorecase),"g"全局匹配(Global).
- "m"多行模式(Multiline),以上几个关键字可以组合使用,或用 "".
- 返回: 返回匹配的字符列表,或无一匹配返回nil
- |;
- ;;47.1 [功能] 字符串分割(正则表达式)
- (defun XD::String:RegExpS (pat str key / end keys matches x)
- (if (not *xxvbsexp)
- (setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
- )
- (vlax-put *xxvbsexp 'Pattern pat)
- (if (not key)
- (setq key "")
- )
- (setq key (strcase key))
- (setq keys '(("I" "IgnoreCase")
- ("G" "Global")
- ("M" "Multiline")
- )
- )
- (mapcar
- '(lambda (x)
- (if (wcmatch key (strcat "*" (car x) "*"))
- (vlax-put *xxvbsexp (read (cadr x)) 0)
- (vlax-put *xxvbsexp (read (cadr x)) -1)
- )
- )
- keys
- )
- (setq matches (vlax-invoke *xxvbsexp 'Execute str))
- (vlax-for x matches (setq end (cons (vla-get-value x) end)))
- (reverse end)
- )
- (defun c:ts ()
- (if (setq lst (vldos-readfile "c:\\test.txt"))
- (progn
- (foreach str lst
- (setq lst1 (xd::string:regexps "[^\\s]+" str ""))
- (command "-layer" "n" (car lst1) "c" (cadr lst1) (car lst1) "" )
- )
- )
- )
- )
|