rookie37 发表于 2022-7-5 19:40:20

从插入块。txt文件

这将插入一个块并从中读取坐标。txt文件。李几年前为我写的。它工作得很好!
 
我想要与此相同的东西,但它从csv文件读取
 
顺便说一句,李
 
你几天前为我写的那封信效果很好。非常感谢。
 

;;; lee mac
;;; this works great 2/dec/2013
(defun c:qqq ( / a f )
   (if
       (and
         (setq f (findfile "c:\\sun.txt"))
         (setq f (open f "r"))
       )
       (progn
         (while (setq a (read-line f))
               (command "_.-insert" "ppoint" "_non" (read (strcat "(" a ")")) "" "" "")
         )
         (close f)
       )
   )
   (princ)
)

Lee Mac 发表于 2022-7-5 19:51:27

尝试以下操作:

(defun c:csv2blk ( / *error* blk cmd cnt csv des dwg ins str )

   (defun *error* ( msg )
       (if (= 'file (type des)) (close des))
       (if (= 'int(type cmd)) (setvar 'cmdecho cmd))
       (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
         (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (setq blk "ppoint" ;; Block to insert
         cmd (getvar 'cmdecho)
   )
   (setvar 'cmdecho 0)
   (cond
       (   (not
               (or (tblsearch "block" (setq dwg blk))
                   (and (setq dwg (findfile (strcat blk ".dwg")))
                     (progn
                           (command "_.-insert" dwg nil)
                           (tblsearch "block" (setq dwg blk))
                     )
                   )
               )
         )               
         (princ (strcat "\n\"" blk ".dwg\" not found."))
       )
       (   (not (setq csv (getfiled "Select CSV" "" "csv" 16))))
       (   (not (setq des (open csv "r")))
         (princ (strcat "\nUnable to open \"" csv "\" for reading."))
       )
       (   (setq cnt 0)
         (while (setq str (read-line des))
               (if (and (setq ins (read (strcat "(" (vl-string-translate "," " " str) ")")))
                        (< 1 (length ins) 4)
                        (vl-every 'numberp ins)
                        (setq cnt (1+ cnt))
                   )
                   (command "_.-insert" dwg "_s" 1.0 "_r" 0.0 "_non" ins)
                   (princ (strcat "\n\"" str "\" is not a valid point."))
               )
         )
         (setq des (close des))
         (if (< 0 cnt)
               (princ (strcat "\n" (itoa cnt) " block" (if (= 1 cnt) "" "s") " inserted."))
               (princ "\nSelected CSV file does not contain valid point data.")
         )
       )
   )
   (*error* nil)
   (princ)
)

rookie37 发表于 2022-7-5 20:01:37

非常感谢你。你们帮了大忙
 
冒着痛苦的风险,我可以要求再次修改吗?
 
如果打开acad图形,您将看到许多圆圈。椭圆周长上的粉红色圆圈是小时。(由于夏令时,共2行)
 
绿色圆圈是月份。然而,我无法区分一月和二月,因为它们都是相同的圆圈
 
这就是我制作月积木(灰色)的原因
 
我想停止插入块ppoint,开始插入每个单独的月份块
 
我愿意听取关于如何做到这一点的建议。
 
我的一个想法是每月制作一个csv文件
 
然后,我将通过读取jan1 csv插入jan1 month块
 

remove this line (   (not (setq csv (getfiled "Select CSV" "" "csv" 16))))
change this
(   (not (setq des (open csv "r")))
to this
(   (not (setq des (open "C:\\sun.csv" "r")))

sdial测试。图纸

Lee Mac 发表于 2022-7-5 20:18:35

rookie37 发表于 2022-7-5 20:28:11

Thank you. I'm impressed
 
Can I get this so that it doesn't prompt me for the csv? The file will always be c:\sun.csv
 
I'm writing a spreadsheet to make sundials. They're pretty trig intensive and it's easy to make a mistake. I need acad so that I can see the mistake. That's why I'll execute this lisp many times and tweak my spreadsheet many times until it is debugged

BIGAL 发表于 2022-7-5 20:33:10

Change this

remove this line (   (not (setq csv (getfiled "Select CSV" "" "csv" 16))))change this(   (not (setq des (open csv "r")))to this(   (not (setq des (open "C:\\sun.csv" "r")))

rookie37 发表于 2022-7-5 20:48:35

Thank you so much. You guys are a big help
 
At the risk of being a pain can I request another alteration?
 
If you open the acad drawing you will see many circles. The pink circles on the perimeter of the ellipse are the hours. (2 rows because of daylight savings)
 
The green circles are the months. However I can't tell january from febuary because they are all identical circles
 
This is why I made month blocks (grey)
 
I'd like to stop inserting the block ppoint and start inserting each individual month block
 
I'm open to suggestions on how to do this.
 
One idea that I have is that I'll make a csv file for each month
 
I'll then insert the jan1 month block by reading the jan1 csv
 

(defun c:csv3blk ( / *error* blk cmd cnt csv des dwg ins str )   (defun *error* ( msg )       (if (= 'file (type des)) (close des))       (if (= 'int(type cmd)) (setvar 'cmdecho cmd))       (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))         (princ (strcat "\nError: " msg))       )       (princ)   )   (setq blk "ppoint" ;; Block to insert         cmd (getvar 'cmdecho)   )   (setvar 'cmdecho 0)   (cond       (   (not               (or (tblsearch "block" (setq dwg blk))                   (and (setq dwg (findfile (strcat blk ".dwg")))                     (progn                           (command "_.-insert" dwg nil)                           (tblsearch "block" (setq dwg blk))                     )                   )               )         )                           (princ (strcat "\n\"" blk ".dwg\" not found."))       )               (   (not (setq des (open "C:\\sun.csv" "r")))         (princ (strcat "\nUnable to open \"" csv "\" for reading."))       )       (   (setq cnt 0)         (while (setq str (read-line des))               (if (and (setq ins (read (strcat "(" (vl-string-translate "," " " str) ")")))                        (< 1 (length ins) 4)                        (vl-every 'numberp ins)                        (setq cnt (1+ cnt))                   )                   (command "_.-insert" dwg "_s" 1.0 "_r" 0.0 "_non" ins)                   (princ (strcat "\n\"" str "\" is not a valid point."))               )         )         (setq des (close des))         (if (< 0 cnt)               (princ (strcat "\n" (itoa cnt) " block" (if (= 1 cnt) "" "s") " inserted."))               (princ "\nSelected CSV file does not contain valid point data.")         )       )   )   (*error* nil)   (princ)(   (not (setq des (open "C:\\m jan1.csv" "r")))         (princ (strcat "\nUnable to open \"" csv "\" for reading."))       )(tblsearch "block" (setq dwg blk))                   (and (setq dwg (findfile (strcat blk ".dwg")))                     (progn                           (command "_.-insert" dwg nil)                           (tblsearch "block" (setq dwg blk))(   (not (setq des (open "C:\\m jan15.csv" "r")))         (princ (strcat "\nUnable to open \"" csv "\" for reading."))       )(tblsearch "block" (setq dwg blk))                   (and (setq dwg (findfile (strcat blk ".dwg")))                     (progn                           (command "_.-insert" dwg nil)                           (tblsearch "block" (setq dwg blk))(   (not (setq des (open "C:\\m feb1.csv" "r")))         (princ (strcat "\nUnable to open \"" csv "\" for reading."))       )(tblsearch "block" (setq dwg blk))                   (and (setq dwg (findfile (strcat blk ".dwg")))                     (progn                           (command "_.-insert" dwg nil)                           (tblsearch "block" (setq dwg blk)))
sdial test.dwg
页: [1]
查看完整版本: 从插入块。txt文件