声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3057|回复: 1

[AutoCAD] 化工工艺流程图阀门程序设计

[复制链接]
发表于 2007-6-3 03:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
提要:本文针对化工工艺流程图CAD阀门绘制程序设计,探讨CAD在化工工艺设计中的运用。文后提供的程序清单可在AutoCAD R12中文环境下运行,对化工工艺设计CAD二次开发提供经验与技巧。
  CAD技术已广泛应用于各专业设计,但在化工工艺设计领域内商品化软件不足,这就需要各设计单位自行开发应用软件以适应CAD技术的发展.本文提供的阀门绘制程序是在AutoCAD二次开发的化工工艺计算机辅助设计CPCAD系统中的一个独立程序,它以AutoLisp语言编写,功能全,使用方便,具有可读性及一定的技巧。
● 阀门绘制要求
  在AutoCAD上绘制阀门,要求于已存在的工艺管道上据阀门类型自动按一定的比例显示,图纸输出时的尺寸符合专业制图要求,(原因是不可能根据阀门的实际尺寸与其它化工设备按同一比例绘图) 并自动切断管道线,同时判断管线与水平方向的夹角,可取代AutoCAD的copy。阀门型式全,层自动设置并不受原当前层的影响。
● 程序简介
  该程序针对以上要求,提供11种常用阀型,可方便地进行选择.如需其它类型,可对源程序简单地修改补充。
