CSV(逗号分隔值)格式只是一个简单的ASCI文件,与TXT格式没有区别。优点是内部数据格式良好。
当做
米尔恰
谢谢你,米尔恰。
这对我来说是新鲜事。
是的,我想要圈内的桩号。截止水平为“Z”值。
致以问候。 将所有数据从Excel文件复制到记事本,并将其另存为(txt文件),然后尝试此代码。
注意:字符串的形式必须与您在第#6号帖子中介绍的相同
祝你好运
(defun c:Test (/ filename openfile string pos lst p h)
;;; Tharwat 27. March . 2012 ;;;
;;form of the string must be as following ;
;"596 490554.848 2788544.836 - 0.700 75MM" ;
; 596 = Number inside the circle ;
; 490554.848 = x ;
; 2788544.836 = y ;
; - 0.700 = z ;
; 75MM = diameter of circle ;
(if (setq filename (getfiled "Select txt file ..."
(getvar 'dwgprefix)
"txt"
8
)
)
(progn
(setq openfile (open filename "r"))
(while
(setq string (read-line openfile))
(while string
(if (setq pos (vl-string-search " " string))
(progn
(setq lst (cons (substr string 1 pos) lst))
(setq string (substr string (+ pos 2)))
)
(progn
(setq lst (cons string lst))
(setq string nil)
)
)
)
(setq lst (reverse lst))
(entmakex
(list
'(0 . "CIRCLE")
(cons 10
(setq p
(list (read (nth 1 lst))
(read (nth 2 lst))
(read (strcat (nth 3 lst) (nth 4 lst)))
)
)
)
(cons 40
(setq h (read (vl-string-right-trim "MM" (nth 5 lst))))
)
)
)
(entmakex (list '(0 . "TEXT")
(cons 10 p)
(cons 11 p)
(cons 1 (car lst))
(cons 40 (/ h 2.))
(cons 7 (getvar 'textstyle))
'(50 . 0.)
'(71 . 0)
'(72 . 1)
'(73 . 2)
'(210 0.0 0.0 1.0)
)
)
(setq lst nil)
)
)
(princ)
)
(princ)
)
一条注释,如果您将粘贴数据从Excel复制到记事本,恐怕分隔符将是字符(ASCII代码9),而不是代码中使用的空格。
当做
米尔恰
这就是我在Cad 2010中测试代码时发生的情况,但在Cad 2009中,它将空间视为一个空间。
因此,如果它需要更改搜索t而不是搜索空间,我会非常乐意在有时间时替换它。
谢谢你的评论。
当做 这与AutoCAD的版本无关;这正是Excel将数据发送到剪贴板的方式。
当做
米尔恰 这很简单。
只需更换此。。
用这个。。。
3 Mircea,用户始终可以替换char。使用记事本中的查找和替换选项。。。
Tharwat,变量filename必须是完整HD path+filename的字符串,因此请考虑将(getfield)的整数从8更改为16。。。
M、 R。 我想你只是从OP的帖子中复制了数据,从那里你得到了空格作为分隔符——请记住,他可能是从Excel中粘贴的,但在HTML中,字符会自动替换为空格,除非添加了特殊的格式标记。
当做
米尔恰
页:
1
[2]