明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: 77077

[已解答] 函数搜索,便于大家收集整理自己的函数库~~~

    [复制链接]
发表于 2014-7-15 16:04 | 显示全部楼层
增加热键 文本框、列表框时ALT+字母键,非文本框、列表框按字母键
友情提示,在列表框中按字母键可以快速找到以该字母为首的函数,输入中文则找到该中文开头的函数。
按确定将复制到剪贴板。
按运行将用法中的语句通过sendcommand执行。如原函数是(entmakeline p1 p2)在用法一栏文本框中输入
(entmakeline (getpoint) (getpoint))可以执行。

  1. (defun make-dcl  (/ lst_str str file f)
  2.     (setq lst_str '(
  3. "hsss:dialog {"
  4. "    label = \"函数搜索\" ;"
  5. "    :spacer {}"
  6. "    :row {"
  7. "        :edit_box {"
  8. "            key = \"key1\" ;"
  9. "            label = \"关键词(&K)\" ;"
  10. "            width = 60 ;"
  11. "        }"
  12. "        :button {"
  13. "            key = \"key2\" ;"
  14. "            label = \"搜索(&S)\" ;"
  15. "        }"
  16. "        :button {"
  17. "            key = \"key3\" ;"
  18. "            label = \"显示全部(&A)\" ;"
  19. "        }"
  20. "    }"
  21. "    :boxed_column {"
  22. "        label = \"函数列表(&L)\" ;"
  23. "        :list_box {"
  24. "            key = \"key4\" ;"
  25. "        }"
  26. "    }"
  27. "    :edit_box {"
  28. "        key = \"key5\" ;"
  29. "        label = \"功能(&F)\" ;"
  30. "    }"
  31. "    :edit_box {"
  32. "        key = \"key6\" ;"
  33. "        label = \"用法(&U)\" ;"
  34. "    }"
  35. "    :spacer {}"
  36. "        :row {"
  37. "    ok_cancel;"
  38. "        :button {"
  39. "            key = \"key7\" ;"
  40. "            label = \"执行(&R)\" ;"
  41. "            fixed_width = true ;"
  42. "            width = 12 ;"
  43. "        }"
  44. "        }"
  45. "}"
  46.         )
  47.     )
  48.     (setq file (vl-filename-mktemp "DclTemp.dcl"))
  49.     (setq f (open file "w"))
  50.     (foreach str lst_str
  51.   (princ "\n" f)
  52.   (princ str f)
  53.     )
  54.     (close f)
  55.     file
  56. )
  57. ;读取txt文本文件,按行组成表
  58. (defun xx-txt2lst(files / out)
  59. (setq file (open files "r"))
  60. (setq out '())
  61. (while (setq a (read-line file))
  62.       (if (= (substr a 1 2) ";[");只提取";["开头的行.
  63.       (setq out (cons a out))
  64.       )
  65.   )
  66. (close file)
  67. (setq out (reverse out))
  68. )
  69. ;填充列表框
  70. (defun fill-list-box (key lst)
  71.      (start_list key)
  72.      (mapcar 'add_list lst)
  73.      (end_list)
  74. )
  75. ;;返回关键字所在的字符串表位置
  76. ;;code by edata@mjtd
  77. (defun sk_ss_str(str_lst key_str / i lst lst2)
  78.   (setq i -1 lst str_lst)
  79.   (while (setq a(car lst))
  80.     (setq lst(cdr lst) i (1+ i))
  81.     (if(wcmatch a (strcat "*" key_str "*"))
  82.       (setq lst2(cons  i lst2)))
  83.     )
  84.   (if lst2 (setq lst2(reverse lst2)))
  85. )
  86. ;=================程序开始========================
  87. (defun C:HSSS( / lst  lst1 lst2 lstx1 lstx2 dcl_file)
  88.   (setq f(open "D:\\XX工具箱\\我的函数库.lsp" "r"))
  89.   (if f (progn (and f (close f))(setq sk_path  "D:\\XX工具箱\\我的函数库.lsp"))
  90.     (or sk_path (setq sk_path(getfiled "选择函数库文件" "c:/" "lsp;dat;txt;*" 8))))
  91. (if sk_path
  92.   (progn   
  93. (setq lst  (xx-txt2lst sk_path)
  94.       lst1  (vl-remove-if '(lambda (x) (/= (substr x 1 7) ";[功能]")) lst)
  95.       lst2  (vl-remove-if '(lambda (x) (/= (substr x 1 7) ";[用法]")) lst)
  96.       lst1  (mapcar '(lambda (x) (substr x 8)) lst1)
  97.       lst2  (mapcar '(lambda (x) (substr x 8)) lst2)
  98.       lstx1 lst1
  99.       lstx2 lst2
  100.       )
  101. (setq dcl_id (load_dialog (setq dcl_file (make-dcl))))
  102. (if(findfile dcl_file)(vl-file-delete dcl_file))
  103. (new_dialog "hsss" dcl_id)
  104. (fill-list-box "key4" lstx1)
  105. (action_tile "key2" "(act-key2 lst1 lst2)")
  106. (action_tile "key3" "(act-key3)")
  107. (action_tile "key4" "(act-key4)")
  108. (action_tile "accept" "(act-key5)(done_dialog)")
  109. (action_tile "key7" "(act-key7)(done_dialog)")
  110. (start_dialog)(unload_dialog dcl_id)
  111. )
  112.   )
  113. (princ)
  114. )
  115. ;============DCL动作=============
  116. (defun act-key2(lst1 lst2 / str)
  117. (setq str (get_tile "key1"))   
  118.   (if (setq key_ss (sk_ss_str lst1 str))
  119.     (progn
  120.       (setq i -1 lstx1 '()  lstx2 '())
  121.       (while(setq a (nth (setq i (1+ i)) key_ss))
  122.         (setq lstx1(cons (nth a lst1) lstx1))
  123.         (setq lstx2(cons (nth a lst2) lstx2))
  124.         )
  125.       (if(and lstx1 lstx2)
  126.         (progn
  127.         (setq lstx1 (reverse lstx1)
  128.               lstx2 (reverse lstx2))
  129.         (fill-list-box "key4" lstx1)
  130.         )
  131.         )
  132.       )
  133.     (fill-list-box "key4" '("Sorry,未找到与描述相符的函数!"))
  134.     )
  135. )
  136. ;
  137. (defun act-key4( / n)
  138. (setq n (atoi (get_tile "key4")))     
  139. (set_tile "key5" (nth n lstx1))
  140. (set_tile "key6" (nth n lstx2))
  141. )
  142. ;
  143. (defun act-key3 ()
  144. (setq lstx1 lst1 lstx2 lst2)
  145. (fill-list-box "key4" lst1)
  146. )
  147. ;
  148. (defun act-key5        (/ str)
  149.   (if (/= (setq str (get_tile "key6")) "")
  150.     (sk_SetClipboard str)
  151.   )
  152. )
  153. ;
  154. (defun act-key7        (/ str)
  155.   (if (/= (setq str (get_tile "key6")) "")
  156.     (progn
  157.       (sk_SetClipboard str)
  158.     (if sk_path(load  sk_path))
  159.       (vla-SendCommand (vla-get-activedocument(vlax-get-acad-object)) (strcat str " "))
  160.        )
  161.   )
  162. )
  163. (defun sk_SetClipboard(clip / htm Clip_Bord);设置剪切板
  164. (setq htm (vlax-create-object "htmlfile"))
  165. (setq Clip_Bord (Vlax-Get-Property (Vlax-Get htm 'ParentWindow) 'ClipboardData))
  166. (Vlax-Invoke Clip_Bord 'SetData "text" clip)
  167. )
  168.       

评分

参与人数 1明经币 +1 收起 理由
yaokui25 + 1 很给力! 谢谢您~

查看全部评分

发表于 2014-7-15 17:07 来自手机 | 显示全部楼层
继续完善。。。。。
发表于 2014-7-15 22:11 来自手机 | 显示全部楼层
edata 发表于 2014-7-15 16:04
增加热键 文本框、列表框时ALT+字母键,非文本框、列表框按字母键
友情提示,在列表框中按字母键可以快速找 ...

怎么回事,出错了
发表于 2014-7-16 09:38 | 显示全部楼层
qyming 发表于 2014-7-15 22:11
怎么回事,出错了

不知道哪里错了。
发表于 2014-7-16 09:48 来自手机 | 显示全部楼层
应该是这段
(setq f(open "D:\\XX工具箱\\我的函数库.lsp" "r"))
(if f (progn (and f (close f))(setq sk_path"D:\\XX工具箱\\我的函数库.lsp"))
  (or sk_path (setq sk_path(getfiled "选择函数库文件" "c:/" "lsp;dat;txt;*" 8))))
(if sk_path
(progn  
(setq lst(xx-txt2lst sk_path)
  lst1(vl-remove-if '(lambda (x) (/= (substr x 1 7) ";[功能]")) lst)
  lst2(vl-remove-if '(lambda (x) (/= (substr x 1 7) ";[用法]")) lst)
  lst1(mapcar '(lambda (x) (substr x 8)) lst1)
  lst2(mapcar '(lambda (x) (substr x 8)) lst2)
  lstx1 lst1
  lstx2 lst2
  )
(set
发表于 2014-7-16 11:00 | 显示全部楼层
qyming 发表于 2014-7-16 09:48
应该是这段
(setq f(open "D:\\XX工具箱\\我的函数库.lsp" "r"))
(if f (progn (and f (close f))(setq s ...

我昨天试用没发现问题
发表于 2014-7-16 11:12 来自手机 | 显示全部楼层
21楼的?还是2楼的?2楼的是没问题
发表于 2014-7-16 11:26 | 显示全部楼层
qyming 发表于 2014-7-16 11:12
21楼的?还是2楼的?2楼的是没问题

21楼的,挺好用的。
发表于 2014-7-16 15:01 | 显示全部楼层
顶起了     
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-25 13:18 , Processed in 0.423518 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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