1.主控程序
  在主控程序中,(if (and (/= *bl nil) (/= *dwgscale nil))判断变量*bl及*dwgscal是否存在.如不存在程序不再执行,因此需在ACAD.LSP中加载或在command下赋值(注:*bl=*dwgscale)。如(setq *bl 100) (setq *dwgscale 100),100为绘图比例。Progn语句段完成图层设置,下面的缺省值设计读者可自行分析,具有通用性和一定的技巧。
2.阀门程序的公用子程序
  该部分是程序的核心.阀门长度的赋值是绘图比例的5倍,当以相同比例输出时其长度为5mm。法兰的绘制是可选择的。当提示阀心位置时,选择line实体,程序可就选择的line实体的起点和终点坐标计算该线与水平方向的夹角,同时求出各绘制点的极坐标。需要强调的是对Pline折线不适用,其原因是起点与终点的连线和要绘阀门不一致。(一般地,如需粗线可在出图时对绘图仪的参数进行设置)该子程序中又调用法兰设计子程序,这是AutoLisp允许的,而且是一很好的功能。
3.其它子程序相对简单,不再介绍。

评分

1

查看全部评分

回复
分享到:

使用道具 举报

 楼主| 发表于 2007-6-3 03:44 | 显示全部楼层
●.附源程序清单VA
  1. (defun *ERROR* (st)
  2. (menucmd "s=s")
  3. (command "osnap" "none")
  4. (command "layer" "s" cl "")
  5. (setvar "regenmode" 1)
  6. (princ st)
  7. (terpri)
  8. )
  9. (defun qs ()
  10. (setq fc (* 5.0 *bl))
  11. (menucmd "s=s")
  12. (initget "Y N")
  13. (if (not *yffl) (setq *yffl "N"))
  14. (princ "\n有否法兰: [ Y/N ]< ")
  15. (princ *yffl)
  16. (setq fl (getkword " >"))
  17. (if (not fl) (setq fl *yffl) (setq *yffl fl))
  18. ) (defun dfw ( )
  19. (command "OSNAP" "NEAR")
  20. (setq e1 (entsel "\n阀心位置:"))
  21. (command "osnap" "none")
  22. (defun gy()
  23. (setq zx (cadr e1)
  24. e2 (entget (car e1))
  25. p01 (cdr (assoc 10 e2))
  26. p02 (cdr (assoc 11 e2))
  27. zj (+ (* (/ 1.0 2.0) pi) (angle p01 p02))
  28. l1 (/ fc 1.732)
  29. l2 (/ l1 1.0)
  30. p1 (polar zx (+ zj (* (/ 2.0 3.0) pi)) l2)
  31. p2 (polar zx (+ zj (* (/ 1.0 3.0) pi)) l2)
  32. p3 (polar zx (+ zj (* (/ 4.0 3.0) pi)) l2)
  33. p4 (polar zx (+ zj (* (/ 5.0 3.0) pi)) l2)
  34. p11 (polar zx (+ zj (* (/ 1.0 2.0) pi)) (* 0.867 l2))
  35. p21 (polar zx (+ zj (* (/ 2.0 3.0) pi)) (* 0.48 l1))
  36. p22 (polar zx (+ zj (* (/ 1.0 3.0) pi)) (* 0.48 l1))
  37. p23 (polar zx (+ zj (* (/ 4.0 3.0) pi)) (* 0.48 l1))
  38. p24 (polar zx (+ zj (* (/ 5.0 3.0) pi)) (* 0.48 l1)));setq
  39. (flsz)
  40. (command "break" p32 p33 )
  41. )
  42. (defun qf ( )
  43. (while e1
  44. (gy)
  45. (command "line" p21 p1 p2 p22 ""
  46. "line" p23 p3 p4 p24 ""
  47. "circle" zx (* 0.48 l1));command
  48. (dfw)
  49. );while
  50. (PRINC)
  51. )
  52. (defun jz ( )
  53. (while e1
  54. (gy)
  55. (command "line" p1 p2 p3 p4 p1 "")
  56. (dfw)
  57. (PRINC)
  58. )
  59. )
  60. (defun zf ( )
  61. (while e1
  62. (gy)
  63. (setq l3 (/ l2 2)
  64. p7 (polar zx (+ zj (* (/ 1.0 1.0) pi)) l3)
  65. p8 (polar zx (+ zj (* (/ 0.0 1.0) pi)) l3));setq
  66. (command "line" p1 p2 p3 p4 p1 ""
  67. "line" p7 p8 "" );command
  68. (dfw)
  69. (PRINC));while
  70. )
  71. (defun dx ( )
  72. (while e1
  73. (gy)
  74. (command "line" p1 p2 p3 p4 p1 ""
  75. "solid" zx p3 p4 "" "");command
  76. (xzjd)
  77. (command "rotate" "c" p2 p3 "" zx zj)
  78. (dfw)
  79. )
  80. (PRINC)
  81. )
  82. (defun xzjd()
  83. (initget "Y N")
  84. (if (not *xz) (setq *xz "N"))
  85. (princ "\n镜像旋转: [ Y/N ]< ")
  86. (princ *xz)
  87. (setq xz (getkword " >"))
  88. (if (not xz) (setq xz *xz) (setq *xz xz))
  89. (if (= xz "N") (setq zj 0.0) (setq zj 180.0))
  90. ) (defun xs ( )
  91. (while e1
  92. (gy)
  93. (command "line" p1 p2 p3 p4 p1 ""
  94. "donut" 0 (* 0.8 l1) zx "");command
  95. (dfw)
  96. );while
  97. (PRINC)
  98. )
  99. (defun jl ( )
  100. (while e1
  101. (gy)
  102. (command "line" p1 p2 p3 p4 p1 ""
  103. "solid" zx p3 p4 "" ""
  104. "solid" zx p1 p2 "" "");command
  105. (dfw)
  106. );while
  107. (PRINC)
  108. )
  109. (defun jy ( )
  110. (while e1
  111. (gy)
  112. (command "line" p1 p3 p4 p2 p1 ""
  113. "line" p3 p11 p4 "");command
  114. (xzjd)
  115. (command "rotate" "c" p2 p3 "" zx zj)
  116. (dfw)
  117. );while
  118. (PRINC)
  119. )
  120. (defun gm ( )
  121. (while e1
  122. (gy)
  123. (setq p44 (polar zx (+ zj (* 0.0 pi)) (* 0.6 l1)))
  124. (command "line" p1 p2 p3 p4 p1 ""
  125. "arc" p24 p44 p22);command
  126. (dfw)
  127. );while
  128. (PRINC)
  129. ) (defun df ( )
  130. (while e1
  131. (gy)
  132. (command "line" p1 p3 p4 p2 p1 ""
  133. "circle" zx (* 0.5 l1));command
  134. (dfw)
  135. );while
  136. (PRINC)
  137. )
  138. (defun ss ( )
  139. (while e1
  140. (gy)
  141. (setq p55 (polar zx (* 0.25 pi) (* 0.45 fc))
  142. p56 (polar zx (* 1.25 pi) (* 0.45 fc))
  143. p57 (polar zx (* 1.25 pi) (* 0.225 fc)));setq
  144. (command "pline" p57 "w" (* 0.45 fc) "" "a" "ce" zx "a" 180 ""
  145. "line" p55 p56 ""
  146. "circle" zx (* 0.45 fc) );command
  147. (dfw)
  148. );while
  149. (PRINC)
  150. )
  151. (defun kz ( )
  152. (while e1
  153. (gy)
  154. (setq k1 (polar zx zj (* l2 0.7))
  155. kzx (polar zx zj (* l2 0.35))
  156. k2 (polar k1 (+ zj (* (/ 1.0 2.0) pi)) (/ l2 2.0))
  157. k3 (polar k1 (+ zj (* (/ 3.0 2.0) pi)) (/ l2 2.0))
  158. k4 (polar k1 zj (/ l2 2.0)));setq
  159. (command "line" p1 p2 p3 p4 p1 ""
  160. "line" k2 k3 ""
  161. "line" k1 zx ""
  162. "arc" k2 k4 k3);command
  163. (xzjd)
  164. (command "rotate" "c" kzx k4 "" zx zj)
  165. (dfw)
  166. );while
  167. (PRINC)
  168. )
  169. (defun flsz()
  170. (if (= fl "Y")
  171. (progn
  172. (setq p32 (polar zx (+ zj (* (/ -1.0 2.0) pi)) (* 3.0 *bl))
  173. p33 (polar zx (+ zj (* (/ 1.0 2.0) pi)) (* 3.0 *bl))
  174. pf1 (polar p32 (+ zj (* 0.0 pi)) (* 0.5 l1))
  175. pf2 (polar p32 (+ zj (* 1.0 pi)) (* 0.5 l1))
  176. pf3 (polar p33 (+ zj (* 1.0 pi)) (* 0.5 l1))
  177. pf4 (polar p33 (+ zj (* 0.0 pi)) (* 0.5 l1)));setq
  178. (command "break" p32 p33 "line" pf1 pf2 ""
  179. "line" pf3 pf4 "");command
  180. );progn
  181. (setq p32 (polar zx (+ zj (* (/ -1.0 2.0) pi)) l2)
  182. p33 (polar zx (+ zj (* (/ 1.0 2.0) pi)) l2));setq
  183. );if
  184. (princ)
  185. )
  186. (defun va( )
  187. (if (and (/= *bl nil) (/= *dwgscale nil))
  188. (progn
  189. (setvar "cmdecho" 0)
  190. (setvar "regenmode" 0)
  191. (setq cl (getvar "clayer"))
  192. (command "blipmode" "off"
  193. "fill" "on"
  194. "layer" "m" "va" "s" "va"
  195. "lt" "continuous" "" "c" "green" "" "");command
  196. (initget "Q Z J D X L Y G W S K")
  197. (if (not *fm) (setq *fm "J"))
  198. (princ "\n球Q/闸Z/截J/单D/旋X/节L/减Y/隔G/蝶W/疏S/控K < ")
  199. (princ *fm)
  200. (setq fm (getkword " >:"))
  201. (if (not fm) (setq fm *fm) (setq *fm fm))
  202. (cond ((= fm "Q") (qs) (dfw) (qf))
  203. ((= fm "Z") (qs) (dfw) (zf))
  204. ((= fm "J") (qs) (dfw) (jz))
  205. ((= fm "D") (qs) (dfw) (dx))
  206. ((= fm "X") (qs) (dfw) (xs))
  207. ((= fm "L") (qs) (dfw) (jl))
  208. ((= fm "Y") (qs) (dfw) (jy))
  209. ((= fm "G") (qs) (dfw) (gm))
  210. ((= fm "W") (qs) (dfw) (df))
  211. ((= fm "S") (qs) (dfw) (ss))
  212. ((= fm "K") (qs) (dfw) (kz)));cond
  213. (command "layer" "s" cl "")
  214. (setvar "regenmode" 1)
  215. (princ)
  216. )
  217. )
  218. );end
  219. (va)
  220. princ)
  221. )
  222. )
  223. );end
  224. (va)
复制代码
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-24 02:12 , Processed in 0.097824 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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