明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2311|回复: 6

[求助] 求个LISP小程序

[复制链接]
发表于 2010-5-11 18:05:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2010-5-11 19:58:33 编辑

界面如图:

功能:宗地编号和四至可以直接在cad图上选择文字或输入,然后每次生成一条记录,生成电子表格或者是数据库格式。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2010-5-18 11:52:00 | 显示全部楼层
今天边看NBA边随便写了下,不知道合不合你用,可惜太阳输了...
  1. (defun c:Test
  2.        (/ BZ DZ ID NZ OBJ STD SZ ZDBH Temp_Fold Temp_File Temp_Dcl)
  3.   (if (findfile "Lisp_Function.VLX")
  4.   (load "Lisp_Function.VLX")
  5.   )
  6. ;;; Lisp_Function.VLX 可于 http://e.ys168.com/?ls0201 下载
  7. ;;; 主要是一些常用的函数打包,包括Excel处理函数,部分来源于网络 ^_^
  8.   (setq Temp_Fold (getenv "Temp")) ;_临时文件
  9.   (setq Temp_File (strcat Temp_Fold "\\20100518_宗地编号_Tmp.txt"))
  10.   (setq Temp_Dcl (strcat Temp_Fold "\\20100518_宗地编号.dcl"))
  11. ;;;--------------------------------------------------------------;;;
  12. ;;;                            Start                             ;;;
  13. ;;;--------------------------------------------------------------;;;
  14. ;;; 设置对话框的值
  15.   (defun set_dialog (zdbh dz nz sz bz / file)
  16.     (if zdbh
  17.       (set_tile "zdbh" zdbh)
  18.     )
  19.     (if dz
  20.       (set_tile "dz" dz)
  21.     )
  22.     (if nz
  23.       (set_tile "nz" nz)
  24.     )
  25.     (if sz
  26.       (set_tile "sz" sz)
  27.     )
  28.     (if bz
  29.       (set_tile "bz" bz)
  30.     )
  31.     (setq file Temp_File)
  32.     (if (findfile Temp_File)
  33.       (progn
  34. (set_tile
  35.    "Show_Info"
  36.    (strcat "当前临时记录文件宗地数: "
  37.     (rtos (/ (length (at_file_to_list_st file)) 5) 2 0)
  38.    )
  39. )
  40.       )
  41.     )
  42.   )
  43. ;;; 新建临时记录文件
  44.   (defun New_File ()
  45.     (if (= (NewDialog1 "     是否新建记录文件?") 1)
  46.       (progn
  47. (close (open Temp_File "w"))
  48. (set_tile "Show_Info" "当前临时记录文件宗地数: 0")
  49. (alert "    建立成功")
  50.       )
  51.       (progn
  52. (alert "    建立失败")
  53.       )
  54.     )
  55.   )
  56. ;;; 记录宗地信息
  57.   (defun S_This (/ BZ DZ FILE FN F_NUM NZ P_LIST R_LIST SZ X ZDBH)
  58.     (setq file Temp_File)
  59.     (setq zdbh (get_tile "zdbh"))
  60.     (if (/= zdbh "")
  61.       (progn
  62. (setq dz (get_tile "dz"))
  63. (setq nz (get_tile "nz"))
  64. (setq sz (get_tile "sz"))
  65. (setq bz (get_tile "bz"))
  66. (setq p_list (strcat zdbh "\n" dz "\n" nz "\n" sz "\n" bz "\n"))
  67. (if (findfile file)
  68.    (progn
  69.      (if (setq f_num (Get_Txt_Num_File file zdbh))
  70.        (progn
  71.   (if (= (NewDialog1 "    是否替换原有宗地?") 1) ;_替换
  72.     (progn
  73. ;;;       (setq r_list (reverse (readfile_to_list file)))
  74.       (setq r_list (reverse (at_file_to_list_st file)))
  75.       (setq
  76.         r_list (lt:list-subst-n r_list (- f_num 1) zdbh)
  77.       )
  78.       (setq r_list (lt:list-subst-n r_list f_num dz))
  79.       (setq
  80.         r_list (lt:list-subst-n r_list (+ f_num 1) nz)
  81.       )
  82.       (setq
  83.         r_list (lt:list-subst-n r_list (+ f_num 2) sz)
  84.       )
  85.       (setq
  86.         r_list (lt:list-subst-n r_list (+ f_num 3) bz)
  87.       )
  88.       (setq fn (open file "w"))
  89.       (mapcar '(lambda (x) (princ (strcat x "\n") fn))
  90.        r_list
  91.       )
  92.       (close fn)
  93.     )
  94.   )
  95.        )
  96.        (progn
  97.   (setq fn (open file "a"))
  98.   (princ p_list fn)
  99.   (close fn)
  100.        )
  101.      )
  102.    )
  103.    (progn
  104.      (setq fn (open file "a"))
  105.      (princ p_list fn)
  106.      (close fn)
  107.    )
  108. )
  109. (set_tile "Show_Info"
  110.     (strcat "当前临时记录文件宗地数: "
  111.      (itoa (/ (length (at_file_to_list_st file)) 5))
  112.     )
  113. )
  114.       )
  115.       (progn
  116. (alert "宗地编号也得有吧...")
  117.       )
  118.     )
  119.   )
  120.   ;; 确认覆盖原宗地对话框
  121.   (defun NewDialog1 (info / id std)
  122.     (setq id
  123.     (load_dialog
  124.       Temp_Dcl
  125.     )
  126.     )
  127.     (new_dialog "New_Tab" id)
  128.     (set_tile "New_D_info" info)
  129.     (setq std (start_dialog))
  130.     (unload_dialog id)
  131.     std
  132.   )
  133. ;;; 输出到Excel文件
  134.   (defun out_put
  135.   (/ *XLAPP* FILE FILE_TMP I R_LIST XLS_LIST XLS_TMP isopen)
  136.     (setq file_tmp Temp_File)
  137.     (if (findfile file_tmp)
  138.       (progn
  139. (alert (strcat "输出前请保存你正在编辑的Excel文件\n\n 转出完成后会关闭所有Excel程序!"))
  140. (setq file (getfiled "输入文件名" "c:\" "xls" 1))
  141. (if (and file (setq isopen (open file "w")))
  142.    (progn
  143.      (close isopen)
  144.      (if (setq r_list (at_file_to_list_st file_tmp))
  145.        (progn
  146.   (setq r_list (reverse r_list))
  147.   (setq i 0)
  148.   (setq xls_tmp '())
  149.   (setq xls_list (list))
  150.   (foreach r_list_i r_list
  151.     (setq xls_tmp (append (list r_list_i) xls_tmp))
  152.     (if (= i 4)
  153.       (progn
  154.         (setq xls_list
  155.         (append (list (reverse xls_tmp)) xls_list)
  156.         )
  157.         (setq xls_tmp '())
  158.         (setq i -1)
  159.       )
  160.     )
  161.     (setq i (1+ i))
  162.   )
  163.   (setq xls_list (reverse xls_list))
  164.   (setq *xlapp* (vlxls-app-open file nil))
  165.   (vlxls-cell-put-value
  166.     *xlapp*
  167.     (strcat "A1:E" (itoa (/ (length r_list) 5)))
  168.     xls_list
  169.   )
  170.   (vlxls-app-save *xlapp*)
  171.   (vla-put-visible *xlapp* 1)
  172.   (vlxls-app-quit *xlapp* nil)
  173.   (alert (strcat "文件已保存到\n" file))
  174.        )
  175.        (progn
  176.   (alert "文件中没有记录,请先录入")
  177.   )
  178.      )
  179.    )
  180.    (progn
  181.      (alert "没有选择文件或文件处于使用状态")
  182.    )
  183. )
  184.       )
  185.       (progn
  186. (alert "没有记录信息,请重新录入")
  187. )
  188.     )
  189.     (princ)
  190.   )
  191. ;;; 生成DCL文件
  192.   (defun dcl_s (/ file fn f_list F_LIST_1 F_LIST_0)
  193.     (setq file Temp_Dcl)
  194.     (setq fn (open file "w"))
  195.     (setq f_list
  196.     (strcat
  197.       "
  198. dcl_settings : default_dcl_settings { audit_level = 3; }
  199. ZdData : dialog {
  200.     value = "By ls...";
  201.     initial_focus = "button_cen";
  202.     : image_button {
  203.         key = "image_button_a";
  204.         aspect_ratio = 0.01;
  205.         width = 50;
  206.         }
  207.         :row{
  208.         alignment = right;
  209.         : edit_box {
  210.         label = "编    号:";
  211.         key = "zdbh";
  212.         edit_width = 30;
  213. }
  214. : button {
  215.             label = "选择(Z)";
  216.             key = "select_zdbh";
  217.             mnemonic = "Z";
  218. //            action = "select_zdbh";
  219.         }
  220. }
  221. :row{
  222. alignment = right;
  223. : edit_box {
  224.         label = "东    至:";
  225.         key = "dz";
  226.         edit_width = 30;
  227.         }
  228.         : button {
  229.             label = "选择(D)";
  230.             key = "select_dz";
  231.             mnemonic = "D";
  232. //            action = "select_dz";
  233.         }
  234.         }
  235.         :row{
  236.         : edit_box {
  237.         label = "南    至:";
  238.         key = "nz";
  239.         edit_width = 30;
  240.         }
  241.         : button {
  242.             label = "选择(N)";
  243.             key = "select_nz";
  244.             mnemonic = "N";
  245. //            action = "select_nz";
  246.         }
  247.         }
  248.         :row{
  249.         : edit_box {
  250.         label = "西    至:";
  251.         key = "sz";
  252.         edit_width = 30;
  253.         }
  254.         : button {
  255.             label = "选择(S)";
  256.             key = "select_sz";
  257.             mnemonic = "S";
  258. //            action = "select_sz";
  259.         }
  260.         }
  261.         :row{
  262.         : edit_box {
  263.         label = "北    至:";
  264.         key = "bz";
  265.         edit_width = 30;
  266.         }
  267.         : button {
  268.             label = "选择(B)";
  269.             key = "select_bz";
  270.             mnemonic = "B";
  271. //            action = "select_bz";
  272.         }
  273.         }
  274. "    )
  275.     )
  276.     (setq f_list_0
  277.     (strcat
  278.       ": spacer {
  279.     }
  280.     : row {
  281.     :button {
  282.     label = "新建文件";
  283.     key = "New_File";
  284.     fixed_width = true;
  285.     }
  286.     : button {
  287.             label = "记录此宗地(O)";
  288.             key = "S_This";
  289.             mnemonic = "O";
  290.         }
  291.         }
  292.      :text {
  293.            label="当前临时记录文件宗地数:" ;
  294.            key="Show_Info";
  295.            }
  296.     : spacer {
  297.     }
  298.     : row {
  299.         : button {
  300.             label = "写入Excel文件(W)";
  301.             key = "button_ok";
  302.             mnemonic = "W";
  303.         }
  304.         : button {
  305.             label = "取 消(C)";
  306.             key = "cancel";
  307.             mnemonic = "C";
  308.             is_default = true;
  309.             is_cancel = true;
  310.         }
  311.     }
  312.     : image_button {
  313.         key = "image_button_b";
  314.         aspect_ratio = 0.01;
  315.         width = 50;
  316.     }
  317. }"    )
  318.     )
  319.     (setq f_list_1
  320.     (strcat
  321.       "New_Tab : dialog {
  322.    value = "确认信息";
  323.    spacer;
  324.    :text
  325.    {label="信息显示" ;
  326.    key = "New_D_info";
  327.    }
  328.      ok_cancel;
  329. }"    )
  330.     )
  331.     (princ f_list fn)
  332.     (princ f_list_0 fn)
  333.     (princ f_list_1 fn)
  334.     (close fn)
  335.   )
  336. ;;;--------------------------------------------------------------;;;
  337. ;;;                            End                               ;;;
  338. ;;;--------------------------------------------------------------;;;
  339. ;;; 主程序
  340.   (dcl_s)
  341.   (setq id
  342.   (load_dialog
  343.     Temp_Dcl
  344.   )
  345.   )
  346.   (if (< id 0)
  347.     (exit)
  348.   )
  349.   (setq std 10)
  350.   (while (> std 0)
  351.     (if (not (new_dialog "ZdData" id))
  352.       (exit)
  353.     )
  354.     (action_tile "select_zdbh" "(done_dialog 1)")
  355.     (action_tile "select_dz" "(done_dialog 2)")
  356.     (action_tile "select_nz" "(done_dialog 3)")
  357.     (action_tile "select_sz" "(done_dialog 4)")
  358.     (action_tile "select_bz" "(done_dialog 5)")
  359.     (action_tile "New_File" "(New_File)")
  360.     (action_tile "S_This" "(S_This)")
  361. ;;;    (action_tile "button_ok" "(out_put)(done_dialog 0)")
  362.     (action_tile "button_ok" "(out_put)")
  363.     (action_tile "cancel" "(done_dialog 0)")
  364.     (set_dialog zdbh dz nz sz bz)
  365.     (setq std (start_dialog))
  366.     (cond
  367.       ((= std 1)
  368.        (while (not (setq obj (entsel "\n选择宗地号:"))))
  369.        (setq zdbh (cdr (assoc 1 (entget (car obj)))))
  370.       )
  371.       ((= std 2)
  372.        (while (not (setq obj (entsel "\n选择东至:"))))
  373.        (setq dz (cdr (assoc 1 (entget (car obj)))))
  374.       )
  375.       ((= std 3)
  376.        (while (not (setq obj (entsel "\n选择南至:"))))
  377.        (setq nz (cdr (assoc 1 (entget (car obj)))))
  378.       )
  379.       ((= std 4)
  380.        (while (not (setq obj (entsel "\n选择西至:"))))
  381.        (setq sz (cdr (assoc 1 (entget (car obj)))))
  382.       )
  383.       ((= std 5)
  384.        (while (not (setq obj (entsel "\n选择北至:"))))
  385.        (setq bz (cdr (assoc 1 (entget (car obj)))))
  386.       )
  387.     )
  388.   )
  389.   (unload_dialog id)
  390.   (princ)
  391. )
 楼主| 发表于 2010-5-18 21:50:00 | 显示全部楼层

谢谢了,可我加载第一次可以用,以后加载就用不了了,怎么回事呢,而且生成的文件打不开

能不能麻烦解决下

发表于 2010-5-19 12:11:00 | 显示全部楼层

1、不能用有什么提示?

2、文件 Lisp_Function.VLX 放到CAD的搜索目录没有?

3、生成的Excel文件,你电脑上有没有装OFFICE的Excel?

 楼主| 发表于 2010-5-19 17:59:00 | 显示全部楼层

具体也不好说清楚,如果你有空的话,请指教下

qq:280462207

发表于 2010-5-23 21:23:00 | 显示全部楼层
高手啊,随便写写就出来了
发表于 2011-10-22 20:04:15 | 显示全部楼层
高手啊,随便写写就出来了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-28 09:32 , Processed in 0.171828 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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