Lee Mac 发表于 2022-7-6 10:31:03

点的格式是什么?i、 e.逗号分隔?x、 y,z

wannabe 发表于 2022-7-6 10:36:34

 
我认为ReMark的referal赢了:D

Lee Mac 发表于 2022-7-6 10:38:47

如果没有,这应该有效(假设2D):
 

(defun c:ptpoly (/ doc spc file nl ptlst)
(vl-load-com)

(setq doc (vla-get-ActiveDocument
             (vlax-get-Acad-Object))
       spc (if (zerop (vla-get-activespace doc))
             (if (= (vla-get-mspace doc) :vlax-true)
               (vla-get-modelspace doc)
               (vla-get-paperspace doc))
             (vla-get-modelspace doc)))

(if (setq file (getfiled "Select File" "" "txt" )
   (progn
   (setq file (open file "r"))
   (while (setq nl (read-line file))
       (setq ptlst (cons (StrBrk nl 44) ptlst)))
   (close file)
   (if ptlst
       (progn
         (setq ptlst
                (apply 'append
                     (mapcar
                         (function
                           (lambda (x)
                           (list (car x) (cadr x))))
                         (reverse
                           (mapcar
                           (function
                               (lambda (x)
                                 (mapcar 'distof x))) ptlst)))))
         (vla-addLightweightpolyline spc
         (vlax-make-variant
             (vlax-safearray-fill
               (vlax-make-safearray
               vlax-vbdouble
               (cons 0 (1- (length ptlst)))) ptlst))))
       (princ "\n<< No Points Found in File >>")))
   (princ "\n<< No File Selected >>"))
(princ))
         

(defun StrBrk (str chrc / pos lst)
(while (setq pos (vl-string-position chrc str))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
(reverse (cons str lst)))

ReMark 发表于 2022-7-6 10:41:17

那样的话,我就拿一杯啤酒作为奖品。非常感谢你。

fbby 发表于 2022-7-6 10:46:01

我附上了我的一些坐标
请检查一下
谢谢
 
 
 
__________________________
对不起我的英语

Lee Mac 发表于 2022-7-6 10:49:07

如果你不想使用备注法,可以把坐标复制到一个文本文件中,告诉我是什么把它们分开的,是制表符、空格还是逗号。

fbby 发表于 2022-7-6 10:51:07

这是空间
 
X和Y
135643    4740
135650    4737
135656    4734

Lee Mac 发表于 2022-7-6 10:54:14

好的,如果从文本文件的顶部删除X和Y,这应该可以工作:
 

(defun c:ptpoly (/ doc spc file nl ptlst)
(vl-load-com)

(setq doc (vla-get-ActiveDocument
             (vlax-get-Acad-Object))
       spc (if (zerop (vla-get-activespace doc))
             (if (= (vla-get-mspace doc) :vlax-true)
               (vla-get-modelspace doc)
               (vla-get-paperspace doc))
             (vla-get-modelspace doc)))

(if (setq file (getfiled "Select File" "" "txt" )
   (progn
   (setq file (open file "r"))
   (while (setq nl (read-line file))
       (setq ptlst (cons (StrBrk nl 32) ptlst)))
   (close file)
   (if ptlst
       (progn
         (setq ptlst
                (apply 'append
                     (mapcar
                         (function
                           (lambda (x)
                           (list (car x) (cadr x))))
                         (reverse
                           (mapcar
                           (function
                               (lambda (x)
                                 (mapcar 'distof x))) ptlst)))))
         (vla-addLightweightpolyline spc
         (vlax-make-variant
             (vlax-safearray-fill
               (vlax-make-safearray
               vlax-vbdouble
               (cons 0 (1- (length ptlst)))) ptlst))))
       (princ "\n<< No Points Found in File >>")))
   (princ "\n<< No File Selected >>"))
(princ))
         

(defun StrBrk (str chrc / pos lst)
(while (setq pos (vl-string-position chrc str))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
(reverse (cons str lst)))

fbby 发表于 2022-7-6 10:57:11

 
 
你能告诉我要做什么吗?
谢谢
 
 
 
 
 
____________________________
对不起我的英语

Lee Mac 发表于 2022-7-6 11:02:25

 
关于加载例程:
 
http://www.cadtutor.net/faq/questions/28/How+do+I+use+an+AutoLISP+routine%3F
 
加载后,在ACAD中用“ptpoly”调用它。
 
选择文本文件,工作就完成了(希望如此!)
页: 1 [2]
查看完整版本: excel到autocad