乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 61|回复: 6

[编程交流] 从插入块。txt文件

[复制链接]

32

主题

98

帖子

73

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
197
发表于 2022-7-5 19:40:20 | 显示全部楼层 |阅读模式
这将插入一个块并从中读取坐标。txt文件。李几年前为我写的。它工作得很好!
 
我想要与此相同的东西,但它从csv文件读取
 
顺便说一句,李
 
你几天前为我写的那封信效果很好。非常感谢。
 
  1. ;;; lee mac
  2. ;;; this works great 2/dec/2013
  3. (defun c:qqq ( / a f )
  4.    (if
  5.        (and
  6.            (setq f (findfile "c:\\sun.txt"))
  7.            (setq f (open f "r"))
  8.        )
  9.        (progn
  10.            (while (setq a (read-line f))
  11.                (command "_.-insert" "ppoint" "_non" (read (strcat "(" a ")")) "" "" "")
  12.            )
  13.            (close f)
  14.        )
  15.    )
  16.    (princ)
  17. )
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:51:27 | 显示全部楼层
尝试以下操作:
  1. ([color=BLUE]defun[/color] c:csv2blk ( [color=BLUE]/[/color] *error* blk cmd cnt csv des dwg ins str )
  2.    ([color=BLUE]defun[/color] *error* ( msg )
  3.        ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des))
  4.        ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'int  ([color=BLUE]type[/color] cmd)) ([color=BLUE]setvar[/color] 'cmdecho cmd))
  5.        ([color=BLUE]if[/color] ([color=blue]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color])))
  6.            ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
  7.        )
  8.        ([color=BLUE]princ[/color])
  9.    )
  10.    ([color=BLUE]setq[/color] blk [color=darkred]"ppoint"[/color] [color=GREEN];; Block to insert[/color]
  11.          cmd ([color=BLUE]getvar[/color] 'cmdecho)
  12.    )
  13.    ([color=BLUE]setvar[/color] 'cmdecho 0)
  14.    ([color=BLUE]cond[/color]
  15.        (   ([color=BLUE]not[/color]
  16.                ([color=BLUE]or[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"block"[/color] ([color=BLUE]setq[/color] dwg blk))
  17.                    ([color=BLUE]and[/color] ([color=BLUE]setq[/color] dwg ([color=BLUE]findfile[/color] ([color=BLUE]strcat[/color] blk [color=MAROON]".dwg"[/color])))
  18.                        ([color=BLUE]progn[/color]
  19.                            ([color=BLUE]command[/color] [color=MAROON]"_.-insert"[/color] dwg [color=BLUE]nil[/color])
  20.                            ([color=BLUE]tblsearch[/color] [color=MAROON]"block"[/color] ([color=BLUE]setq[/color] dwg blk))
  21.                        )
  22.                    )
  23.                )
  24.            )               
  25.            ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n""[/color] blk [color=MAROON]".dwg" not found."[/color]))
  26.        )
  27.        (   ([color=BLUE]not[/color] ([color=BLUE]setq[/color] csv ([color=BLUE]getfiled[/color] [color=MAROON]"Select CSV"[/color] [color=MAROON]""[/color] [color=MAROON]"csv"[/color] 16))))
  28.        (   ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] csv [color=MAROON]"r"[/color])))
  29.            ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nUnable to open ""[/color] csv [color=MAROON]"" for reading."[/color]))
  30.        )
  31.        (   ([color=BLUE]setq[/color] cnt 0)
  32.            ([color=BLUE]while[/color] ([color=BLUE]setq[/color] str ([color=BLUE]read-line[/color] des))
  33.                ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] ins ([color=BLUE]read[/color] ([color=BLUE]strcat[/color] [color=MAROON]"("[/color] ([color=BLUE]vl-string-translate[/color] [color=MAROON]","[/color] [color=MAROON]" "[/color] str) [color=MAROON]")"[/color])))
  34.                         ([color=BLUE]<[/color] 1 ([color=BLUE]length[/color] ins) 4)
  35.                         ([color=BLUE]vl-every[/color] '[color=BLUE]numberp[/color] ins)
  36.                         ([color=BLUE]setq[/color] cnt ([color=BLUE]1+[/color] cnt))
  37.                    )
  38.                    ([color=BLUE]command[/color] [color=MAROON]"_.-insert"[/color] dwg [color=MAROON]"_s"[/color] 1.0 [color=MAROON]"_r"[/color] 0.0 [color=MAROON]"_non"[/color] ins)
  39.                    ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n""[/color] str [color=MAROON]"" is not a valid point."[/color]))
  40.                )
  41.            )
  42.            ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des))
  43.            ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 cnt)
  44.                ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] ([color=BLUE]itoa[/color] cnt) [color=MAROON]" block"[/color] ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 cnt) [color=MAROON]""[/color] [color=MAROON]"s"[/color]) [color=MAROON]" inserted."[/color]))
  45.                ([color=BLUE]princ[/color] [color=MAROON]"\nSelected CSV file does not contain valid point data."[/color])
  46.            )
  47.        )
  48.    )
  49.    (*error* [color=blue]nil[/color])
  50.    ([color=BLUE]princ[/color])
  51. )
回复

使用道具 举报

32

主题

98

帖子

73

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
197
发表于 2022-7-5 20:01:37 | 显示全部楼层
非常感谢你。你们帮了大忙
 
冒着痛苦的风险,我可以要求再次修改吗?
 
如果打开acad图形,您将看到许多圆圈。椭圆周长上的粉红色圆圈是小时。(由于夏令时,共2行)
 
绿色圆圈是月份。然而,我无法区分一月和二月,因为它们都是相同的圆圈
 
这就是我制作月积木(灰色)的原因
 
我想停止插入块ppoint,开始插入每个单独的月份块
 
我愿意听取关于如何做到这一点的建议。
 
我的一个想法是每月制作一个csv文件
 
然后,我将通过读取jan1 csv插入jan1 month块
 
  1. remove this line (   (not (setq csv (getfiled "Select CSV" "" "csv" 16))))
  2. change this
  3. (   (not (setq des (open csv "r")))
  4. to this
  5. (   (not (setq des (open "C:\\sun.csv" "r")))

sdial测试。图纸
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:18:35 | 显示全部楼层
回复

使用道具 举报

32

主题

98

帖子

73

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
197
发表于 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
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 20:33:10 | 显示全部楼层
Change this
  1. 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")))
回复

使用道具 举报

32

主题

98

帖子

73

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
197
发表于 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
 
  1. (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
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 01:23 , Processed in 0.505264 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表