乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 32|回复: 10

[编程交流] 我的一些lisp编码。。。

[复制链接]

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 11:52:15 | 显示全部楼层 |阅读模式
这里,将是我的一些autolisp/vital lisp/visual lisp/dcl。。。
 
希望这仍然会有一些用处,关于lisp我失去了练习,现在不再用lisp写了。
 
REDODIM公司
选择一个分解尺寸,它将被重新完成,这是为了学习如何重新创建分解尺寸。
 
  1. (vl-load-com)
  2. (defun sslist  (ss / n lst)
  3. (if (= (type ss) 'pickset)
  4.    (repeat (setq n (ssLength ss))
  5.      (setq n (1- n)
  6.     lst (cons (ssname ss n) lst)))))
  7. (defun coolineal  (p1 p2 ptchk / ang ang1 absang fuzz)
  8. (setq fuzz 0.00001)
  9. (if (or (equal p1 ptchk fuzz) (equal p2 ptchk fuzz))
  10.    (setq retval t)
  11.    (progn
  12.      (setq ang    (angle p1 ptchk)
  13.     ang1   (angle p1 p2)
  14.     absang (abs (- ang ang1)))
  15.      (if (or (equal absang 0.0 fuzz)
  16.       (equal absang pi fuzz)
  17.       (equal absang (* pi 2) fuzz))
  18. t
  19. nil))))
  20. (defun lincool (l1 l2 / p1 p2 p3 p4)
  21. (setq p1 (cdr (assoc 10 (entget l1)))
  22. p2 (cdr (assoc 11 (entget l1)))
  23. p3 (cdr (assoc 10 (entget l2)))
  24. p4 (cdr (assoc 11 (entget l2))))
  25. (if (and (coolineal p1 p2 p3) (coolineal p1 p2 p4))
  26.    t))
  27. (if (not thisdwg)
  28. (setq thisdwg (vla-get-activedocument (vlax-get-acad-object))))
  29. (if (not modelspace)
  30. (setq modelspace
  31. (vla-get-modelspace thisdwg)))
  32. (defun paperspace () (vla-get-paperspace thisdwg))
  33. (defun rcmd-get-activespace  ()
  34. (if (= acmodelspace (vla-get-activespace thisdwg))
  35.    modelspace
  36.    (if (= (vla-get-mspace thisdwg) :vlax-true)
  37.      modelspace
  38.      (paperspace))))
  39. (defun adddimrotated
  40.        (xline1point xline2point dimlinelocation rotationangle / vla_dim)
  41. (if (not (vl-catch-all-error-p
  42.      (setq vla_dim
  43.      (vl-catch-all-apply
  44.        'vla-adddimrotated
  45.        (list (rcmd-get-activespace)
  46.       (vlax-3d-point xline1point)
  47.       (vlax-3d-point xline2point)
  48.       (vlax-3d-point dimlinelocation)
  49.       rotationangle)))))
  50.    vla_dim))
  51. (defun arrowhead-blk  (bname)
  52. (cond
  53.    ((= bname "_DOT")
  54.     acArrowDot)
  55.    ((= bname "_DOTSMALL")
  56.     acArrowDotSmall)
  57.    ((= bname "_DOTBLANK")
  58.     acArrowDotBlank)
  59.    ((= bname "_ORIGIN")
  60.     acArrowOrigin)
  61.    ((= bname "_ORIGIN2")
  62.     acArrowOrigin2)
  63.    ((= bname "_OPEN")
  64.     acArrowOpen)
  65.    ((= bname "_OPEN90")
  66.     acArrowOpen90)
  67.    ((= bname "_OPEN30")
  68.     acArrowOpen30)
  69.    ((= bname "_CLOSED")
  70.     acArrowClosed)
  71.    ((= bname "_SMALL")
  72.     acArrowSmall)
  73.    ((= bname "_NONE")
  74.     acArrowNone)
  75.    ((= bname "_OBLIQUE")
  76.     acArrowOblique)
  77.    ((= bname "_BOXFILLED")
  78.     acArrowBoxFilled)
  79.    ((= bname "_BOXBLANK")
  80.     acArrowBoxBlank)
  81.    ((= bname "_CLOSEDBLANK")
  82.     acArrowClosedBlank)
  83.    ((= bname "_DATUMFILLED")
  84.     acArrowDatumFilled)
  85.    ((= bname "_DATUMBLANK")
  86.     acArrowDatumBlank)
  87.    ((= bname "_INTEGRAL")
  88.     acArrowIntegral)
  89.    ((= bname "_ARCHTICK")
  90.     acArrowArchTick)))
  91. (defun C:REDODIM  (/ ss lst lst_lines lst_blocks lst_solids ints int1 int2 int3 line1 line2
  92.     line3 lst3)
  93. (if (setq ss (ssget))
  94.    (progn
  95.      (setq lst       (sslist ss)
  96.     lst_lines
  97.        (vl-remove-if-not
  98.   (function (lambda (ent) (eq (cdadr (entget ent)) "LINE")))
  99.   lst))
  100.      (if (not
  101.     (setq lst_blocks
  102.     (vl-remove-if-not
  103.       (function
  104.         (lambda (ent) (eq (cdadr (entget ent)) "INSERT")))
  105.       lst)))
  106. (setq lst_solids
  107.        (vl-remove-if-not
  108.   (function
  109.     (lambda (ent) (eq (cdadr (entget ent)) "SOLID")))
  110.   lst)))
  111.      (setq l_a     lst_lines
  112.     L_a2    l_a
  113.     lTemp   T
  114.     lTot    nil
  115.     lst_not
  116.      nil
  117.     par     nil)
  118.      (while l_a2
  119. (setq EntChk (car l_a2)
  120.       l_a2   (cdr l_a2))
  121. (setq list_T-nil
  122.        (mapcar (function (lambda (x) (lincool x EntChk))) l_a2))
  123. (setq lTemp (vl-remove-if
  124.        'not
  125.        (mapcar (function
  126.    (lambda (x y)
  127.      (if (and x y)
  128.        y)))
  129.         list_T-nil
  130.         l_a2)))
  131. (foreach j lTemp (setq l_a2 (vl-remove j l_a2)))
  132. (setq lTemp (cons EntChk lTemp))
  133. (if (and lTemp (> (length lTemp) 1))
  134.   (setq lTot (cons lTemp lTot))
  135.   (setq lst_not (cons ltemp lst_not))))
  136.      (setq tmp nil)
  137.      (if (and (not ltot) lst_not (= (length lst_not) 3))
  138. (progn
  139.   (setq lst3  (apply 'append lst_not)
  140. line1 (car lst3)
  141. line2 (cadr lst3)
  142. line3 (caddr lst3)
  143. p1    (cdr (assoc 10 (entget line1)))
  144. p2    (cdr (assoc 11 (entget line1)))
  145. p3    (cdr (assoc 10 (entget line2)))
  146. p4    (cdr (assoc 11 (entget line2)))
  147. p5    (cdr (assoc 10 (entget line3)))
  148. p6    (cdr (assoc 11 (entget line3)))
  149. int1  (inters p1 p2 p3 p4 nil)
  150. int2  (inters p3 p4 p5 p6 nil)
  151. int3  (inters p1 p2 p5 p6 nil)
  152. ints  (vl-remove nil (list int1 int2 int3))
  153. a     (car ints)
  154. b     (cadr ints)
  155. flag  (if lst_blocks
  156.   "insert"
  157.   "solid"))
  158.   (cond
  159.     ((= flag "solid")
  160.      (setq solid1  (car lst_solids)
  161.     elst    (entget solid1)
  162.     p1    (cdr (assoc 10 elst))
  163.     p2    (cdr (assoc 11 elst))
  164.     p3    (cdr (assoc 12 elst))
  165.     solid2  (cadr lst_solids)
  166.     elst    (entget solid2)
  167.     p1    (cdr (assoc 10 elst))
  168.     p2    (cdr (assoc 11 elst))
  169.     p4    (cdr (assoc 12 elst))
  170.     c    p3
  171.     dim_obj
  172.      (adddimrotated a b c (angle p3 p4)))
  173.      (vla-put-arrowhead1type dim_obj acarrowdefault)
  174.      (vla-put-arrowhead2type dim_obj acarrowdefault))
  175.     ((= flag "insert")
  176.      (setq block1  (car lst_blocks)
  177.     elst    (entget block1)
  178.     bname   (cdr (assoc 2 (entget block1)))
  179.     p3    (cdr (assoc 10 (entget block1)))
  180.     block2  (cadr lst_blocks)
  181.     elst    (entget block2)
  182.     p4    (cdr (assoc 10 (entget block2)))
  183.     c    p3
  184.     dim_obj
  185.      (adddimrotated a b c (angle p3 p4)))
  186.      (vla-put-arrowhead1type
  187.        dim_obj
  188.        (arrowhead-blk (strcase bname)))
  189.      (vla-put-arrowhead2type
  190.        dim_obj
  191.        (arrowhead-blk (strcase bname)))))))
  192.      (if ltot
  193. (progn
  194.   (setq i 0)
  195.   (repeat (length (setq par (car ltot)))
  196.     (setq ename (nth i par)
  197.    tmp (cons (cdr (assoc 10 (entget ename))) tmp)
  198.    tmp (cons (cdr (assoc 11 (entget ename))) tmp)
  199.    i (1+ i)))
  200.   (setq flag (if lst_blocks
  201.         "insert"
  202.         "solid"))
  203.   (cond
  204.     ((= flag "solid")
  205.      (setq solid1  (car lst_solids)
  206.     elst    (entget solid1)
  207.     p1    (cdr (assoc 10 elst))
  208.     p2    (cdr (assoc 11 elst))
  209.     p3    (cdr (assoc 12 elst))
  210.     solid2  (cadr lst_solids)
  211.     elst    (entget solid2)
  212.     p1    (cdr (assoc 10 elst))
  213.     p2    (cdr (assoc 11 elst))
  214.     p4    (cdr (assoc 12 elst))
  215.     par    (apply 'append lst_not)
  216.     a    (cdr (assoc 10 (entget (car par))))
  217.     b    (cdr (assoc 10 (entget (cadr par))))
  218.     c    p3
  219.     dim_obj
  220.      (adddimrotated a b c (angle p3 p4)))
  221.      (vla-put-arrowhead1type dim_obj acarrowdefault)
  222.      (vla-put-arrowhead2type dim_obj acarrowdefault))
  223.     ((= flag "insert")
  224.      (setq block1  (car lst_blocks)
  225.     elst    (entget block1)
  226.     bname   (cdr (assoc 2 (entget block1)))
  227.     p3    (cdr (assoc 10 (entget block1)))
  228.     block2  (cadr lst_blocks)
  229.     elst    (entget block2)
  230.     p4    (cdr (assoc 10 (entget block2)))
  231.     par    (apply 'append lst_not)
  232.     a    (cdr (assoc 10 (entget (car par))))
  233.     b    (cdr (assoc 10 (entget (cadr par))))
  234.     c    p3
  235.     dim_obj
  236.      (adddimrotated a b c (angle p3 p4)))
  237.      (vla-put-arrowhead1type
  238.        dim_obj
  239.        (arrowhead-blk (strcase bname)))
  240.      (vla-put-arrowhead2type
  241.        dim_obj
  242.        (arrowhead-blk (strcase bname)))))))
  243.      (if dim_obj
  244. (mapcar 'entdel lst))))
  245. (princ))
  246. (princ)
回复

使用道具 举报

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:03:48 | 显示全部楼层
MTLSTAIR公司
按照UBC代码绘制金属楼梯的楼层平面和剖面。
 
包含了当时最丑陋的源代码,但很有帮助——在zip文件中,我写了这个例程,当时我在一个高层项目(32层楼的酒店)上工作,负责所有楼梯的分析。
125218fraqdb7xzxdrz273.png
mtlstair。拉链
回复

使用道具 举报

10

主题

8258

帖子

8335

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 12:09:24 | 显示全部楼层
感谢您与我们分享您的日常活动。
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 12:14:39 | 显示全部楼层
 
谢谢你,李,
回复

使用道具 举报

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:17:13 | 显示全部楼层
区域读取器-AR
选择闭合多段线,它将在命令行上显示该区域以及一些可用选项。
 
  1. ;; by LE
  2. ;; To turn this ability ON-OFF use:
  3. ;; For ON:
  4. ;; (setenv "AutoAreaReader" "1")
  5. ;; For OFF:
  6. ;; (setenv "AutoAreaReader" "0")
  7. ;;
  8. ;;
  9. ;; To change the print output use:
  10. ;; Variable name: def_show_area
  11. ;; Options:
  12. ;; 1. "Decimal"
  13. ;; 2. "Squarefeet"
  14. ;; 3. "Acres"
  15. ;; 4. "SquareMeters"
  16. ;; 5. "Hectares"
  17. ;; In example:
  18. ;; Command: (setq def_show_area "Acres")
  19. ;;--------------------------------------------------------------
  20. (if (not (getenv "AutoAreaReader"))
  21. (setenv "AutoAreaReader" "0"))
  22. ;;--------------------------------------------------------------
  23. (defun ssget->vla-list  (ss / index vlaList)
  24. (setq index (if ss
  25. (1- (ssLength ss))
  26. -1))
  27. (while (>= index 0)
  28.    (setq vlaList (cons
  29.      (vlax-ename->vla-object
  30.        (ssname ss index))
  31.      vlaList)
  32.   index   (1- index)))
  33. vlaList)
  34. ;;--------------------------------------------------------------
  35. (defun addComma  (txt / strl cont1 lth cont txt1)
  36. (setq strl  (strlen txt)
  37. cont1 1
  38. txt1  "")
  39. (while (and (/= (substr txt cont1 1) ".") (<= cont1 strl))
  40.    (setq cont1 (1+ cont1)))
  41. (setq lth   (1- cont1)
  42. cont1 1
  43. cont  (1- lth))
  44. (if (> lth 3)
  45.    (progn
  46.      (while (< cont1 lth)
  47. (setq let  (substr txt cont1 1)
  48.       txt1 (strcat txt1 let))
  49. (if (and (zerop (rem cont 3)) (eq (type (read let)) 'INT))
  50.   (setq txt1 (strcat txt1 ",")))
  51. (setq cont  (1- cont)
  52.       cont1 (1+ cont1)))
  53.      (while (<= cont1 strl)
  54. (setq txt1  (strcat txt1 (substr txt cont1 1))
  55.       cont1 (1+ cont1)))
  56.      txt1)
  57.    txt))
  58. ;;--------------------------------------------------------------
  59. (defun printArea  (ar / string)
  60. (setq string
  61.    "\nChange variable LUPREC to a higher precision value - try again.")
  62. (if (not def_show_area)
  63.    (setq def_show_area "Decimal"))
  64. (cond
  65.    ((= def_show_area "Decimal")
  66.     (if (zerop (atof (rtos ar 2 (getvar "luprec"))))
  67.       (prompt string)
  68.       (princ
  69. (addComma
  70.    (rtos ar 2 (getvar "luprec"))))))
  71.    ((= def_show_area "Squarefeet")
  72.     (if (zerop (atof (rtos (/ ar 144.0) 2 (getvar "luprec"))))
  73.       (prompt string)
  74.       (progn
  75. (princ
  76.    (addComma (rtos (/ ar 144.0) 2 (getvar "luprec"))))
  77. (princ " square feet"))))
  78.    ((= def_show_area "Acres")
  79.     (if
  80.       (zerop
  81. (atof (rtos (/ (/ ar 144.0) 43560.0) 2 (getvar "luprec"))))
  82. (prompt string)
  83. (progn
  84.   (princ
  85.     (addComma
  86.       (rtos (/ (/ ar 144.0) 43560.0) 2 (getvar "luprec"))))
  87.   (princ " acres"))))
  88.    ((= def_show_area "SquareMeters")
  89.     (if (zerop (atof (rtos ar 2 (getvar "luprec"))))
  90.       (prompt string)
  91.       (progn
  92. (princ
  93.    (addComma
  94.      (rtos ar 2 (getvar "luprec"))))
  95. (princ " m2"))))
  96.    ((= def_show_area "Hectares")
  97.     (if
  98.       (zerop
  99. (atof (rtos (/ ar 10000.0) 2 (getvar "luprec"))))
  100. (prompt string)
  101. (progn
  102.   (princ
  103.     (addComma
  104.       (rtos (/ ar 10000.0) 2 (getvar "luprec"))))
  105.   (princ " hectares"))))))
  106. ;;--------------------------------------------------------------
  107. (defun areareader-pickfirst
  108.       (reactor params / ss ent obj ar pol_data lst_dat)
  109. (if (eq (getenv "AutoAreaReader") "1")
  110.    (cond
  111.      ((and (eq 1 (logand 1 (getvar "pickfirst")))
  112.     (setq ss (ssget "_i" '((0 . "LWPOLYLINE"))))
  113.     (eq 1 (sslength ss))
  114.     (setq ent (ssname ss 0))
  115.     (setq obj (vlax-ename->vla-object ent))
  116.     (eq (vla-get-closed obj) :vlax-true))
  117.       (setq ar (vla-get-area obj))
  118.       (princ "\nArea of single polyline= ")
  119.       (printArea ar)
  120.       (princ))
  121.      ((and
  122. (eq 1 (logand 1 (getvar "pickfirst")))
  123. (setq ss (ssget "_i" '((0 . "LWPOLYLINE"))))
  124. (> (sslength ss) 1)
  125. (vl-every
  126.    (function
  127.      (lambda (obj) (eq (vla-get-closed obj) :vlax-true)))
  128.    (setq objs (ssget->vla-list ss))))
  129.       (princ "\nTotal area of multiple polylines= ")
  130.       (setq ar (apply '+ (mapcar 'vla-get-area objs)))
  131.       (printArea ar)
  132.       (princ)))))
  133. ;;--------------------------------------------------------------
  134. (if (not areareader_pickfirst_reactor)
  135. (setq areareader_pickfirst_reactor
  136. (vlr-set-notification
  137.    (vlr-miscellaneous-reactor
  138.      "AutoAreaReader"
  139.      '((:vlr-pickfirstmodified . areareader-pickfirst)))
  140.    'active-document-only)))
  141. ;;--------------------------------------------------------------
  142. (defun dtt-removeall  (reactor params)
  143. (vlr-remove-all))
  144. ;;--------------------------------------------------------------
  145. (if (not dtt_reactor_dwg)
  146. (setq dtt_reactor_dwg
  147. (vlr-set-notification
  148.    (vlr-editor-reactor
  149.      "removeallreactors"
  150.      '((:vlr-beginclose . dtt-removeall)))
  151.    'active-document-only)))
  152. ;;--------------------------------------------------------------
  153. (defun C:AR()
  154. (cond
  155. ;; ON
  156. ((and (eq (getenv "AutoAreaReader") "1")
  157. areareader_pickfirst_reactor
  158. (not (vlr-added-p areareader_pickfirst_reactor)))
  159.   (vlr-add areareader_pickfirst_reactor))
  160. ;; OFF
  161. ((and (eq (getenv "AutoAreaReader") "0")
  162. areareader_pickfirst_reactor
  163. (vlr-added-p areareader_pickfirst_reactor))
  164.   (vlr-remove areareader_pickfirst_reactor)))
  165. (princ))
  166. (princ)
回复

使用道具 举报

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:27:34 | 显示全部楼层
从分组点列表中绘制多段线
一种从点绘制多段线的简单方法,其中一条线是由两个点SP-EP和一个凸起数据组成的列表,它由三个点SP-MP-EP表示
 
  1. ;; by LE
  2. (if (not thisDwg)
  3. (setq thisDwg
  4. (vla-get-activeDocument (vlax-get-acad-object))))
  5. (defun pspace () (vla-get-paperSpace thisDwg))
  6. (if (not :rcmModel)
  7. (setq :rcmModel
  8. (vla-get-modelSpace thisDwg)))
  9. (defun activespace  ()
  10. (if (= acModelSpace (vla-get-activeSpace thisDwg))
  11.    :rcmModel
  12.    (if (= (vla-get-mSpace thisDwg) :vlax-true)
  13.      :rcmModel
  14.      (pspace))))
  15. (defun list->variantArray  (ptslist / arrayspace sarray)
  16. (setq arrayspace
  17. (vlax-make-safeArray
  18.    vlax-vbDouble
  19.    (cons 0
  20. (- (length ptslist) 1))))
  21. (setq sarray (vlax-safeArray-fill arrayspace ptslist))
  22. (vlax-make-variant sarray))
  23. (defun getbulge (fromVertex midp p2 / ang chord midc alt)
  24. (setq ang   (angle fromVertex p2)
  25. chord (distance fromVertex p2)
  26. midc  (polar fromVertex ang (* chord 0.5))
  27. alt   (distance midp midc))
  28. (cond
  29.    ((zerop chord) 0.0)
  30.    ((equal (angle midp midc)
  31.     (rem (+ ang (* pi 0.5)) (* pi 2))
  32.     1e-4)
  33.     (/ alt chord 0.5))
  34.    (T (/ alt chord -0.5))))
  35. (defun 2dpt  (pt)
  36. (if (caddr pt)
  37.    (list (car pt) (cadr pt))
  38.    pt))
  39. (defun pline_vlisp  (tst / sp pts index vla_poly)
  40. (setq sp (2dpt (caar tst)))
  41.    (setq
  42.    pts (mapcar
  43.   (function (lambda (lst)
  44.        (cond
  45.   ((= (length lst) 2) (2dpt (cadr lst)))
  46.   ((= (length lst) 3) (2dpt (caddr lst))))))
  47.   tst))
  48. (setq pts (cons sp pts))
  49. (if (not (vl-catch-all-error-p
  50.      (setq vla_poly
  51.      (vl-catch-all-apply
  52.        'vla-addlightweightpolyline
  53.        (list (activespace)
  54.       (list->variantArray (apply 'append pts)))))))
  55.    (vla-put-closed vla_poly t))
  56. (setq index 0)
  57. (mapcar (function
  58.     (lambda (lst)
  59.       (if (= (length lst) 3)
  60. (vla-setbulge
  61.    vla_poly
  62.    index
  63.    (getbulge (car lst) (cadr lst) (caddr lst))))
  64.       (setq index (1+ index))))
  65.   tst)
  66. vla_poly)
  67. ;; list of points
  68. ;; included are lists of two for lines and three for curves
  69. (setq tst (list
  70.     '((39.6076 -8.96248 0.0) (32.6084 -18.2036 0.0))
  71.     '((32.6084 -18.2036 0.0) (52.2729 -16.9548))
  72.     '((52.2729 -16.9548)
  73.       (56.9734 -18.4078)
  74.       (59.5221 -22.6161))
  75.     '((59.5221 -22.6161)
  76.       (64.61 -25.6477)
  77.       (66.938 -20.2017))
  78.     '((66.938 -20.2017) (59.0222 -7.79693 0.0))
  79.     '((59.0222 -7.79693 0.0) (39.6076 -8.96248 0.0))))
  80. ;; do the test...
  81. ;;(pline_vlisp tst) ;; remove this line to test the above code
回复

使用道具 举报

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:33:30 | 显示全部楼层
自定义自动保存控件
一种将自动保存文件备份到特定文件夹位置(C:自动保存)的方法,格式前缀为BAK_(dwgname)
 
注意:在每个打开的文件上加载反应器,并在保存图形后进行保存。
 
  1. (vl-load-com)
  2. (if (not (vl-file-directory-p "C:\\AUTOSAVE\"))
  3. (vl-mkdir "C:\\AUTOSAVE\"))
  4. (defun copy_sv$  (reactor params / files file)
  5. (if
  6.    (and (setq files
  7. (vl-directory-files (getvar "SAVEFILEPATH") "*.SV$"))
  8. (setq file
  9. (vl-some
  10.    (function
  11.      (lambda (dwg)
  12.        (if
  13.   (wcmatch
  14.     dwg
  15.     (strcat "*"
  16.      (vl-filename-base (getvar "DWGNAME"))
  17.      "*"))
  18.    dwg)))
  19.    files)))
  20.     (progn
  21.       ;; make a copy of SV$ file into the c:\\autosave folder
  22.       ;; as a drawing extension with the OUT_ prefix
  23.       (vl-file-copy
  24. (strcat (getvar "SAVEFILEPATH") "\" file)
  25. (strcat "C:\\AUTOSAVE\" "OUT_" (getvar "DWGNAME")))
  26.       ;; delete previous BAK_ file
  27.       (vl-file-delete
  28. (strcat "C:\\AUTOSAVE\" "BAK_" (getvar "DWGNAME")))
  29.       ;; rename the new OUT_ file with the BAK_ prefix
  30.       (vl-file-rename
  31. (strcat "C:\\AUTOSAVE\" "OUT_" (getvar "DWGNAME"))
  32. (strcat "C:\\AUTOSAVE\" "BAK_" (getvar "DWGNAME")))
  33.       ;; delete OUT_ file
  34.       (vl-file-delete
  35. (strcat "C:\\AUTOSAVE\" "OUT_" (getvar "DWGNAME"))))))
  36. (if (not dwg_reactor)
  37. (setq dwg_reactor
  38. (vlr-dwg-reactor nil '((:vlr-beginsave . copy_sv$)))))
  39. (princ)
回复

使用道具 举报

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:35:51 | 显示全部楼层
反应器Wiz
一种控制visual lisp对象反应器的方法。
包含的例程示例生成详图、注释记号和圆形气泡符号。
 
一些控件或功能包括:
-属性的位置控制。
-指定一个对象来控制复制。复制此对象时,它将创建一个新符号并将其添加到同一反应器。
-当符号中的一个对象被删除时,整个符号也将被删除。
 
希望这会有意义。。。
 
部分代码示例-(所有源代码和vlisp.prj都在附带的zip中)
  1. ;;LE
  2. ;; degrees
  3. (setq :rwiz_45degrees (* pi 0.25))
  4. (setq :rwiz_90degrees (* pi 0.5))
  5. (setq :rwiz_135degrees (* pi 0.75))
  6. (setq :rwiz_225degrees (* pi 1.25))
  7. (setq :rwiz_270degrees (* pi 1.5))
  8. (setq :rwiz_315degrees (* pi 1.75))
  9. (setq :rwiz_360degrees (* pi 2.0))
  10. ;;;_____________________________________________________________
  11. ;; get acad object object
  12. ;; LE
  13. (if (not :rwiz_acad)
  14.    (setq :rwiz_acad (vlax-get-acad-object)))
  15. ;;;_____________________________________________________________
  16. ;;; get active drawing object
  17. ;;; LE
  18. (defun rwiz-thisdwg () (vla-get-activedocument :rwiz_acad))
  19. ;; global variable for this drawing
  20. ;; LE
  21. ;;;(or :rwiz_thisdwg (setq :rwiz_thisdwg (rwiz-thisdwg)))
  22. (setq
  23. :rwiz_thisdwg
  24.   (cond (:rwiz_thisdwg)
  25. ((rwiz-thisdwg))
  26. (t (rwiz-thisdwg))))
  27. ;;;_____________________________________________________________
  28. ;; get model space object
  29. ;; LE
  30. (if (not :rwiz_model)
  31.    (setq :rwiz_model
  32.    (vla-get-modelspace (rwiz-thisdwg))))
  33. ;;;_____________________________________________________________
  34. ;;; get paper space object
  35. ;;; LE
  36. (defun rwiz-pspace () (vla-get-paperspace (rwiz-thisdwg)))
  37. ;;;_____________________________________________________________
  38. ;;; get active space object
  39. (defun rwiz-get-activespace  ()
  40. (if (= acmodelspace (vla-get-activespace (rwiz-thisdwg)))
  41.    :rwiz_model
  42.    (if (= (vla-get-mspace (rwiz-thisdwg)) :vlax-true)
  43.      :rwiz_model
  44.      (rwiz-pspace))))
  45. ;;;_____________________________________________________________
  46. ;;; get active space name "Model" or "Paper"
  47. (defun rwiz-activespacename  ()
  48. (cond
  49.    ((= acmodelspace (vla-get-activespace (rwiz-thisdwg)))
  50.     "Model")
  51.    (t
  52.     (if (= (vla-get-mspace (rwiz-thisdwg)) :vlax-true)
  53.       "Model"
  54.       "Paper"))))
  55. ;;;_____________________________________________________________
  56. ;;; adjust dimscale, it will use 1.0 factor when is in paper space
  57. ;;; sc = scale factor as real
  58. ;;; LE
  59. (defun rwiz-adjust-dimscale  (sc)
  60. (if (= (rwiz-activespacename) "Model")
  61.    sc
  62.    1.0))
  63. ;;;_____________________________________________________________
  64. ;;; list to variant array
  65. ;;; ptslist = point list
  66. (defun rwiz-list-variantarray  (ptslist / arrayspace sarray)
  67. (setq arrayspace
  68. (vlax-make-safearray
  69.    ;; element type
  70.    vlax-vbdouble
  71.    ;; array dimension
  72.    (cons 0
  73.   (- (length ptslist) 1))))
  74. (setq sarray (vlax-safearray-fill arrayspace ptslist))
  75. ;; return array variant
  76. (vlax-make-variant sarray))
  77. ;;;_____________________________________________________________
  78. ;;; 3d point to 2d point
  79. ;;; 3dpt = 3d point
  80. (defun rwiz-3dpt-2dpt  (3dpt)
  81. (list (float (car 3dpt)) (float (cadr 3dpt))))
  82. ;;;_____________________________________________________________
  83. ;;; selection set to vla objects list
  84. ;;; ss = selection set
  85. (defun rwiz-ss-vla-list  (ss / index vlalist)
  86. (setq index (if ss
  87. (1- (sslength ss))
  88. -1))
  89. (while (>= index 0)
  90.    (setq vlalist (cons
  91.      (vlax-ename->vla-object
  92.        (ssname ss index))
  93.      vlalist)
  94.   index   (1- index)))
  95. vlalist)
  96. ;;;_____________________________________________________________
  97. ;;; selection set to array
  98. ;;; ss = selection set
  99. (defun rwiz-ss-array  (ss / c r)
  100. (setq c -1)
  101. (repeat (sslength ss)
  102.    (setq r (cons (ssname ss (setq c (1+ c))) r)))
  103. (setq r (reverse r))
  104. (vlax-safearray-fill
  105.    (vlax-make-safearray
  106.      vlax-vbobject
  107.      (cons 0 (1- (length r))))
  108.    (mapcar 'vlax-ename->vla-object r)))
  109. ;;;_____________________________________________________________
  110. ;;; array of vbobject's
  111. ;;; vla_lst = vla-object list
  112. ;;; LE
  113. (defun rwiz-array-vbobject  (vla_lst)
  114. (vlax-safearray-fill
  115.    (vlax-make-safearray
  116.      vlax-vbobject
  117.      (cons 0 (1- (length vla_lst))))
  118.    vla_lst))
  119. ;;;_____________________________________________________________
  120. ;;; make block
  121. ;;; usage:
  122. ;;; (rwiz-makeblock (list 0.0 0.0 0.0) "BLOCKNAME" selection_set T)
  123. ;;; flag:
  124. ;;; t = delete objects
  125. ;;; nil = keep objects
  126. ;;; LE
  127. (defun rwiz-makeblock  (pt name ss flag / ssarray vla_block)
  128. (vla-copyobjects
  129.    (rwiz-thisdwg)
  130.    (setq ssarray (rwiz-ss-array ss))
  131.    (setq vla_block (vla-add (vla-get-blocks (rwiz-thisdwg))
  132.        (vlax-3d-point pt)
  133.        name)))
  134. ;; delete objects
  135. (if (and flag
  136.    ssarray
  137.    (= (type ssarray) 'safearray)
  138.    ;; is the safearray made of vlax-object's
  139.    (= (vlax-safearray-type ssarray) 9))
  140.    (mapcar 'vla-delete (safearray-value ssarray)))
  141. vla_block)
  142. ;;;_____________________________________________________________

 
  1. ...
  2. (cond
  3.    ((and (equal (vlr-type reactor) :vlr-object-reactor)
  4.   (vl-some 'vlax-erased-p (vlr-owners reactor)))
  5.     (foreach owner  (vlr-owners reactor)
  6.       (vlr-owner-remove reactor owner))
  7.     (vlr-data-set reactor nil)
  8.     (vlr-pers-release reactor))
  9.    ((and (equal (vlr-type reactor) :vlr-object-reactor)
  10.   (not (vlr-owners reactor)))
  11.     (foreach owner  (vlr-owners reactor)
  12.       (vlr-owner-remove reactor owner))
  13.     (vlr-data-set reactor nil)
  14.     (vlr-pers-release reactor))
  15.    ((and (vlr-added-p reactor)
  16.   (not (equal (vlr-type reactor)
  17.        :vlr-object-reactor))
  18.   (vl-some 'vlax-erased-p (vlr-data reactor)))
  19.     (vlr-data-set reactor nil)
  20.     (vlr-pers-release reactor))
  21.    ((and (vlr-added-p reactor)
  22.   (not (equal (vlr-type reactor)
  23.        :vlr-object-reactor))
  24.   (not (vlr-data reactor)))
  25.     (vlr-data-set reactor nil)
  26.     (vlr-pers-release reactor))))
  27. ;;;_____________________________________________________________
  28. (defun rwiz-update-pers-list  ()
  29. (mapcar
  30.    (function
  31.      (lambda (reactor)
  32. (cond
  33.   ((and (equal (vlr-type reactor) :vlr-object-reactor)
  34. (vl-some 'vlax-erased-p (vlr-owners reactor)))
  35.    (foreach owner  (vlr-owners reactor)
  36.      (vlr-owner-remove reactor owner))
  37.    (vlr-data-set reactor nil)
  38.    (vlr-pers-release reactor))
  39.   ((and (equal (vlr-type reactor) :vlr-object-reactor)
  40. (not (vlr-owners reactor)))
  41.    (foreach owner  (vlr-owners reactor)
  42.      (vlr-owner-remove reactor owner))
  43.    (vlr-data-set reactor nil)
  44.    (vlr-pers-release reactor))
  45.   ((and (vlr-added-p reactor)
  46. (not (equal (vlr-type reactor)
  47.       :vlr-object-reactor))
  48. (vl-some 'vlax-erased-p (vlr-data reactor)))
  49.    (vlr-data-set reactor nil)
  50.    (vlr-pers-release reactor))
  51.   ((and (vlr-added-p reactor)
  52. (not (equal (vlr-type reactor)
  53.       :vlr-object-reactor))
  54. ...

125219yaydhhhnsna8jpsn.png
反应器Wiz。拉链
回复

使用道具 举报

54

主题

208

帖子

46

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
386
发表于 2022-7-6 12:42:34 | 显示全部楼层
尊敬的先生:
Lisp程序很好
谢谢分享你的Lisp程序
回复

使用道具 举报

2

主题

47

帖子

45

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:49:39 | 显示全部楼层
LCOPY公司
行复制器或多行偏移器,这个超旧的例程所做的是绘制或选择一条线,然后在给出偏移距离后,通过移动光标,它将偏移到我们移动光标并垂直于所选线的一侧。
 
从未完成例行程序(按原样工作),然后(1994年)我试图模拟我在Intergraph Microstation 4.0中使用的命令,当时这是一个很棒的偏移工具,不知道是否仍然可用。
 
来自Microstation的那一个能够选择线并将光标移动到一边,它将绘制偏移量,并以相反的方式删除偏移量的线。
 
对于那些Lisp程序的人来说,这可能是一个很好的挑战。
 
  1. (vl-load-com)
  2. (defun C:LCOPY (/      p1     p2     p3     p4    sep   lcopyent
  3. entlist       m      s     n    c   lst
  4. obj  take   code5  mklin     
  5.        )  
  6. ;;;      (lbx-sysvarbegin
  7. ;;; '("cursorsize" "snapang" "orthomode")
  8. ;;;      )
  9. ;;; global symbol for angle direction
  10.      (if (not atemp)
  11. (setq atemp 0.0)
  12.      )
  13. ;;; preset distance separation
  14.      (if (not ll)
  15. (setq ll 1.0)
  16.      )
  17. ;;; just in case delete list of points
  18.      (file2nil)
  19.      (setq lst nil)
  20.      (prompt
  21. "\nLine Copier - inside this view only "
  22.      )
  23.      (setq mklin (vector))
  24.      (if (= mklin nil)
  25. (setq obj (entsel "\nSelect: "))
  26. (progn (setq p1 (car mklin)) (setq p2 (cadr mklin)))
  27.      )
  28.      (if (and obj (= (cdr (assoc 0 (entget (car obj)))) "LINE"))
  29. (progn
  30.   (setq lcopyent (car obj))
  31. ;;;   (redraw lcopyent 3)
  32.   (setq
  33.     entlist (entget lcopyent)
  34.     p1     (cdr (assoc 10 entlist))
  35.     p2     (cdr (assoc 11 entlist))
  36.   )
  37. )
  38.      )
  39.      (setq lst (readfile))
  40.      (if (and p1 p2)
  41. (progn
  42.   (if (and (not (member (point2str p1) lst))
  43.     (not (member (point2str p2) lst))
  44.       )
  45.     (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p2)))
  46.   )
  47.   (if (not (member (point2str p1) lst))
  48.     (write2file (point2str p1))
  49.   )
  50.   (if (not (member (point2str p2) lst))
  51.     (write2file (point2str p2))
  52.   )
  53.   (setq lst (readfile))
  54. )
  55.      )
  56.      (if p1
  57. (progn
  58.   (setvar "orthomode" 0)
  59.   (initget 6)
  60.   (setq sep
  61.   (getdist
  62.     (strcat "\nSelect two points/<Offset distance = "
  63.      (rtos ll)
  64.      ">: "
  65.     )
  66.   )
  67.   )
  68.   (if (= sep nil)
  69.     (setq sep ll)
  70.   )
  71.   (if (not ll)
  72.     (setq ll 1.0)
  73.   )
  74.   (setq ll sep)
  75. )
  76.      )
  77.      (if (and p1 p2 sep)
  78. (progn
  79.   (prompt
  80.     "\n<ENTER to stop>/Move the cursor to copy"
  81.   )
  82.   (while (not (equal (setq take (grread 't)) '(2 13)))
  83.     (setq code5 (car take))
  84.     (setq p3 (cadr take))
  85.     (if (and p3 (= 5 code5))
  86.       (progn
  87. (setq ;;find a point perpendicular to p1 & p2
  88.        p4
  89.         (inters p1
  90.          p2
  91.          p3
  92.          (polar p3 (+ (angle p1 p2) (* pi 0.5)) 1.0)
  93.          nil
  94.         )
  95. )
  96. (setq ;;use p3 & p4 as a angle of copy, we need a parallel copy
  97.        p1 (polar p1 (angle p4 p3) sep)
  98.        p2 (polar p2 (angle p4 p3) sep)
  99. )
  100. (setq lst (readfile))
  101. (if (and p1 p2)
  102.    (progn
  103.      (if (and (not (member (point2str p1) lst))
  104.        (not (member (point2str p2) lst))
  105.   )
  106.        (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p2)))
  107.      )
  108.      (if (not (member (point2str p1) lst))
  109.        (write2file (point2str p1))
  110.      )
  111.      (if (not (member (point2str p2) lst))
  112.        (write2file (point2str p2))
  113.      )
  114.    )
  115. )
  116.       )
  117.       (progn
  118. (prompt
  119.    "\r<ENTER to stop>/Move the cursor to copy"
  120. )
  121. (alert
  122.    "\nWorks only at the active view, other commands are disabled."
  123. )
  124.       )
  125.     )
  126.   )
  127. )
  128.      )
  129. ;;;      (lbx-sysvarend)
  130. (princ)
  131. )
  132. ;;; write strings points data to a working temporary file
  133. (defun write2file (n / file p search)
  134. (setq search (acad-target))
  135. (setq file (open (strcat search "$par$") "a"))
  136. (write-line n file)
  137. (close file)
  138. )
  139. ;;; read the working temporary file
  140. (defun readfile (/ file n tmp search)
  141. (setq search (acad-target))
  142. (if (findfile (strcat search "$par$"))
  143.    (progn
  144.      (setq file (open (findfile (strcat search "$par$")) "r"))
  145.      (while (setq n (read-line file))
  146. (if (/= n "")
  147.   (setq tmp (append tmp (list n)))
  148. )
  149.      )
  150.      (close file)
  151.    )
  152. )
  153. tmp
  154. )
  155. ;;; delete working temporary file
  156. (defun file2nil (/ search)
  157. (setq search (acad-target))
  158. (if (findfile (strcat search "$par$"))
  159.    (vl-file-delete (findfile (strcat search "$par$")))
  160.    nil
  161. )
  162. )
  163. ;;; use AutoCAD location as a target directory
  164. (defun acad-target ()
  165. (substr (findfile "ACAD.EXE")
  166.   1
  167.   (- (strlen (findfile "ACAD.EXE"))
  168. )
  169. )
  170. ;;; conversion of point list to string arguments
  171. (defun point2str (n / x y z)
  172. (setq x (rtos (car n) 2 6)
  173. y (rtos (cadr n) 2 6)
  174. z (rtos (caddr n) 2 6)
  175. )
  176. (strcat x y z)
  177. )
  178. (defun rtd (a) (* (/ a pi) 180.0))
  179. ;;; alignment angle (vector direction)
  180. (defun aangle (/ p1 ang)
  181. (setq p1 (getpoint "\n<Select LINE>/Line from: "))
  182. (if p1
  183.    (progn
  184.      (setq
  185. ang (getangle
  186.       (strcat "\nAlignment angle <"
  187.        (rtos (rtd atemp) 2 0)
  188.        ">: "
  189.       )
  190.       p1
  191.     )
  192.      )
  193.      (if (= ang nil)
  194. (setq ang atemp)
  195.      )
  196.      (setq atemp ang)
  197.      (setvar "orthomode" 1)
  198.      (list ang p1)
  199.    )
  200.    nil
  201. )
  202. )
  203. ;;; do a vector, returns: list of two
  204. ;;; points to construct the vector or nil
  205. (defun vector (/ anglin ang p1 sep)
  206. (setq sna (getvar "snapang"))
  207. (setq anglin (aangle))
  208. (if anglin
  209.    (progn
  210.      (setq ang (car anglin))
  211.      (setq p1 (cadr anglin))
  212.      (setvar "snapang" ang)
  213.      (setq size (getvar "cursorsize"))
  214.      (setvar "cursorsize" 1)
  215.      (initget 6)
  216.      ;;no zero, no negative
  217.      (setq sep
  218.      (getdist p1
  219.        (strcat "\nNext point/Length <"
  220.         (rtos ll)
  221.         ">: "
  222.        )
  223.      )
  224.      )
  225.      (if (= sep nil)
  226. (setq sep ll)
  227.      )
  228.      (if (not ll)
  229. (setq ll 1.0)
  230.      )
  231.      (setq ll sep)
  232.      (if sna
  233. (setvar "snapang" sna)
  234.      )
  235.      (if size
  236. (setvar "cursorsize" size)
  237.      )
  238.      (list p1 (polar p1 ang sep))
  239.    )
  240.    nil
  241. )
  242. )
  243. (princ)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 10:16 , Processed in 0.393179 second(s), 74 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表