明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1999|回复: 0

[推荐]关于化工工艺流程图阀门程序设计

[复制链接]
发表于 2007-4-4 08:07:00 | 显示全部楼层 |阅读模式

化工工艺流程图阀门程序设计
提要:本文针对化工工艺流程图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.其它子程序相对简单,不再介绍。
●.附源程序清单VA
(defun *ERROR* (st)
(menucmd "s=s")
(command "osnap" "none")
(command "layer" "s" cl "")
(setvar "regenmode" 1)
(princ st)
(terpri)
)
(defun qs ()
(setq fc (* 5.0 *bl))
(menucmd "s=s")
(initget "Y N")
(if (not *yffl) (setq *yffl "N"))
(princ "\n有否法兰: [ Y/N ]< ")
(princ *yffl)
(setq fl (getkword " >"))
(if (not fl) (setq fl *yffl) (setq *yffl fl))
) (defun dfw ( )
(command "OSNAP" "NEAR")
(setq e1 (entsel "\n阀心位置:"))
(command "osnap" "none")
(defun gy()
(setq zx (cadr e1)
e2 (entget (car e1))
p01 (cdr (assoc 10 e2))
p02 (cdr (assoc 11 e2))
zj (+ (* (/ 1.0 2.0) pi) (angle p01 p02))
l1 (/ fc 1.732)
l2 (/ l1 1.0)
p1 (polar zx (+ zj (* (/ 2.0 3.0) pi)) l2)
p2 (polar zx (+ zj (* (/ 1.0 3.0) pi)) l2)
p3 (polar zx (+ zj (* (/ 4.0 3.0) pi)) l2)
p4 (polar zx (+ zj (* (/ 5.0 3.0) pi)) l2)
p11 (polar zx (+ zj (* (/ 1.0 2.0) pi)) (* 0.867 l2))
p21 (polar zx (+ zj (* (/ 2.0 3.0) pi)) (* 0.48 l1))
p22 (polar zx (+ zj (* (/ 1.0 3.0) pi)) (* 0.48 l1))
p23 (polar zx (+ zj (* (/ 4.0 3.0) pi)) (* 0.48 l1))
p24 (polar zx (+ zj (* (/ 5.0 3.0) pi)) (* 0.48 l1)));setq
(flsz)
(command "break" p32 p33 )
)
(defun qf ( )
(while e1
(gy)
(command "line" p21 p1 p2 p22 ""
"line" p23 p3 p4 p24 ""
"circle" zx (* 0.48 l1));command
(dfw)
);while
(PRINC)
)
(defun jz ( )
(while e1
(gy)
(command "line" p1 p2 p3 p4 p1 "")
(dfw)
(PRINC)
)
)
(defun zf ( )
(while e1
(gy)
(setq l3 (/ l2 2)
p7 (polar zx (+ zj (* (/ 1.0 1.0) pi)) l3)
p8 (polar zx (+ zj (* (/ 0.0 1.0) pi)) l3));setq
(command "line" p1 p2 p3 p4 p1 ""
"line" p7 p8 "" );command
(dfw)
(PRINC));while
)
(defun dx ( )
(while e1
(gy)
(command "line" p1 p2 p3 p4 p1 ""
"solid" zx p3 p4 "" "");command
(xzjd)
(command "rotate" "c" p2 p3 "" zx zj)
(dfw)
)
(PRINC)
)
(defun xzjd()
(initget "Y N")
(if (not *xz) (setq *xz "N"))
(princ "\n镜像旋转: [ Y/N ]< ")
(princ *xz)
(setq xz (getkword " >"))
(if (not xz) (setq xz *xz) (setq *xz xz))
(if (= xz "N") (setq zj 0.0) (setq zj 180.0))
) (defun xs ( )
(while e1
(gy)
(command "line" p1 p2 p3 p4 p1 ""
"donut" 0 (* 0.8 l1) zx "");command
(dfw)
);while
(PRINC)
)
(defun jl ( )
(while e1
(gy)
(command "line" p1 p2 p3 p4 p1 ""
"solid" zx p3 p4 "" ""
"solid" zx p1 p2 "" "");command
(dfw)
);while
(PRINC)
)
(defun jy ( )
(while e1
(gy)
(command "line" p1 p3 p4 p2 p1 ""
"line" p3 p11 p4 "");command
(xzjd)
(command "rotate" "c" p2 p3 "" zx zj)
(dfw)
);while
(PRINC)
)
(defun gm ( )
(while e1
(gy)
(setq p44 (polar zx (+ zj (* 0.0 pi)) (* 0.6 l1)))
(command "line" p1 p2 p3 p4 p1 ""
"arc" p24 p44 p22);command
(dfw)
);while
(PRINC)
) (defun df ( )
(while e1
(gy)
(command "line" p1 p3 p4 p2 p1 ""
"circle" zx (* 0.5 l1));command
(dfw)
);while
(PRINC)
)
(defun ss ( )
(while e1
(gy)
(setq p55 (polar zx (* 0.25 pi) (* 0.45 fc))
p56 (polar zx (* 1.25 pi) (* 0.45 fc))
p57 (polar zx (* 1.25 pi) (* 0.225 fc)));setq
(command "pline" p57 "w" (* 0.45 fc) "" "a" "ce" zx "a" 180 ""
"line" p55 p56 ""
"circle" zx (* 0.45 fc) );command
(dfw)
);while
(PRINC)
)
(defun kz ( )
(while e1
(gy)
(setq k1 (polar zx zj (* l2 0.7))
kzx (polar zx zj (* l2 0.35))
k2 (polar k1 (+ zj (* (/ 1.0 2.0) pi)) (/ l2 2.0))
k3 (polar k1 (+ zj (* (/ 3.0 2.0) pi)) (/ l2 2.0))
k4 (polar k1 zj (/ l2 2.0)));setq
(command "line" p1 p2 p3 p4 p1 ""
"line" k2 k3 ""
"line" k1 zx ""
"arc" k2 k4 k3);command
(xzjd)
(command "rotate" "c" kzx k4 "" zx zj)
(dfw)
);while
(PRINC)
)
(defun flsz()
(if (= fl "Y")
(progn
(setq p32 (polar zx (+ zj (* (/ -1.0 2.0) pi)) (* 3.0 *bl))
p33 (polar zx (+ zj (* (/ 1.0 2.0) pi)) (* 3.0 *bl))
pf1 (polar p32 (+ zj (* 0.0 pi)) (* 0.5 l1))
pf2 (polar p32 (+ zj (* 1.0 pi)) (* 0.5 l1))
pf3 (polar p33 (+ zj (* 1.0 pi)) (* 0.5 l1))
pf4 (polar p33 (+ zj (* 0.0 pi)) (* 0.5 l1)));setq
(command "break" p32 p33 "line" pf1 pf2 ""
"line" pf3 pf4 "");command
);progn
(setq p32 (polar zx (+ zj (* (/ -1.0 2.0) pi)) l2)
p33 (polar zx (+ zj (* (/ 1.0 2.0) pi)) l2));setq
);if
(princ)
)
(defun va( )
(if (and (/= *bl nil) (/= *dwgscale nil))
(progn
(setvar "cmdecho" 0)
(setvar "regenmode" 0)
(setq cl (getvar "clayer"))
(command "blipmode" "off"
"fill" "on"
"layer" "m" "va" "s" "va"
"lt" "continuous" "" "c" "green" "" "");command
(initget "Q Z J D X L Y G W S K")
(if (not *fm) (setq *fm "J"))
(princ "\n球Q/闸Z/截J/单D/旋X/节L/减Y/隔G/蝶W/疏S/控K < ")
(princ *fm)
(setq fm (getkword " >:"))
(if (not fm) (setq fm *fm) (setq *fm fm))
(cond ((= fm "Q") (qs) (dfw) (qf))
((= fm "Z") (qs) (dfw) (zf))
((= fm "J") (qs) (dfw) (jz))
((= fm "D") (qs) (dfw) (dx))
((= fm "X") (qs) (dfw) (xs))
((= fm "L") (qs) (dfw) (jl))
((= fm "Y") (qs) (dfw) (jy))
((= fm "G") (qs) (dfw) (gm))
((= fm "W") (qs) (dfw) (df))
((= fm "S") (qs) (dfw) (ss))
((= fm "K") (qs) (dfw) (kz)));cond
(command "layer" "s" cl "")
(setvar "regenmode" 1)
(princ)
)
)
);end
(va)
princ)
)
)
);end
(va)

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

本版积分规则

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

GMT+8, 2024-11-26 01:46 , Processed in 0.179207 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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