明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6315|回复: 12

[基础] area calculation autolisp

  [复制链接]
发表于 2009-12-18 20:03 | 显示全部楼层 |阅读模式

Dear Sir

im not chines user plz help me

thx

Pick inside the polyline & create no’s of triangles (Rectangle, rotated rectangle, arch, circle) and area of each triangle

本帖子中包含更多资源

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

x
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2009-12-18 21:22 | 显示全部楼层
  1. ;| TOTALAREA version 4.02 (Gile)
  2. Set the controls AREABOX, TOTALAREA, AREAEDIT, AREASHOW and AREACONV
  3. - Block "TotalArea":
  4. A definition block named "TotalArea" must be present in the drawing collection or
  5. as file "TotalArea.dwg" in an AutoCAD search path directory.
  6. This block must contain at least three attributes with "LABEL", "UNIT and "AREA" tags.
  7. "AREA" will be automatically populate with the sum of the areas of objects linked to it.
  8. (arc, circle, ellipse, polylines, spline, hatch, region, mpolygon)
  9. If it contains a fourth attribute with "NOBJ" tag, it will also be
  10. automatically populate with the number of items linked to the block.
  11. Format the display of the attribute "AREA":
  12. It is possible to assign a conversion factor to the value of the attribute.
  13. This value is managed with a variable (AREACONV) that can be changed with the
  14. command of the same name.
  15. The display the number of decimal is managed by a variable too (AREAPREC)
  16. |;
  17. ;;;===============================================;;;
  18. (vl-load-com)
  19. (or *acdoc*
  20.     (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  21. )
  22. ;;; AREABOX (gile)
  23. ;;; Dialog Box for commands calling
  24. (defun c:Areabox (/ tmp file what_next dcl_id result)
  25.   (or (getenv "AreaConv") (setenv "AreaConv" "1"))
  26.   (or (getenv "AreaPrec")
  27.       (setenv "AreaPrec" (itoa (getvar "LUPREC")))
  28.   )
  29.   (setq tmp  (vl-filename-mktemp "Tmp.dcl")
  30. file (open tmp "w")
  31.   )
  32.   (write-line
  33.     "AreaBox:dialog{label="总面积";
  34.     :boxed_column{label="命令";:row{
  35.     :button{label="总面积";key="(c:totalarea)";width=16;}
  36.     spacer;:text{label="插入并连接";width= 20;}}
  37.     :row{
  38.     :button{label="面积编辑";key="(c:areaedit)";width=16;}
  39.     spacer;:text{label="增加或移除链接";width= 20;}}
  40.     :row{
  41.     :button{label="面积显示";key="(c:areashow)";width=16;}
  42.     spacer;:text{label="显示链接对象";width= 20;}}}
  43.     :boxed_column{label="系统变量";:row{
  44.     :text{key="ConvValue";width= 20;}
  45.     :button{label="AreaConv";key="areaconv";width=16;}}
  46.     :row{:text{key="PrecValue";width= 20;}
  47.     :button{label="AreaPrec";key="areaprec";width=16;}}}
  48.     spacer;cancel_button;}"
  49.     file
  50.   )
  51.   (close file)
  52.   (setq dcl_id (load_dialog tmp))
  53.   (setq what_next 2)
  54.   (while (>= what_next 2)
  55.     (if (not (new_dialog "AreaBox" dcl_id))
  56.       (exit)
  57.     )
  58.     (set_tile "ConvValue"
  59.        (strcat "AREACONV = " (getenv "AreaConv"))
  60.     )
  61.     (set_tile "PrecValue"
  62.        (strcat "AREAPREC = " (getenv "AreaPrec"))
  63.     )
  64.     (foreach k '("(c:totalarea)"
  65.    "(c:areaedit)"
  66.    "(c:areashow)"
  67.   )
  68.       (action_tile k "(setq result $key) (done_dialog)")
  69.     )
  70.     (action_tile "areaconv" "(done_dialog 3)")
  71.     (action_tile "areaprec" "(done_dialog 4)")
  72.     (action_tile "cancel" "(done_dialog 0)")
  73.     (setq what_next (start_dialog))
  74.     (cond
  75.       ((= what_next 3) (c:areaconv))
  76.       ((= what_next 4) (c:areaprec))
  77.     )
  78.   )
  79.   (unload_dialog dcl_id)
  80.   (vl-file-delete tmp)
  81.   (and result (eval (read result)))
  82.   (princ)
  83. )
  84. ;;;===============================================;;;
  85. ;; TotalAreaBox
  86. ;; TotalArea command dialog box
  87. (defun TotalAreaBox (/      lbl     unt     scl     lay     lst
  88.        tmp     file    what_next      dcl_id  data
  89.        result
  90.       )
  91.   (or (getenv "AreaConv") (setenv "AreaConv" "1"))
  92.   (or (getenv "AreaPrec")
  93.       (setenv "AreaPrec" (itoa (getvar "LUPREC")))
  94.   )
  95.   (or (setq lbl (vlax-ldata-get "TotalArea" "lbl"))
  96.       (setq lbl (vlax-ldata-put "TotalArea" "lbl" "Total area"))
  97.   )
  98.   (or (setq unt (vlax-ldata-get "TotalArea" "unt"))
  99.       (setq unt (vlax-ldata-put "TotalArea" "unt" "m"))
  100.   )
  101.   (or (setq scl (vlax-ldata-get "TotalArea" "scl"))
  102.       (setq scl (vlax-ldata-put "TotalArea" "scl" 1))
  103.   )
  104.   (while (setq lay (tblnext "LAYER" (not lay)))
  105.     (setq lst (cons (cdr (assoc 2 lay)) lst))
  106.   )
  107.   (setq lst (vl-sort lst '<))
  108.   (setq lay (getvar "CLAYER"))
  109.   (setq tmp  (vl-filename-mktemp "Tmp.dcl")
  110. file (open tmp "w")
  111.   )
  112.   (write-line
  113.     "AreaBox:dialog{label="总面积";
  114.     :boxed_column{label="属性";
  115.     :row{:text{label="Label";}
  116.     :edit_box{key="lbl";width=24;}}
  117.     :row{:text{label="单位";}
  118.     :edit_box{key="unt";fixed_width=true;}}}
  119.     :boxed_column{label="属性";
  120.     :row{:text{label="比例";}
  121.     :edit_box{key="scl";fixed_width=true;}}
  122.     :popup_list{label="图层";key="lay";}}
  123.     :boxed_column{label="变量";:row{
  124.     :text{key="ConvValue";width= 20;}
  125.     :button{label="AreaConv";key="areaconv";width=16;}}
  126.     :row{:text{key="PrecValue";width= 20;}
  127.     :button{label="AreaPrec";key="areaprec";width=16;}}}
  128.     spacer;ok_cancel_help;}"
  129.     file
  130.   )
  131.   (close file)
  132.   (setq dcl_id (load_dialog tmp))
  133.   (setq what_next 2)
  134.   (while (>= what_next 2)
  135.     (if (not (new_dialog "AreaBox" dcl_id))
  136.       (exit)
  137.     )
  138.     (start_list "lay")
  139.     (mapcar 'add_list lst)
  140.     (end_list)
  141.     (set_tile "lbl" lbl)
  142.     (set_tile "unt" unt)
  143.     (set_tile "scl" (rtos scl))
  144.     (set_tile "lay" (itoa (vl-position lay lst)))
  145.     (set_tile "ConvValue"
  146.        (strcat "AREACONV = " (getenv "AreaConv"))
  147.     )
  148.     (set_tile "PrecValue"
  149.        (strcat "AREAPREC = " (getenv "AreaPrec"))
  150.     )
  151.     (action_tile "lbl" "(setq lbl $value)")
  152.     (action_tile "unt" "(setq unt $value)")
  153.     (action_tile
  154.       "scl"
  155.       "(if (< 0 (distof $value))
  156. (setq scl (distof $value))
  157. (progn (alert "Needs a valid scale.")
  158.    (setq scl (vlax-ldata-get "TotalArea" "scl"))
  159.    (set_tile "scl" (rtos scl))
  160.    (mode_tile "scl" 2)))"
  161.     )
  162.     (action_tile "lay" "(setq lay (nth (atoi $value) lst))")
  163.     (action_tile "areaconv" "(done_dialog 3)")
  164.     (action_tile "areaprec" "(done_dialog 4)")
  165.     (action_tile "help" "(done_dialog 5)")
  166.     (action_tile "cancel" "(done_dialog 0)")
  167.     (action_tile
  168.       "accept"
  169.       "(setq result (list lbl unt scl lay))
  170.       (vlax-ldata-put "TotalArea" "lbl" lbl)
  171.       (vlax-ldata-put "TotalArea" "unt" unt)
  172.       (vlax-ldata-put "TotalArea" "scl" scl)
  173.       (done_dialog 1)"
  174.     )
  175.     (setq what_next (start_dialog))
  176.     (cond
  177.       ((= what_next 3) (c:areaconv))
  178.       ((= what_next 4) (c:areaprec))
  179.       ((= what_next 5) (help "TotalArea"))
  180.     )
  181.   )
  182.   (unload_dialog dcl_id)
  183.   (vl-file-delete tmp)
  184.   result
  185. )
  186. ;;;===============================================;;;
  187. ;;; TOTALAREA (gile)
  188. ;;; Insert "TotalArea" block which "AREA" attribute value equals to
  189. ;;; the sum of selected objects areas
  190. (defun c:TotalArea (/ *error* space dz bloc tot ss lst ins scl blk)
  191.   (defun *error* (msg)
  192.     (or (= msg "Function cancelled")
  193. (princ (strcat "\Error: " msg))
  194.     )
  195.     (setvar "DIMZIN" dz)
  196.     (vla-EndUndoMark *acdoc*)
  197.     (princ)
  198.   )
  199.   (setq Space (if (= (getvar "CVPORT") 1)
  200.   (vla-get-PaperSpace *acdoc*)
  201.   (vla-get-ModelSpace *acdoc*)
  202.        )
  203. dz    (getvar "DIMZIN")
  204.   )
  205.   (if (or
  206. (gc:GetItem
  207.    (vla-get-Blocks *acdoc*)
  208.    (setq bloc "TotalArea")
  209. )
  210. (findfile (setq bloc "TotalArea.dwg"))
  211.       )
  212.     (if (setq data (TotalAreaBox))
  213.       (if
  214. (ssget
  215.    '((-4 . "<OR")
  216.      (0 . "ARC,CIRCLE,ELLIPSE,LWPOLYLINE,HATCH,MPOLYGON,REGION")
  217.      (-4 . "<AND")
  218.      (0 . "POLYLINE")
  219.      (-4 . "<NOT")
  220.      (-4 . "&")
  221.      (70 . 120)
  222.      (-4 . "NOT>")
  223.      (-4 . "AND>")
  224.      (-4 . "<AND")
  225.      (0 . "SPLINE")
  226.      (-4 . "&")
  227.      (70 . 8)
  228.      (-4 . "AND>")
  229.      (-4 . "OR>")
  230.     )
  231. )
  232.   (progn
  233.     (setq tot 0.0)
  234.     (vla-StartUndoMark *acdoc*)
  235.     (vlax-for obj (setq ss (vla-get-ActiveSelectionset *acdoc*))
  236.       (setq tot (+ tot (vla-get-Area obj))
  237.      lst (cons obj lst)
  238.       )
  239.     )
  240.     (vla-delete ss)
  241.     (initget 1)
  242.     (setq ins (getpoint "\nSpecify insertion point: ")
  243.    scl (caddr data)
  244.    blk
  245.        (vla-insertBlock
  246.          Space
  247.          (vlax-3d-point (trans ins 1 0))
  248.          bloc
  249.          scl
  250.          scl
  251.          scl
  252.          0.0
  253.        )
  254.     )
  255.     (vla-put-layer blk (cadddr data))
  256.     (setvar "DIMZIN" (Boole 2 (getvar "DIMZIN") 8))
  257.     (foreach att (vlax-invoke blk 'GetAttributes)
  258.       (cond
  259.         ((= (vla-get-TagString att) "LABEL")
  260.   (vla-put-TextString att (car data))
  261.         )
  262.         ((= (vla-get-TagString att) "UNIT")
  263.   (vla-put-TextString att (cadr data))
  264.         )
  265.         ((= (vla-get-TagString att) "AREA")
  266.   (vla-put-Textstring
  267.     att
  268.     (rtos (/ tot (distof (getenv "areaConv")))
  269.    2
  270.    (atoi (getenv "AreaPrec"))
  271.     )
  272.   )
  273.         )
  274.         ((= (vla-get-TagString att) "NOBJ")
  275.   (vla-put-TextString att (itoa (length lst)))
  276.         )
  277.       )
  278.     )
  279.     (vlax-ldata-put
  280.       blk
  281.       "TotalArea"
  282.       (mapcar 'vla-get-Handle lst)
  283.     )
  284.     (setvar "DIMZIN" dz)
  285.     ;;------------------------------------------------------------------;;
  286.     ;; Creating reactor
  287.     (foreach obj lst
  288.       (vlr-object-reactor
  289.         (list obj)
  290.         (vla-get-Handle blk)
  291.         '((:vlr-erased . GC:AREAOBJECTERASED)
  292.    (:vlr-unerased . GC:AREAOBJECTUNERASED)
  293.    (:vlr-objectClosed . GC:AREAOBJECTCLOSED)
  294.   )
  295.       )
  296.     )
  297.     ;;------------------------------------------------------------------;;
  298.     (vla-EndUndoMark *acdoc*)
  299.   )
  300.       )
  301.     )
  302.     (princ "\n"TotalArea" block can't be found.")
  303.   )
  304.   (princ)
  305. )
  306. ;;------------------------------------------------------------------;;
  307. ;;; AREAEDIT (gile)
  308. ;;; Add or remove links to "TotalArea" block
  309. (defun c:AreaEdit (/ *error* lst blk obj elst rea)
  310.   (defun *error* (msg)
  311.     (or (= msg "Function cancelled")
  312. (princ (strcat "\Error: " msg))
  313.     )
  314.     (mapcar (function (lambda (x) (vla-highlight x :vlax-false)))
  315.      lst
  316.     )
  317.     (vla-EndUndoMark *acdoc*)
  318.     (princ)
  319.   )
  320.   (sssetfirst nil nil)
  321.   (if (setq lst (gc:AreaGet "\nSelect the block to edit: "))
  322.     (progn
  323.       (setq blk (car lst)
  324.      lst (cadr lst)
  325.       )
  326.       (vla-StartUndoMark *acdoc*)
  327.       (while (setq obj
  328.       (car
  329.         (entsel
  330.    "\nSelect an object to add or remove: "
  331.         )
  332.       )
  333.       )
  334. (setq elst (entget obj))
  335. (if (or
  336.        (member (cdr (assoc 0 elst))
  337.         '("ARC"       "CIRCLE"     "ELLIPSE"
  338.    "LWPOLYLINE"  "HATCH"     "MPOLYGON"
  339.    "REGION"
  340.          )
  341.        )
  342.        (and (= (cdr (assoc 0 elst)) "POLYLINE")
  343.      (zerop (logand 120 (cdr (assoc 70 elst))))
  344.        )
  345.        (and (= (cdr (assoc 0 elst)) "SPLINE")
  346.      (= 8 (logand 8 (cdr (assoc 70 elst))))
  347.        )
  348.      )
  349.    (if (member (setq obj (vlax-ename->vla-object obj)) lst)
  350.      (progn
  351.        (setq lst (vl-remove obj lst))
  352.        (vla-highlight obj :vlax-false)
  353.        (if (setq rea (gc:GetAreaObjectReactor obj blk))
  354.   (vlr-remove rea)
  355.        )
  356.      )
  357.      (progn
  358.        (setq lst (cons obj lst))
  359.        (vla-highlight obj :vlax-true)
  360.        (vlr-object-reactor
  361.   (list obj)
  362.   (vla-get-Handle blk)
  363.   '((:vlr-erased . GC:AREAOBJECTERASED)
  364.     (:vlr-unerased . GC:AREAOBJECTUNERASED)
  365.     (:vlr-objectClosed . GC:AREAOBJECTCLOSED)
  366.    )
  367.        )
  368.      )
  369.    )
  370. )
  371. (gc:TotalAreaUpd blk lst)
  372.       )
  373.       (mapcar (function (lambda (x) (vla-highlight x :vlax-false)))
  374.        lst
  375.       )
  376.       (vla-EndUndoMark *acdoc*)
  377.     )
  378.   )
  379.   (princ)
  380. )
  381. ;;;===============================================;;;
  382. ;;; AREASHOW (gile)
  383. ;;; Highlight the linked objects to the block the cursor is on
  384. (defun c:AreaShow (/ blk lst)
  385.   (and (setq lst (gc:AreaGet ""))
  386.        (mapcar (function (lambda (x) (vla-highlight x :vlax-false)))
  387.         (cadr lst)
  388.        )
  389.   )
  390.   (princ)
  391. )
  392. ;;;===============================================;;;
  393. ;;; AREACONV (gile)
  394. ;;; Edit AREACONV sysvar value
  395. ;;; This sysvar is registered and manages the area unit conversion factor
  396. ;;; example : 10000 for cm?-> m? 1000000 (or 1e6) for m?-> km?
  397. (defun c:AreaConv ()
  398.   (or (getenv "AreaConv") (setenv "AreaConv" "1"))
  399.   (while
  400.     (not
  401.       ((lambda (r)
  402.   (or (= r "")
  403.       (< 0 (distof r))
  404.   )
  405.        )
  406. (setq
  407.    r (getstring
  408.        (strcat "\nEnter a new value for AREACONV <"
  409.         (getenv "AreaConv")
  410.         ">: "
  411.        )
  412.      )
  413. )
  414.       )
  415.     )
  416.      (princ "\nNeeds a strictly positive number")
  417.   )
  418.   (or (= r "") (setenv "AreaConv" r))
  419.   (princ)
  420. )
  421. ;;;===============================================;;;
  422. ;;; AREAPREC (gile)
  423. ;;; Edit AREACONV sysvar value
  424. ;;; This registered sysvar manages the number of decimal displayed
  425. (defun c:AreaPrec ()
  426.   (or (getenv "AreaPrec")
  427.       (setenv "AreaPrec" (itoa (getvar "LUPREC")))
  428.   )
  429.   (while
  430.     (not
  431.       ((lambda (r)
  432.   (or (= r "")
  433.       (and
  434.         (= 'INT (type (read r)))
  435.         (<= 0 (atoi r))
  436.       )
  437.   )
  438.        )
  439. (setq
  440.    r (getstring
  441.        (strcat "\nEnter a new value for AREAPREC <"
  442.         (getenv "AreaPrec")
  443.         ">: "
  444.        )
  445.      )
  446. )
  447.       )
  448.     )
  449.      (princ "\nNeeds a strictly positive number")
  450.   )
  451.   (or (= r "") (setenv "AreaPrec" r))
  452.   (princ)
  453. )
  454. ;;;================== SUB ROUTINES ==================;;;
  455. ;;; gc:TotalAreaUpd (gile)
  456. ;;; Update of a "TotalArea" block attributes
  457. (defun gc:TotalAreaUpd (blk lst / *error* dz hand tot pl new)
  458.   (vl-load-com)
  459.   (defun *error* (msg)
  460.     (or (= msg "Function cancelled")
  461. (princ (strcat "\Error: " msg))
  462.     )
  463.     (setvar "DIMZIN" dz)
  464.     (princ)
  465.   )
  466. (setq dz (getvar "DIMZIN"))
  467.   (setvar "DIMZIN" (Boole 2 (getvar "DIMZIN") 8))
  468.   (if lst
  469.     (progn
  470.       (setq tot 0.0)
  471.       (foreach obj lst
  472. (if obj
  473.    (setq tot (+ tot (vla-get-Area obj))
  474.   new (cons (vla-get-Handle obj) new)
  475.    )
  476. )
  477.       )
  478.       (foreach att (vlax-invoke blk 'GetAttributes)
  479. (cond
  480.    ((= (vla-get-TagString att) "AREA")
  481.     (vla-put-Textstring
  482.       att
  483.       (rtos (/ tot (distof (getenv "areaConv")))
  484.      2
  485.      (atoi (getenv "AreaPrec"))
  486.       )
  487.     )
  488.    )
  489.    ((= (vla-get-TagString att) "NOBJ")
  490.     (vla-put-TextString att (itoa (length new)))
  491.    )
  492. )
  493.       )
  494.     )
  495.     (foreach att (vlax-invoke blk 'GetAttributes)
  496.       (cond
  497. ((= (vla-get-TagString att) "AREA")
  498.   (vla-put-Textstring
  499.     att
  500.     (rtos 0.0 2 (atoi (getenv "AreaPrec")))
  501.   )
  502. )
  503. ((= (vla-get-TagString att) "NOBJ")
  504.   (vla-put-TextString att "0")
  505. )
  506.       )
  507.     )
  508.   )
  509.   (setvar "DIMZIN" dz)
  510. )
  511. ;;;===============================================;;;
  512. ;;; gc:AreaGet (gile)
  513. ;;; Returns a list which countains a "TotalArea" block and all linked objects
  514. ;;; Linked objects are highlighted while the cursor is on the block
  515. (defun gc:AreaGet (msg / ss l1 gr ent l2 l3)
  516.   
  517.   (defun *error* (msg)
  518.     (or (= msg "Function cancelled")
  519. (princ (strcat "\nError: " msg))
  520.     )
  521.     (mapcar (function (lambda (x) (vla-highlight x :vlax-false)))
  522.      l2
  523.     )
  524.     (princ)
  525.   )
  526.   
  527.   (princ msg)
  528.   (while (and (setq gr (grread T 4 2)) (= (car gr) 5))
  529.     (if (and (setq ent (nentselp (cadr gr)))
  530.       (or
  531.         (and
  532.    (caddr ent)
  533.    (setq ent (last (last ent)))
  534.         )
  535.         (setq ent (cdr (assoc 330 (entget (car ent)))))
  536.       )
  537. )
  538.       (if (= (cdr (assoc 2 (entget ent))) "TotalArea")
  539. (progn
  540.    (setq blk T
  541.   l1  (vlax-ldata-get ent "TotalArea")
  542.    )
  543.    (foreach h l1
  544.      (if (setq obj (gc:HandleToObject h))
  545.        (progn
  546.   (vla-highlight obj :vlax-true)
  547.   (or (member obj l2) (setq l2 (cons obj l2)))
  548.        )
  549.      )
  550.    )
  551. )
  552.       )
  553.       (progn
  554. (mapcar (function (lambda (x) (vla-highlight x :vlax-false)))
  555.   l2
  556. )
  557. (setq l2  nil
  558.        blk nil
  559. )
  560.       )
  561.     )
  562.   )
  563.   (if (and (= (car gr) 3) l2)
  564.     (list (vlax-ename->vla-object ent) l2)
  565.     (mapcar (function (lambda (x) (vla-highlight x :vlax-false)))
  566.      l2
  567.     )
  568.   )
  569. )
  570. ;;;===============================================;;;
  571. ;;; gc:AreaUpdAll
  572. ;;; Updates all "ToTalArea" block references
  573. (defun gc:AreaUpdAll (/ ss)
  574.   (if (ssget "_X" '((0 . "INSERT") (2 . "TotalArea")))
  575.     (progn
  576.       (vlax-for blk (setq ss (vla-get-activeSelectionSet *acdoc*))
  577. (gc:TotalAreaUpd
  578.    blk
  579.    (mapcar 'gc:HandleToObject
  580.     (vlax-ldata-get blk "TotalArea")
  581.    )
  582. )
  583.       )
  584.       (vla-delete ss)
  585.     )
  586.   )
  587. )
  588. ;;;===============================================;;;
  589. ;;; gc:GetAreaObjectReactor
  590. ;;; Returns the reactor linked to the object
  591. ;;; Arguments
  592. ;;; obj : owner object (vla-object)
  593. ;;; blk : the block linked to object (vla-object)
  594. ;;;
  595. ;;; Retour : the reactor or nil
  596. (defun gc:GetAreaObjectReactor (obj blk / lst rea loop)
  597.   (setq lst  (cdr (assoc :VLR-Object-Reactor (vlr-reactors)))
  598. loop T
  599.   )
  600.   (while (and lst loop)
  601.     (setq rea (car lst)
  602.    lst (cdr lst)
  603.     )
  604.     (if (and
  605.    (equal (vlr-owners rea) (list obj))
  606.    (= (vlr-data rea) (vla-get-Handle blk))
  607. )
  608.       (setq loop nil)
  609.       (setq rea nil)
  610.     )
  611.   )
  612.   rea
  613. )
  614. ;;;===============================================;;;
  615. ;;; gc:GetItem (gile)
  616. ;;; Returns a vla-object if item exists in the collection
  617. ;;;
  618. ;;; Arguments
  619. ;;; col : the collection (vla-object)
  620. ;;; name : the item name (string) or its index (integer)
  621. ;;;
  622. ;;; Return : the vla-object or nil
  623. (defun gc:GetItem (col name / obj)
  624.   (vl-catch-all-apply
  625.     (function (lambda () (setq obj (vla-item col name))))
  626.   )
  627.   obj
  628. )
  629. ;;;===============================================;;;
  630. ;; gc:HandleToObject (gile)
  631. ;; Returns the VLA-OBJECT about its handle
  632. ;;; Argument
  633. ;;; handle : the object handle
  634. ;;;
  635. ;;; Return : the vla-object or nil
  636. (defun gc:HandleToObject (handle / obj)
  637.   (vl-catch-all-apply
  638.     (function
  639.       (lambda ()
  640. (setq obj (vla-HandleToObject
  641.       (vla-get-ActiveDocument (vlax-get-acad-object))
  642.       handle
  643.     )
  644. )
  645.       )
  646.     )
  647.   )
  648.   obj
  649. )
  650. ;;;================== CALLBACKS ==================;;;
  651. (defun GC:AREAOBJECTERASED (own rea lst)
  652.   (vlr-remove rea)
  653. )
  654. ;;;===============================================;;;
  655. (defun GC:AREAOBJECTUNERASED (own rea lst)
  656.   (if (setq blk (gc:HandleToObject (vlr-data rea)))
  657.     (vlr-add rea)
  658.     (vlr-remove rea)
  659.   )
  660. )
  661. ;;;===============================================;;;
  662. (defun GC:AREAOBJECTCLOSED (own rea lst / blk data)
  663.   (if (setq blk (gc:HandleToObject (vlr-data rea)))
  664.     (if (setq data (vlax-ldata-get blk "TotalArea"))
  665.       (gc:TotalAreaUpd blk (mapcar 'gc:HandleToObject data))
  666.     )
  667.     (vlr-remove rea)
  668.   )
  669. )
  670. ;;;==================== CREATING REACTORS WHILE LOADING ====================;;;
  671. ((lambda (/ ss obj)
  672.    (foreach r (cdr (assoc :VLR-Object-Reactor (vlr-reactors)))
  673.      (if (member '(:VLR-erased . GC:AREAOBJECTERASED)
  674.    (vlr-reactions r)
  675.   )
  676.        (vlr-remove r)
  677.      )
  678.    )
  679.    (if (ssget "_X" '((0 . "INSERT") (2 . "TotalArea")))
  680.      (progn
  681.        (vlax-for blk (setq ss (vla-get-ActiveSelectionSet *acdoc*))
  682.   (foreach hand (vlax-ldata-get blk "TotalArea")
  683.     (if (setq obj (gc:HandleToObject hand))
  684.       (vlr-object-reactor
  685.         (list obj)
  686.         (vla-get-Handle blk)
  687.         '((:vlr-erased . GC:AREAOBJECTERASED)
  688.    (:vlr-unerased . GC:AREAOBJECTUNERASED)
  689.    (:vlr-objectClosed . GC:AREAOBJECTCLOSED)
  690.   )
  691.       )
  692.     )
  693.   )
  694.        )
  695.        (vla-delete ss)
  696.      )
  697.    )
  698. )
  699. )
  700. (princ)
发表于 2009-12-18 21:26 | 显示全部楼层

本帖子中包含更多资源

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

x
发表于 2009-12-19 14:05 | 显示全部楼层

好像很高级的样子,如何用呢??代码下载下来后用不了

发表于 2009-12-19 14:50 | 显示全部楼层

使用方法:

1:打开一个图形制作一个块,该块含有"LABEL", "UNIT "AREA" 以及"NOBJ"提示的属性。然后将该图形保存到cad支持路径下;

2:另打开一个图形,加载该程序,在命令行输入命令TotalArea;

3:在弹出对话框后,输入所选对象的标签(LABEL),确定;

4:选择要计算的对象,在点取数据要放置的位置;

5:同4,计算其他对象的面积;

6:如果选择所有的对象,将计算总面积;

7:完成后,修改任何一个对象,面积数据也会发生变化。

发表于 2009-12-19 15:10 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-12-19 15:29 | 显示全部楼层

本帖子中包含更多资源

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

x
发表于 2009-12-19 15:32 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-12-19 15:39 | 显示全部楼层
反应器的目的在当前计算时是不起作用的,只有在计算完成后,某个对象要进行修改或变动时才起作用。不知你能明白吗?
发表于 2009-12-19 15:43 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-17 20:26 , Processed in 0.191908 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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