明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2938|回复: 7

能否修改一下:批量插入图块

[复制链接]
发表于 2010-10-10 15:48 | 显示全部楼层 |阅读模式
  1. ;;------------------------------------DCL语句-----------------------------------------------------
  2. 这个程序有时会把所有的图块都插到一起,而没有阵列,并且读取文件名的时候是没有规律的读取
  3. YH_批量出入图块 : dialog {
  4. label="批量插入图块对话框 V1.0测试版";
  5. :column {
  6. :row {
  7. :boxed_column {
  8. label="阵列参数";
  9. :edit_box {
  10. label="行数:";
  11. key="YH_rnum";
  12. }
  13. :edit_box {
  14. label="行距:";
  15. key="YH_rdis";
  16. }
  17. :edit_box {
  18. label="列数:";
  19. key="YH_cnum";
  20. }
  21. :edit_box {
  22. label="列距:";
  23. key="YH_cdis";
  24. }
  25. }
  26. :column{
  27. :boxed_column {
  28. label="插入点";
  29. :radio_button{
  30. label="手工逐个点取";
  31. value="1";
  32. key="YH_mode1";
  33. }
  34. :radio_button{
  35. label="阵列布置";
  36. key="YH_mode2";
  37. }
  38. }
  39. :boxed_column {
  40. label="阵列布置方向";
  41. :radio_button {
  42. label="横向排列";
  43. key="YH_H1";
  44. value="1";
  45. fixed_width=true;
  46. }
  47. :radio_button {
  48. label="竖向排列";
  49. key="YH_V1";
  50. fixed_width=true;
  51. }
  52. }
  53. }
  54. }
  55. :edit_box {
  56. label="图块图名";
  57. key="YH_blockname";
  58. }
  59. }
  60. :row{
  61. :edit_box {
  62. label="图块目录";
  63. key="YH_fileload";
  64. is_enabled=true;
  65. }
  66. :button {
  67. label="浏览";
  68. key="YH_brows";
  69. fixed_width=true;
  70. }
  71. }
  72. :boxed_row {
  73. label="实时说明";
  74. :list_box{
  75. fixed_height=true;
  76. width=41;
  77. height=10;
  78. key="YH_softtext";
  79. }
  80. }
  81. ok_cancel;
  82. }
  83. ;;------------------------------------DCL语句-----------------------------------------------------
  84. ;;------------------------------------主 程 序-----------------------------------------------------
  85. (defun c:ib ()
  86. (setq YH_oldosmode (getvar "osmode"))
  87. (setvar "osmode" 0)
  88. (YH_dclset)
  89. (if (= YH_mode1 "1")
  90. (YH_insert1)
  91. (YH_insert2)
  92. )
  93. (setvar "osmode" YH_oldosmode)
  94. (princ)
  95. ;;清空系统变量
  96. (setq YH_BLOCK nil
  97. YH_FILELIST nil
  98. YH_INDEX nil
  99. YH_CDIS nil
  100. YH_H1 nil
  101. YH_POINT1 nil
  102. YH_RDIS nil
  103. YH_X1 nil
  104. YH_Y1 nil
  105. YH_CDIS nil
  106. YH_CNUM nil
  107. YH_HREM nil
  108. YH_INDEX1 nil
  109. YH_INDEX2 nil
  110. YH_INDEX3 nil
  111. YH_LOOP1 nil
  112. YH_LOOP2 nil
  113. YH_POINT2 nil
  114. YH_ROWNUM2 nil
  115. YH_X2 nil
  116. YH_Y2 nil
  117. )
  118. )
  119. ;;对话框处理程序
  120. (defun YH_dclset ()
  121. (setq YH_DCLID (load_dialog "YH_insertblocks.dcl"))
  122. (new_dialog "YH_批量出入图块" YH_DCLID)
  123. (if (/= YH_filepath nil) (set_tile "YH_fileload" YH_filepath))
  124. (if (/= YH_filename1 nil) (set_tile "YH_blockname" YH_filename1))
  125. ;;对话框化
  126. (YH_dclmode)
  127. (action_tile "YH_mode1" "(YH_dclmode)")
  128. (action_tile "YH_mode2" "(YH_dclHV)")
  129. (action_tile "YH_H1" "(YH_dclH1)")
  130. (action_tile "YH_V1" "(YH_dclV1)")
  131. (action_tile "YH_brows" "(YH_getFolder)(YH_setfile)")
  132. (action_tile "accept" "(YH_value)")
  133. (action_tile "YH_blockname" "(YH_blockname1)")
  134. (action_tile "YH_fileload" "(YH_setfile)")
  135. (action_tile "cancel" "(exit)")
  136. (start_dialog)
  137. (unload_dialog YH_DCLID)
  138. (princ)
  139. )
  140. (defun YH_dclmode ()
  141. (mode_tile "YH_rnum" 1)
  142. (mode_tile "YH_cnum" 1)
  143. (mode_tile "YH_rdis" 1)
  144. (mode_tile "YH_cdis" 1)
  145. (mode_tile "YH_H1" 1)
  146. (mode_tile "YH_V1" 1)
  147. (mode_tile "YH_mode1" 2)
  148. (start_list "YH_softtext" 3 0)
  149. (add_list "手工逐个点取")
  150. (add_list "")
  151. (add_list "请在图块名中指定图块名称条件,支持统配符*")
  152. (add_list "图块名称输入请不要带有后缀。如不指定图名")
  153. (add_list "将默认全部DWG文件,同时请注意图块插入点的")
  154. (add_list "制作。")
  155. (add_list " ")
  156. (add_list " --2005.10 by sailorcwx")
  157. (end_list)
  158. )
  159. (defun YH_dclHV ()
  160. (mode_tile "YH_H1" 0)
  161. (mode_tile "YH_V1" 0)
  162. (YH_dclH1)
  163. (start_list "YH_softtext" 3 0)
  164. (add_list "根据第一个插入点进行阵列布置")
  165. (add_list "")
  166. (add_list "请在图块名中指定图块名称条件,支持统配符*")
  167. (add_list "图块名称输入请不要带有后缀。如不指定图名")
  168. (add_list "将默认全部DWG文件,同时请注意图块插入点的")
  169. (add_list "制作。")
  170. (add_list " ")
  171. (add_list " --2005.10 by sailorcwx")
  172. (end_list)
  173. )
  174. (defun YH_dclH1 ()
  175. (mode_tile "YH_rnum" 1)
  176. (mode_tile "YH_rdis" 0)
  177. (mode_tile "YH_cnum" 0)
  178. (mode_tile "YH_cdis" 0)
  179. (start_list "YH_softtext" 3 0)
  180. (add_list "横向排列是沿X轴方向根据每行的列数布置")
  181. (add_list "")
  182. (add_list "请在图块名中指定图块名称条件,支持统配符*")
  183. (add_list "图块名称输入请不要带有后缀。如不指定图名")
  184. (add_list "将默认全部DWG文件,同时请注意图块插入点的")
  185. (add_list "制作。")
  186. (add_list " ")
  187. (add_list " --2005.10 by sailorcwx")
  188. (end_list)
  189. )
  190. (defun YH_dclV1 ()
  191. (mode_tile "YH_rnum" 0)
  192. (mode_tile "YH_rdis" 0)
  193. (mode_tile "YH_cnum" 1)
  194. (mode_tile "YH_cdis" 0)
  195. (start_list "YH_softtext" 3 0)
  196. (add_list "横向排列是沿Y轴方向根据每列的行数布置")
  197. (add_list "")
  198. (add_list "请在图块名中指定图块名称条件,支持统配符*")
  199. (add_list "图块名称输入请不要带有后缀。如不指定图名")
  200. (add_list "将默认全部DWG文件,同时请注意图块插入点的")
  201. (add_list "制作。")
  202. (add_list " ")
  203. (add_list " --2005.10 by sailorcwx")
  204. (end_list)
  205. )
  206. (defun YH_getFolder (/ WinShell shFolder path catchit)
  207. (vl-load-com)
  208. (setq winshell (vlax-create-object "Shell.Application"))
  209. (setq shFolder (vlax-invoke-method
  210. WinShell 'BrowseForFolder 0 "选择目录" 1)
  211. )
  212. (setq
  213. catchit (vl-catch-all-apply
  214. '(lambda ()
  215. (setq shFolder (vlax-get-property shFolder 'self))
  216. (setq path (vlax-get-property shFolder 'path))
  217. )
  218. )
  219. )
  220. (if (vl-catch-all-error-p catchit)
  221. nil
  222. path
  223. )
  224. (set_tile "YH_fileload" path)
  225. )
  226. (defun YH_setfile()
  227. (setq YH_filelist nil)
  228. (setq YH_filepath (get_tile "YH_fileload"))
  229. (if (/= YH_filepath "")
  230. (progn
  231. (setq YH_filename1 (get_tile "YH_blockname"))
  232. (setq YH_filename YH_filename1)
  233. (if (= YH_filename "") (setq YH_filename "*.dwg") (setq YH_filename (strcat YH_filename ".dwg")))
  234. (setq YH_filelist (vl-directory-files YH_filepath YH_filename 1))
  235. (start_list "YH_softtext" 3 0)
  236. (add_list "符合条件的图块如下:")
  237. (mapcar 'add_list YH_filelist)
  238. (add_list " --2005.10 by sailorcwx")
  239. (end_list)
  240. )
  241. )
  242. )
  243. (defun YH_blockname1()
  244. (setq YH_filepath (get_tile "YH_fileload"))
  245. (if (/= YH_filepath "") (YH_setfile))
  246. )
  247. (defun YH_value()
  248. (setq YH_errorinput 1)
  249. (setq YH_mode1 (get_tile "YH_mode1")
  250. YH_mode2 (get_tile "YH_mode2")
  251. YH_H1 (get_tile "YH_H1")
  252. YH_V1 (get_tile "YH_V1")
  253. YH_rnum (get_tile "YH_rnum")
  254. YH_rdis (get_tile "YH_rdis")
  255. YH_cnum (get_tile "YH_cnum")
  256. YH_cdis (get_tile "YH_cdis")
  257. YH_filename (get_tile "YH_blockname")
  258. YH_filename1 (get_tile "YH_blockname")
  259. YH_filepath (get_tile "YH_fileload")
  260. )
  261. (if (= YH_filepath "") (progn (setq YH_errorwhy "错误输入,图块目录不能为空")(setq YH_errorinput 0)))
  262. (if (= YH_mode2 "1")
  263. (progn
  264. (if (and (= YH_H1 "1") (= (atof YH_cnum) 0)) (progn (setq YH_errorwhy "错误输入,列数必须为非零数字")(setq YH_errorinput 0)))
  265. (if (and (= YH_V2 "1") (= (atof YH_rnum) 0)) (progn (setq YH_errorwhy "错误输入,行数必须为非零数字")(setq YH_errorinput 0)))
  266. )
  267. )
  268. (if (= YH_errorinput 0) (alert YH_errorwhy) (progn (YH_setfile)(done_dialog)))
  269. (princ)
  270. )
  271. (defun YH_insert1 ()
  272. (setq YH_index (length YH_filelist))
  273. (repeat YH_index
  274. (setq YH_block (strcat YH_filepath "\" (car YH_filelist)))
  275. (setq YH_filelist (cdr YH_filelist))
  276. (command "insert" YH_block pause "1" "1" "0")
  277. )
  278. )
  279. (defun YH_insert2 ()
  280. (setq YH_block (strcat YH_filepath "\" (car YH_filelist)))
  281. (command "insert" YH_block pause "1" "1" "0")
  282. (setq YH_point1 (getvar "lastpoint"))
  283. (setq YH_index (length YH_filelist))
  284. (setq YH_x1 (car YH_point1)
  285. YH_y1 (cadr YH_point1)
  286. )
  287. (if (= YH_rdis "") (setq YH_rdis 0) (setq YH_rdis (atof YH_rdis)))
  288. (if (= YH_cdis "") (setq YH_cdis 0) (setq YH_cdis (atof YH_cdis)))
  289. (if (= YH_H1 "1") (YH_insertH) (YH_insertV))
  290. )
  291. (defun YH_insertH()
  292. (setq YH_rownum2 (fix (/ (+ YH_index 1) (atof YH_cnum))))
  293. (setq YH_Hrem (rem YH_index (atof YH_cnum)))
  294. (if (= YH_Hrem 0) (setq YH_loop1 YH_rownum2 YH_loop2 0)
  295. (progn
  296. (if (= YH_rownum2 0) (setq YH_loop1 0 YH_loop2 YH_Hrem)
  297. (setq YH_loop1 YH_rownum2 YH_loop2 YH_Hrem)
  298. )
  299. )
  300. )
  301. (if (/= YH_loop1 0)
  302. (progn
  303. (setq YH_index1 0)
  304. (repeat YH_loop1
  305. (setq YH_y2 (+ YH_y1 (* YH_rdis YH_index1)))
  306. (setq YH_index1 (1+ YH_index1))
  307. (setq YH_index2 0)
  308. (repeat (fix (atof YH_cnum))
  309. (setq YH_x2 (+ YH_x1 (* YH_cdis YH_index2)))
  310. (setq YH_index2 (1+ YH_index2))
  311. (setq YH_point2 (list YH_x2 YH_y2))
  312. (setq YH_block (strcat YH_filepath "\" (car YH_filelist)))
  313. (setq YH_filelist (cdr YH_filelist))
  314. (command "insert" YH_block YH_point2 "1" "1" "0")
  315. )
  316. )
  317. (if (/= YH_loop2 0)
  318. (progn
  319. (setq YH_y2 (+ YH_y1 YH_rdis))
  320. (repeat (fix YH_loop2)
  321. (setq YH_index3 0)
  322. (setq YH_x2 (+ YH_x1 (* YH_cdis YH_index3)))
  323. (setq YH_index3 (1+ YH_index3))
  324. (setq YH_point2 (list YH_x2 YH_y2))
  325. (setq YH_block (strcat YH_filepath "\" (car YH_filelist)))
  326. (setq YH_filelist (cdr YH_filelist))
  327. (command "insert" YH_block YH_point2 "1" "1" "0")
  328. )
  329. )
  330. )
  331. )
  332. )
  333. (princ)
  334. )
  335. (defun YH_insertV()
  336. (setq YH_rownum2 (fix (/ (+ YH_index 1) (atof YH_rnum))))
  337. (setq YH_Hrem (rem YH_index (atof YH_rnum)))
  338. (if (= YH_Hrem 0) (setq YH_loop1 YH_rownum2 YH_loop2 0)
  339. (progn
  340. (if (= YH_rownum2 0) (setq YH_loop1 0 YH_loop2 YH_Hrem)
  341. (setq YH_loop1 YH_rownum2 YH_loop2 YH_Hrem)
  342. )
  343. )
  344. )
  345. (if (/= YH_loop1 0)
  346. (progn
  347. (setq YH_index1 0)
  348. (repeat YH_loop1
  349. (setq YH_x2 (+ YH_x1 (* YH_cdis YH_index1)))
  350. (setq YH_index1 (1+ YH_index1))
  351. (setq YH_index2 0)
  352. (repeat (fix (atof YH_rnum))
  353. (setq YH_y2 (+ YH_y1 (* YH_rdis YH_index2)))
  354. (setq YH_index2 (1+ YH_index2))
  355. (setq YH_point2 (list YH_x2 YH_y2))
  356. (setq YH_block (strcat YH_filepath "\" (car YH_filelist)))
  357. (setq YH_filelist (cdr YH_filelist))
  358. (command "insert" YH_block YH_point2 "1" "1" "0")
  359. )
  360. )
  361. (if (/= YH_loop2 0)
  362. (progn
  363. (setq YH_x2 (+ YH_x1 YH_cdis))
  364. (repeat (fix YH_loop2)
  365. (setq YH_index3 0)
  366. (setq YH_y2 (+ YH_y1 (* YH_rdis YH_index3)))
  367. (setq YH_index3 (1+ YH_index3))
  368. (setq YH_point2 (list YH_x2 YH_y2))
  369. (setq YH_block (strcat YH_filepath "\" (car YH_filelist)))
  370. (setq YH_filelist (cdr YH_filelist))
  371. (command "insert" YH_block YH_point2 "1" "1" "0")
  372. )
  373. )
  374. )
  375. )
  376. )
  377. (princ)
  378. )
 楼主| 发表于 2010-10-10 16:03 | 显示全部楼层
是插入对象不能整除插入列数或行数时才出现插块重叠现象
 楼主| 发表于 2010-10-15 09:34 | 显示全部楼层
要能读文件名的时候按一定的顺序排列,还有是插入对象个数不能整除插入列数或行数时才出现插块重叠现象
发表于 2010-12-17 11:09 | 显示全部楼层
现在也正在学习,过来学习一下
发表于 2011-1-14 11:45 | 显示全部楼层
是流浪水手的程序,好久没有更新啦
发表于 2011-1-16 20:23 | 显示全部楼层
这个程序我今天也看到了,也不能用,提示语法错误
发表于 2011-11-19 14:19 | 显示全部楼层
测试一下,真的还不错啊 谢谢啊
发表于 2011-12-14 14:38 | 显示全部楼层
过来学习一下

评分

参与人数 1明经币 +1 收起 理由
yan19851204 + 1

查看全部评分

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-2 02:25 , Processed in 0.335416 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表