乐筑天下

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

[综合讨论] 插入块注意Lee M

[复制链接]

32

主题

98

帖子

73

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
197
发表于 2022-7-7 00:13:07 | 显示全部楼层 |阅读模式

 
你的程序运行得很好,这正是我需要的。
 
我将电子表格另存为CSV
 
有时它不起作用。我没有做什么不同的事,但有时我会出错
 
; 错误:错误的参数类型:FILE nil
 
 
  1. ;; Block Insertor by Lee McDonnell
  2. ;; 03.06.2009
  3. (defun c:blkIns (/ doc spc bdef blk file ofile ex lst iBlk line)
  4. (vl-load-com)
  5. (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))
  6.        spc (if (zerop (vla-get-activespace doc))
  7.              (if (= (vla-get-mspace doc) :vlax-true) ; vPort
  8.                (vla-get-modelspace doc)
  9.                (vla-get-paperspace doc))
  10.              (vla-get-modelspace doc)))
  11. (setq bdef (getvar "INSNAME"))
  12. (while (not blk)
  13.    (setq blk
  14.      (getstring t
  15.        (strcat "\nSpecify Block to be Inserted <" bdef ">: ")))
  16.    (cond ((eq "" blk)
  17.           (setq blk bdef))
  18.          ((and (snvalid blk)
  19.                (tblsearch "BLOCK" blk)))
  20.          ((and (snvalid blk)
  21.                (findfile (strcat blk ".dwg")))
  22.           (command "_.insert" blk) (command))
  23.          (T (princ "<!> Please Re-Select <!>")
  24.           (setq blk nil bdef ""))))
  25. (if (setq file (getfiled "Select File to Read"
  26.        (if *load$file* *load$file* "") "txt;csv" )
  27.    (progn
  28.      (setq *load$file* file ofile (open file "r")
  29.            ex (vl-filename-extension file))
  30.      (while (setq nl (read-line ofile))
  31.        (setq lst (cons (StrBrk nl (if (eq ex ".txt") 32 44)) lst)))
  32.      (close ofile)
  33.      (foreach line lst
  34.        (setq iBlk
  35.          (vla-InsertBlock spc
  36.            (vlax-3D-point
  37.              (mapcar 'distof (list (car line) (cadr line) "0.0")))
  38.            blk 1. 1. 1. 0.))      
  39.        (if (and (eq :vlax-true (vla-get-HasAttributes iBlk))
  40.                 (setq line (cddr line)))
  41.          (foreach att  (vlax-safearray->list
  42.                          (vlax-variant-value
  43.                            (vla-getAttributes iBlk)))
  44.            (if line
  45.              (vla-put-TextString att (car line)))
  46.            (setq line (cdr line))))))
  47.    (princ "\n<!> No File Selected <!>"))
  48. (princ))
  49.      
  50. (defun StrBrk (str chrc / pos lst)
  51. (while (setq pos (vl-string-position chrc str))
  52.    (setq lst (cons (substr str 1 pos) lst)
  53.          str (substr str (+ pos 2))))
  54. (reverse (cons str lst)))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-9 09:09 , Processed in 0.366887 second(s), 54 queries .

© 2020-2025 乐筑天下

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