明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1901|回复: 12

[经验] 批量建块+图块统计

[复制链接]
发表于 2023-3-14 14:39 | 显示全部楼层 |阅读模式
全屋定制使用


本帖子中包含更多资源

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

x

评分

参与人数 1明经币 +1 收起 理由
kucha007 + 1 赞一个!

查看全部评分

"觉得好,就打赏"
    共1人打赏
发表于 2023-4-4 18:44 | 显示全部楼层
作者--LeeMac


  1. ;;--------------=={ Count.lsp - Advanced Block Counter }==--------------;;
  2. ;;                                                                      ;;
  3. ;;  This program enables the user to record the quantities of a         ;;
  4. ;;  selection or all standard or dynamic blocks in the working drawing. ;;
  5. ;;  The results of the block count may be displayed at the AutoCAD      ;;
  6. ;;  command-line, written to a Text or CSV file, or displayed in an     ;;
  7. ;;  AutoCAD Table, where available.                                     ;;
  8. ;;                                                                      ;;
  9. ;;  Upon issuing the command syntax 'count' at the AutoCAD              ;;
  10. ;;  command-line, the user is prompted to make a selection of standard  ;;
  11. ;;  or dynamic blocks to be counted by the program. At this prompt,     ;;
  12. ;;  the user may right-click or press 'Enter' to automatically count    ;;
  13. ;;  all blocks in the drawing.                                          ;;
  14. ;;                                                                      ;;
  15. ;;  Depending on the output setting, the results may then be printed    ;;
  16. ;;  to the AutoCAD command-line and displayed in the Text Window, or    ;;
  17. ;;  the user will be prompted to specify an insertion point for the     ;;
  18. ;;  table, or a filename & location for the Text or CSV output file.    ;;
  19. ;;                                                                      ;;
  20. ;;  The program settings may be configured using the 'countsettings'    ;;
  21. ;;  command; this command will present the user with a dialog interface ;;
  22. ;;  through which the data output, table & file headings, displayed     ;;
  23. ;;  columns, sorting field & sort order may each be altered.            ;;
  24. ;;----------------------------------------------------------------------;;
  25. ;;  Author:  Lee Mac, Copyright ?2014  -  www.lee-mac.com              ;;
  26. ;;----------------------------------------------------------------------;;
  27. ;;  Version 1.0    -    2010-06-05                                      ;;
  28. ;;                                                                      ;;
  29. ;;  - First release.                                                    ;;
  30. ;;----------------------------------------------------------------------;;
  31. ;;  Version 1.1    -    2010-06-06                                      ;;
  32. ;;                                                                      ;;
  33. ;;  - Updated code to include Settings dialog.                          ;;
  34. ;;  - Added Undo Marks.                                                 ;;
  35. ;;----------------------------------------------------------------------;;
  36. ;;  Version 1.2    -    2010-06-06                                      ;;
  37. ;;                                                                      ;;
  38. ;;  - Fixed bug with 64-bit systems.                                    ;;
  39. ;;----------------------------------------------------------------------;;
  40. ;;  Version 1.3    -    2011-03-02                                      ;;
  41. ;;                                                                      ;;
  42. ;;  - Program completely rewritten.                                     ;;
  43. ;;  - Updated code to work without error on 64-bit systems by fixing    ;;
  44. ;;    bug with ObjectID subfunction - my thanks go to member 'Jeff M'   ;;
  45. ;;    at theSwamp.org forums for helping me solve this problem.         ;;
  46. ;;  - Added ability to write block count to Text/CSV Files.             ;;
  47. ;;----------------------------------------------------------------------;;
  48. ;;  Version 1.4    -    2014-06-15                                      ;;
  49. ;;                                                                      ;;
  50. ;;  - Program completely rewritten.                                     ;;
  51. ;;----------------------------------------------------------------------;;

  52. (setq
  53.     count:version "1-4"
  54.     count:defaults
  55.    '(
  56.         (out "tab")
  57.         (tg1 "1")
  58.         (tg2 "1")
  59.         (tg3 "1")
  60.         (ed1 "Block Data")
  61.         (ed2 "Preview")
  62.         (ed3 "Block Name")
  63.         (ed4 "Count")
  64.         (srt "blk")
  65.         (ord "asc")
  66.     )
  67. )

  68. ;;----------------------------------------------------------------------;;

  69. (defun count:fixdir ( dir )
  70.     (vl-string-right-trim "\" (vl-string-translate "/" "\" dir))
  71. )

  72. ;;----------------------------------------------------------------------;;

  73. (defun count:getsavepath ( / tmp )
  74.     (cond      
  75.         (   (setq tmp (getvar 'roamablerootprefix))
  76.             (strcat (count:fixdir tmp) "\\Support")
  77.         )
  78.         (   (setq tmp (findfile "acad.pat"))
  79.             (count:fixdir (vl-filename-directory tmp))
  80.         )
  81.         (   (count:fixdir (vl-filename-directory (vl-filename-mktemp))))
  82.     )
  83. )

  84. ;;----------------------------------------------------------------------;;

  85. (setq count:savepath (count:getsavepath) ;; Save path for DCL & Config files
  86.       count:dclfname (strcat count:savepath "\\LMAC_count_V" count:version ".dcl")
  87.       count:cfgfname (strcat count:savepath "\\LMAC_count_V" count:version ".cfg")
  88. )

  89. ;;----------------------------------------------------------------------;;

  90. (defun c:count

  91.     (
  92.         /
  93.         *error*
  94.         all
  95.         col
  96.         des dir
  97.         ed1 ed2 ed3 ed4
  98.         fil fnm fun
  99.         hgt
  100.         idx ins
  101.         lst
  102.         ord out
  103.         row
  104.         sel srt
  105.         tab tg1 tg2 tg3 tmp
  106.         xrf
  107.     )

  108.     (defun *error* ( msg )
  109.         (if (= 'file (type des))
  110.             (close des)
  111.         )
  112.         (if (and (= 'vla-object (type tab))
  113.                  (null (vlax-erased-p tab))
  114.                  (= "AcDbTable" (vla-get-objectname tab))
  115.                  (vlax-write-enabled-p tab)
  116.             )
  117.             (vla-put-regeneratetablesuppressed tab :vlax-false)
  118.         )
  119.         (if (and (= 'vla-object (type count:wshobject))
  120.                  (not (vlax-object-released-p count:wshobject))
  121.             )
  122.             (progn
  123.                 (vlax-release-object count:wshobject)
  124.                 (setq count:wshobject nil)
  125.             )
  126.         )
  127.         (count:endundo (count:acdoc))
  128.         (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  129.             (princ (strcat "\nError: " msg))
  130.         )
  131.         (princ)
  132.     )

  133.     (if (not (findfile count:cfgfname))
  134.         (count:writecfg count:cfgfname (mapcar 'cadr count:defaults))
  135.     )
  136.     (count:readcfg count:cfgfname (mapcar 'car count:defaults))
  137.     (foreach sym count:defaults
  138.         (if (not (boundp (car sym))) (apply 'set sym))
  139.     )
  140.     (if (and (= "tab" out) (not (vlax-method-applicable-p (vla-get-modelspace (count:acdoc)) 'addtable)))
  141.         (setq out "txt")
  142.     )
  143.     (count:startundo (count:acdoc))

  144.     (while (setq tmp (tblnext "block" (null tmp)))
  145.         (if (= 4 (logand 4 (cdr (assoc 70 tmp))))
  146.             (setq xrf (vl-list* "," (cdr (assoc 2 tmp)) xrf))
  147.         )
  148.     )
  149.     (if xrf
  150.         (setq fil  (list '(0 . "INSERT") '(-4 . "<NOT") (cons 2 (apply 'strcat (cdr xrf))) '(-4 . "NOT>")))
  151.         (setq fil '((0 . "INSERT")))
  152.     )
  153.     (cond
  154.         (   (null (setq all (ssget "_X" fil)))
  155.             (count:popup
  156.                 "No Blocks Found" 64
  157.                 (princ "No blocks were found in the active drawing.")
  158.             )
  159.         )
  160.         (   (and (= "tab" out) (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer)))))))
  161.             (count:popup
  162.                 "Current Layer Locked" 64
  163.                 (princ "Please unlock the current layer before using this program.")
  164.             )
  165.         )
  166.         (   (progn
  167.                 (setvar 'nomutt 1)
  168.                 (princ "\nSelect blocks to count <all>: ")
  169.                 (setq sel
  170.                     (cond
  171.                         (   (null (setq sel (vl-catch-all-apply 'ssget (list fil))))
  172.                             all
  173.                         )
  174.                         (   (null (vl-catch-all-error-p sel))
  175.                             sel
  176.                         )
  177.                     )
  178.                 )
  179.                 (setvar 'nomutt 0)
  180.                 (null sel)
  181.             )
  182.         )
  183.         (   (or (= "com" out)
  184.                 (and (=  "tab" out) (setq ins (getpoint "\nSpecify point for table: ")))
  185.                 (and (/= "tab" out)
  186.                     (setq fnm
  187.                         (getfiled "Create Output File"
  188.                             (cond
  189.                                 (   (and (setq dir (getenv "LMac\\countdir"))
  190.                                          (vl-file-directory-p (setq dir (count:fixdir dir)))
  191.                                     )
  192.                                     (strcat dir "\")
  193.                                 )
  194.                                 (   (getvar 'dwgprefix))
  195.                             )
  196.                             out 1
  197.                         )
  198.                     )
  199.                 )
  200.             )
  201.             (repeat (setq idx (sslength sel))
  202.                 (setq lst (count:assoc++ (count:effectivename (ssname sel (setq idx (1- idx)))) lst))
  203.             )
  204.             (if (= "blk" srt)
  205.                 (setq fun (eval (list 'lambda '( a b ) (list (if (= "asc" ord) '< '>) '(strcase (car a)) '(strcase (car b))))))
  206.                 (setq fun (eval (list 'lambda '( a b ) (list (if (= "asc" ord) '< '>) '(cdr a) '(cdr b)))))
  207.             )
  208.             (setq lst (vl-sort lst 'fun))
  209.             (cond
  210.                 (   (= "com" out)
  211.                     (defun prinn ( x ) (princ "\n") (princ x))
  212.                     (prinn (count:padbetween "" "" "=" 60))
  213.                     (if (= "1" tg1)
  214.                         (progn
  215.                             (prinn ed1)
  216.                             (prinn (count:padbetween "" "" "-" 60))
  217.                         )
  218.                     )
  219.                     (prinn (count:padbetween ed3 ed4 " " 55))
  220.                     (prinn (count:padbetween "" "" "-"   60))
  221.                     (if (= "1" tg3)
  222.                         (foreach itm lst
  223.                             (prinn (count:padbetween (car itm) (itoa (cdr itm)) "." 55))
  224.                         )
  225.                         (foreach itm lst (prinn (car itm)))
  226.                     )
  227.                     (prinn (count:padbetween "" "" "=" 60))
  228.                     (textpage)
  229.                 )
  230.                 (   (= "tab" out)
  231.                     (if (= "1" tg3)
  232.                         (setq lst (mapcar '(lambda ( x ) (list (car x) (itoa (cdr x)))) lst))
  233.                         (setq lst (mapcar '(lambda ( x ) (list (car x))) lst))
  234.                     )
  235.                     (setq hgt
  236.                         (vla-gettextheight
  237.                             (vla-item
  238.                                 (vla-item (vla-get-dictionaries (count:acdoc)) "acad_tablestyle")
  239.                                 (getvar 'ctablestyle)
  240.                             )
  241.                             acdatarow
  242.                         )
  243.                     )
  244.                     (setq tab
  245.                         (vla-addtable
  246.                             (vlax-get-property (count:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
  247.                             (vlax-3D-point (trans ins 1 0))
  248.                             (+ (length lst) 2)
  249.                             (+ 1 (atoi tg2) (atoi tg3))
  250.                             (* 2.5 hgt)
  251.                             (* hgt
  252.                                 (max
  253.                                     (apply 'max
  254.                                         (mapcar 'strlen
  255.                                             (append
  256.                                                 (if (= "1" tg2) (list ed2))
  257.                                                 (if (= "1" tg3) (list ed4))
  258.                                                 (cons ed3 (apply 'append lst))
  259.                                             )
  260.                                         )
  261.                                     )
  262.                                     (if (= "1" tg1) (/ (strlen ed1) (+ 1 (atoi tg2) (atoi tg3))) 0)
  263.                                 )
  264.                             )
  265.                         )
  266.                     )
  267.                     (vla-put-regeneratetablesuppressed tab :vlax-true)
  268.                     (vla-put-stylename tab (getvar 'ctablestyle))
  269.                     (setq col 0)
  270.                     (mapcar
  271.                        '(lambda ( a b ) (if (= "1" a) (progn (vla-settext tab 1 col b) (setq col (1+ col)))))
  272.                         (list tg2 "1" tg3)
  273.                         (list ed2 ed3 ed4)
  274.                     )
  275.                     (setq row 2)
  276.                     (foreach itm lst
  277.                         (if (= "1" tg2)
  278.                             (count:setblocktablerecord tab row (setq col 0) (car itm))
  279.                             (setq col -1)
  280.                         )
  281.                         (foreach txt itm
  282.                             (vla-settext tab row (setq col (1+ col)) txt)
  283.                         )
  284.                         (setq row (1+ row))
  285.                     )
  286.                     (if (= "1" tg1)
  287.                         (vla-settext tab 0 0 ed1)
  288.                         (vla-deleterows tab 0 1)
  289.                     )
  290.                 )
  291.                 (   (setenv "LMac\\countdir" (count:fixdir (vl-filename-directory fnm)))
  292.                     (if
  293.                         (
  294.                             (if (= "txt" out)
  295.                                 count:writetxt
  296.                                 count:writecsv
  297.                             )
  298.                             (append
  299.                                 (if (= "1" tg1)
  300.                                     (list (list ed1))
  301.                                 )
  302.                                 (if (= "1" tg3)
  303.                                     (cons (list ed3 ed4) (mapcar '(lambda ( x ) (list (car x) (itoa (cdr x)))) lst))
  304.                                     (cons (list ed3)     (mapcar '(lambda ( x ) (list (car x))) lst))
  305.                                 )
  306.                             )
  307.                             fnm
  308.                         )
  309.                         (princ (strcat "\nBlock data written to " fnm))
  310.                         (count:popup "Unable to Create Output File" 48
  311.                             (princ
  312.                                 (strcat
  313.                                     "The program was unable to create the following file:\n\n"
  314.                                     fnm
  315.                                     "\n\nPlease ensure that you have write-permissions for the above directory."
  316.                                 )
  317.                             )
  318.                         )
  319.                     )
  320.                 )
  321.             )
  322.         )
  323.     )
  324.     (*error* nil)
  325.     (princ)
  326. )

  327. ;;----------------------------------------------------------------------;;

  328. (defun c:countsettings

  329.     (
  330.         /
  331.         *error*
  332.         dch des
  333.         ord out out-fun
  334.         srt
  335.         tg1 tg1-fun tg2 tg2-fun tg3 tg3-fun
  336.     )

  337.     (defun *error* ( msg )
  338.         (if (= 'file (type des))
  339.             (close des)
  340.         )
  341.         (if (and (= 'int (type dch))
  342.                  (< 0 dch)
  343.             )
  344.             (unload_dialog dch)
  345.         )
  346.         (if (and (= 'vla-object (type count:wshobject))
  347.                  (not (vlax-object-released-p count:wshobject))
  348.             )
  349.             (progn
  350.                 (vlax-release-object count:wshobject)
  351.                 (setq count:wshobject nil)
  352.             )
  353.         )
  354.         (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  355.             (princ (strcat "\nError: " msg))
  356.         )
  357.         (princ)
  358.     )

  359.     (if (not (findfile count:cfgfname))
  360.         (count:writecfg count:cfgfname (mapcar 'cadr count:defaults))
  361.     )
  362.     (count:readcfg count:cfgfname (mapcar 'car count:defaults))
  363.     (foreach sym count:defaults
  364.         (if (not (boundp (car sym))) (apply 'set sym))
  365.     )
  366.     (cond
  367.         (   (not (count:writedcl count:dclfname))
  368.             (count:popup "DCL file could not be written" 48
  369.                 (princ
  370.                     (strcat
  371.                         "The DCL file required by this program could not be written to the following location:\n\n"
  372.                         count:dclfname
  373.                         "\n\nPlease ensure that you have write-permissions for the above directory."
  374.                     )
  375.                 )
  376.             )
  377.         )
  378.         (   (<= (setq dch (load_dialog count:dclfname)) 0)
  379.             (count:popup "DCL file could not be loaded" 48
  380.                 (princ
  381.                     (strcat
  382.                         "The following DCL file required by this program could not be loaded:\n\n"
  383.                         count:dclfname
  384.                         "\n\nPlease verify the integrity of this file."
  385.                     )
  386.                 )
  387.             )
  388.         )
  389.         (   (not (new_dialog "dia" dch))
  390.             (count:popup "DCL file contains an error" 48
  391.                 (princ
  392.                     (strcat
  393.                         "The program dialog could not be displayed as the following DCL file file contains an error:\n\n"
  394.                         count:dclfname
  395.                         "\n\nPlease verify the integrity of this file."
  396.                     )
  397.                 )
  398.             )
  399.         )
  400.         (   t
  401.             (set_tile "dcl"
  402.                 (strcat
  403.                     "Count.lsp Version "
  404.                     (vl-string-translate "-" "." count:version)
  405.                     " \\U+00A9 Lee Mac "
  406.                     (menucmd "m=$(edtime,0,yyyy)")
  407.                 )
  408.             )
  409.             (if (and (= "tab" out) (not (vlax-method-applicable-p (vla-get-modelspace (count:acdoc)) 'addtable)))
  410.                 (progn
  411.                     (mode_tile "tab" 1)
  412.                     (setq out "txt")
  413.                 )
  414.             )
  415.             (   (setq tg1-fun (lambda ( val ) (mode_tile "ed1" (- 1 (atoi (setq tg1 val)))))) (set_tile "tg1" tg1))
  416.             (action_tile "tg1" "(tg1-fun $value)")

  417.             (   (setq tg2-fun (lambda ( val ) (mode_tile "ed2" (- 1 (atoi (setq tg2 val)))))) (set_tile "tg2" tg2))
  418.             (action_tile "tg2" "(tg2-fun $value)")

  419.             (   (setq tg3-fun (lambda ( val ) (mode_tile "ed4" (- 1 (atoi (setq tg3 val)))))) (set_tile "tg3" tg3))
  420.             (action_tile "tg3" "(tg3-fun $value)")

  421.             (foreach key '("ed1" "ed2" "ed3" "ed4")
  422.                 (set_tile key (eval (read key)))
  423.                 (action_tile key (strcat "(setq " key " $value)"))
  424.             )
  425.             (set_tile out "1")
  426.             (   (setq out-fun
  427.                     (lambda ( val )
  428.                         (if (= "tab" (setq out val))
  429.                             (progn
  430.                                 (mode_tile "tg2" 0)
  431.                                 (mode_tile "ed2" (- 1 (atoi tg2)))
  432.                             )
  433.                             (progn
  434.                                 (mode_tile "tg2" 1)
  435.                                 (mode_tile "ed2" 1)
  436.                             )
  437.                         )
  438.                     )
  439.                 )
  440.                 out
  441.             )
  442.             (foreach key '("tab" "txt" "csv" "com")
  443.                 (action_tile key "(out-fun $key)")
  444.             )
  445.             (set_tile srt "1")
  446.             (foreach key '("blk" "qty")
  447.                 (action_tile key "(setq srt $key)")
  448.             )
  449.             (set_tile ord "1")
  450.             (foreach key '("asc" "des")
  451.                 (action_tile key "(setq ord $key)")
  452.             )
  453.             (if (= 1 (start_dialog))
  454.                 (count:writecfg count:cfgfname (mapcar 'eval (mapcar 'car count:defaults)))
  455.             )
  456.         )
  457.     )
  458.     (*error* nil)
  459.     (princ)
  460. )

  461. ;;----------------------------------------------------------------------;;
  462.                
  463. (defun count:popup ( ttl flg msg / err )
  464.     (setq err (vl-catch-all-apply 'vlax-invoke-method (list (count:wsh) 'popup msg 0 ttl flg)))
  465.     (if (null (vl-catch-all-error-p err))
  466.         err
  467.     )
  468. )

  469. ;;----------------------------------------------------------------------;;

  470. (defun count:wsh nil
  471.     (cond (count:wshobject) ((setq count:wshobject (vlax-create-object "wscript.shell"))))
  472. )

  473. ;;----------------------------------------------------------------------;;

  474. (defun count:tostring ( arg / dim )
  475.     (cond
  476.         (   (= 'int (type arg))
  477.             (itoa arg)
  478.         )
  479.         (   (= 'real (type arg))
  480.             (setq dim (getvar 'dimzin))
  481.             (setvar 'dimzin 8)
  482.             (setq arg (rtos arg 2 15))
  483.             (setvar 'dimzin dim)
  484.             arg
  485.         )
  486.         (   (vl-prin1-to-string arg))
  487.     )
  488. )

  489. ;;----------------------------------------------------------------------;;

  490. (defun count:writecfg ( cfg lst / des )
  491.     (if (setq des (open cfg "w"))
  492.         (progn
  493.             (foreach itm lst (write-line (count:tostring itm) des))
  494.             (setq des (close des))
  495.             t
  496.         )
  497.     )
  498. )

  499. ;;----------------------------------------------------------------------;;

  500. (defun count:readcfg ( cfg lst / des itm )
  501.     (if
  502.         (and
  503.             (setq cfg (findfile cfg))
  504.             (setq des (open cfg "r"))
  505.         )
  506.         (progn
  507.             (foreach sym lst
  508.                 (if (setq itm (read-line des))
  509.                     (set  sym (read itm))
  510.                 )
  511.             )
  512.             (setq des (close des))
  513.             t
  514.         )
  515.     )
  516. )

  517. ;;----------------------------------------------------------------------;;

  518. (defun count:writedcl ( dcl / des )
  519.     (cond
  520.         (   (findfile dcl))
  521.         (   (setq des (open dcl "w"))
  522.             (foreach itm
  523.                '(
  524.                     "//--------------------=={ Count Dialog Definition }==-------------------//"
  525.                     "//                                                                      //"
  526.                     "//  Dialog definition file for use in conjunction with Count.lsp        //"
  527.                     "//----------------------------------------------------------------------//"
  528.                     "//  Author:  Lee Mac, Copyright ?2014  -  www.lee-mac.com              //"
  529.                     "//----------------------------------------------------------------------//"
  530.                     ""
  531.                     "b15 : edit_box"
  532.                     "{"
  533.                     "    edit_width = 16;"
  534.                     "    edit_limit = 1024;"
  535.                     "    fixed_width = true;"
  536.                     "    alignment = centered;"
  537.                     "    horizontal_margin = none;"
  538.                     "    vertical_margin = none;"
  539.                     "}"
  540.                     "b30 : edit_box"
  541.                     "{"
  542.                     "    edit_width = 52;"
  543.                     "    edit_limit = 1024;"
  544.                     "    fixed_width = true;"
  545.                     "    alignment = centered;"
  546.                     "    horizontal_margin = none;"
  547.                     "    vertical_margin = none;"
  548.                     "}"
  549.                     "tog : toggle"
  550.                     "{"
  551.                     "    vertical_margin = none;"
  552.                     "    horizontal_margin = 0.2;"
  553.                     "}"
  554.                     "rwo : row"
  555.                     "{"
  556.                     "    fixed_width = true;"
  557.                     "    alignment = centered;"
  558.                     "}"
  559.                     "rrw : radio_row"
  560.                     "{"
  561.                     "    fixed_width = true;"
  562.                     "    alignment = centered;"
  563.                     "}"
  564.                     "dia : dialog"
  565.                     "{"
  566.                     "    key = "dcl";"
  567.                     "    spacer_1;"
  568.                     "    : boxed_column"
  569.                     "    {"
  570.                     "        label = "Output";"
  571.                     "        : rrw"
  572.                     "        {"
  573.                     "            : radio_button { key = "tab"; label = "Table"; }"
  574.                     "            : radio_button { key = "txt"; label = "Text File"; }"
  575.                     "            : radio_button { key = "csv"; label = "CSV File"; }"
  576.                     "            : radio_button { key = "com"; label = "Command line"; }"
  577.                     "        }"
  578.                     "        spacer;"
  579.                     "    }"
  580.                     "    : boxed_column"
  581.                     "    {"
  582.                     "        label = "Headings";"
  583.                     "        spacer_1;"
  584.                     "        : rwo"
  585.                     "        {"
  586.                     "            : tog { key = "tg1"; }"
  587.                     "            : b30 { key = "ed1"; }"
  588.                     "            : spacer"
  589.                     "            {"
  590.                     "                fixed_width = true;"
  591.                     "                vertical_margin = none;"
  592.                     "                width = 2.5;"
  593.                     "            }"
  594.                     "        }"
  595.                     "        : rwo"
  596.                     "        {"
  597.                     "            spacer;"
  598.                     "            : tog { key = "tg2"; }"
  599.                     "            : b15 { key = "ed2"; }"
  600.                     "            : b15 { key = "ed3"; }"
  601.                     "            : b15 { key = "ed4"; }"
  602.                     "            : tog { key = "tg3"; }"
  603.                     "            spacer;"
  604.                     "        }"
  605.                     "        spacer_1;"
  606.                     "    }"
  607.                     "    : row"
  608.                     "    {"
  609.                     "        : boxed_column"
  610.                     "        {"
  611.                     "            label = "Sort By";"
  612.                     "            : rrw"
  613.                     "            {"
  614.                     "                : radio_button { key = "blk"; label = "Block Name"; }"
  615.                     "                : radio_button { key = "qty"; label = "Quantity"; }"
  616.                     "            }"
  617.                     "            spacer;"
  618.                     "        }"
  619.                     "        : boxed_column"
  620.                     "        {"
  621.                     "            label = "Sort Order";"
  622.                     "            : rrw"
  623.                     "            {"
  624.                     "                : radio_button { key = "asc"; label = "Ascending"; }"
  625.                     "                : radio_button { key = "des"; label = "Descending"; }"
  626.                     "            }"
  627.                     "            spacer;"
  628.                     "        }"
  629.                     "    }"
  630.                     "    spacer_1; ok_cancel;"
  631.                     "}"
  632.                     ""
  633.                     "//----------------------------------------------------------------------//"
  634.                     "//                             End of File                              //"
  635.                     "//----------------------------------------------------------------------//"
  636.                 )
  637.                 (write-line itm des)
  638.             )
  639.             (setq des (close des))
  640.             (while (not (findfile dcl))) ;; for slow HDDs
  641.             dcl
  642.         )
  643.     )
  644. )

  645. ;;----------------------------------------------------------------------;;

  646. (defun count:writecsv ( lst csv / des sep )
  647.     (if (setq des (open csv "w"))
  648.         (progn
  649.             (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
  650.             (foreach row lst (write-line (count:lst->csv row sep) des))
  651.             (close des)
  652.             t
  653.         )
  654.     )
  655. )

  656. ;;----------------------------------------------------------------------;;

  657. (defun count:lst->csv ( lst sep )
  658.     (if (cdr lst)
  659.         (strcat (count:csv-addquotes (car lst) sep) sep (count:lst->csv (cdr lst) sep))
  660.         (count:csv-addquotes (car lst) sep)
  661.     )
  662. )

  663. ;;----------------------------------------------------------------------;;

  664. (defun count:csv-addquotes ( str sep / pos )
  665.     (cond
  666.         (   (wcmatch str (strcat "*[`" sep ""]*"))
  667.             (setq pos 0)   
  668.             (while (setq pos (vl-string-position 34 str pos))
  669.                 (setq str (vl-string-subst """" """ str pos)
  670.                       pos (+ pos 2)
  671.                 )
  672.             )
  673.             (strcat """ str """)
  674.         )
  675.         (   str   )
  676.     )
  677. )

  678. ;;----------------------------------------------------------------------;;

  679. (defun count:writetxt ( lst txt / des )
  680.     (if (setq des (open txt "w"))
  681.         (progn
  682.             (foreach itm lst (write-line (count:lst->str itm "\t") des))
  683.             (close des)
  684.             t
  685.         )
  686.     )
  687. )

  688. ;;----------------------------------------------------------------------;;

  689. (defun count:lst->str ( lst del )
  690.     (if (cdr lst)
  691.         (strcat (car lst) del (count:lst->str (cdr lst) del))
  692.         (car lst)
  693.     )
  694. )

  695. ;;----------------------------------------------------------------------;;

  696. (defun count:padbetween ( s1 s2 ch ln )
  697.     (
  698.         (lambda ( a b c )
  699.             (repeat (- ln (length b) (length c)) (setq c (cons a c)))
  700.             (vl-list->string (append b c))
  701.         )
  702.         (ascii ch)
  703.         (vl-string->list s1)
  704.         (vl-string->list s2)
  705.     )
  706. )

  707. ;;----------------------------------------------------------------------;;

  708. (defun count:setblocktablerecord ( obj row col blk )
  709.     (eval
  710.         (list 'defun 'count:setblocktablerecord '( obj row col blk )
  711.             (cons
  712.                 (if (vlax-method-applicable-p obj 'setblocktablerecordid32)
  713.                     'vla-setblocktablerecordid32
  714.                     'vla-setblocktablerecordid
  715.                 )
  716.                 (list
  717.                     'obj 'row 'col
  718.                     (list 'count:objectid (list 'vla-item (vla-get-blocks (count:acdoc)) 'blk))
  719.                     ':vlax-true
  720.                 )
  721.             )
  722.         )
  723.     )
  724.     (count:setblocktablerecord obj row col blk)
  725. )

  726. ;;----------------------------------------------------------------------;;

  727. (defun count:objectid ( obj )
  728.     (eval
  729.         (list 'defun 'count:objectid '( obj )
  730.             (cond
  731.                 (   (not (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*"))
  732.                    '(vla-get-objectid obj)
  733.                 )
  734.                 (   (= 'subr (type vla-get-objectid32))
  735.                    '(vla-get-objectid32 obj)
  736.                 )
  737.                 (   (list 'vla-getobjectidstring (vla-get-utility (count:acdoc)) 'obj ':vlax-false))
  738.             )
  739.         )
  740.     )
  741.     (count:objectid obj)
  742. )

  743. ;;----------------------------------------------------------------------;;

  744. (defun count:assoc++ ( key lst / itm )
  745.     (if (setq itm (assoc key lst))
  746.         (subst (cons key (1+ (cdr itm))) itm lst)
  747.         (cons  (cons key 1) lst)
  748.     )
  749. )

  750. ;;----------------------------------------------------------------------;;

  751. (defun count:effectivename ( ent / blk rep )
  752.     (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
  753.         (if
  754.             (and
  755.                 (setq rep
  756.                     (cdadr
  757.                         (assoc -3
  758.                             (entget
  759.                                 (cdr
  760.                                     (assoc 330
  761.                                         (entget
  762.                                             (tblobjname "block" blk)
  763.                                         )
  764.                                     )
  765.                                 )
  766.                                '("AcDbBlockRepBTag")
  767.                             )
  768.                         )
  769.                     )
  770.                 )
  771.                 (setq rep (handent (cdr (assoc 1005 rep))))
  772.             )
  773.             (setq blk (cdr (assoc 2 (entget rep))))
  774.         )
  775.     )
  776.     blk
  777. )

  778. ;;----------------------------------------------------------------------;;

  779. (defun count:startundo ( doc )
  780.     (count:endundo doc)
  781.     (vla-startundomark doc)
  782. )

  783. ;;----------------------------------------------------------------------;;

  784. (defun count:endundo ( doc )
  785.     (while (= 8 (logand 8 (getvar 'undoctl)))
  786.         (vla-endundomark doc)
  787.     )
  788. )

  789. ;;----------------------------------------------------------------------;;

  790. (defun count:acdoc nil
  791.     (eval (list 'defun 'count:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
  792.     (count:acdoc)
  793. )

  794. ;;----------------------------------------------------------------------;;

  795. (vl-load-com)
  796. (princ
  797.     (strcat
  798.         "\n:: Count.lsp | Version "
  799.         (vl-string-translate "-" "." count:version)
  800.         " | \\U+00A9 Lee Mac "
  801.         (menucmd "m=$(edtime,0,yyyy)")
  802.         " www.lee-mac.com ::"
  803.         "\n:: "count" - Main Program | "countsettings" - Settings ::"
  804.     )
  805. )
  806. (princ)

  807. ;;----------------------------------------------------------------------;;
  808. ;;                             End of File                              ;;
  809. ;;----------------------------------------------------------------------;;
发表于 2023-8-17 22:16 | 显示全部楼层
liunian0524 发表于 2023-5-22 11:33
这个图块统计论坛有源码

你号源码再哪里呢
发表于 2023-4-4 18:46 | 显示全部楼层
每人每天均有免费的明经币2个。


觉得好用点击【评分】,赏个币
发表于 2023-3-14 17:19 来自手机 | 显示全部楼层
大神能否分享原码
发表于 2023-3-21 16:35 | 显示全部楼层
这个有什么稀奇的哈
发表于 2023-3-29 15:13 | 显示全部楼层
大神能否分享原码
发表于 2023-4-8 11:32 | 显示全部楼层
这个真厉害
发表于 2023-5-22 11:33 | 显示全部楼层
本帖最后由 liunian0524 于 2023-9-6 09:17 编辑

6666666,支持
发表于 2023-5-22 11:40 | 显示全部楼层
楼主的这个不错!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-14 18:31 , Processed in 0.836112 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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