[推荐]关于化工工艺流程图阀门程序设计
<p align="center">化工工艺流程图阀门程序设计<br/>提要:本文针对化工工艺流程图CAD阀门绘制程序设计,探讨CAD在化工工艺设计中的运用。文后提供的程序清单可在AutoCAD R12中文环境下运行,对化工工艺设计CAD二次开发提供经验与技巧。 <br/> CAD技术已广泛应用于各专业设计,但在化工工艺设计领域内商品化软件不足,这就需要各设计单位自行开发应用软件以适应CAD技术的发展.本文提供的阀门绘制程序是在AutoCAD二次开发的化工工艺计算机辅助设计CPCAD系统中的一个独立程序,它以AutoLisp语言编写,功能全,使用方便,具有可读性及一定的技巧。<br/>● 阀门绘制要求<br/> 在AutoCAD上绘制阀门,要求于已存在的工艺管道上据阀门类型自动按一定的比例显示,图纸输出时的尺寸符合专业制图要求,(原因是不可能根据阀门的实际尺寸与其它化工设备按同一比例绘图) 并自动切断管道线,同时判断管线与水平方向的夹角,可取代AutoCAD的copy。阀门型式全,层自动设置并不受原当前层的影响。<br/>● 程序简介<br/> 该程序针对以上要求,提供11种常用阀型,可方便地进行选择.如需其它类型,可对源程序简单地修改补充。<br/>1.主控程序<br/> 在主控程序中,(if (and (/= *bl nil) (/= *dwgscale nil))判断变量*bl及*dwgscal是否存在.如不存在程序不再执行,因此需在ACAD.LSP中加载或在command下赋值(注:*bl=*dwgscale)。如(setq *bl 100) (setq *dwgscale 100),100为绘图比例。Progn语句段完成图层设置,下面的缺省值设计读者可自行分析,具有通用性和一定的技巧。<br/>2.阀门程序的公用子程序<br/> 该部分是程序的核心.阀门长度的赋值是绘图比例的5倍,当以相同比例输出时其长度为5mm。法兰的绘制是可选择的。当提示阀心位置时,选择line实体,程序可就选择的line实体的起点和终点坐标计算该线与水平方向的夹角,同时求出各绘制点的极坐标。需要强调的是对Pline折线不适用,其原因是起点与终点的连线和要绘阀门不一致。(一般地,如需粗线可在出图时对绘图仪的参数进行设置)该子程序中又调用法兰设计子程序,这是AutoLisp允许的,而且是一很好的功能。<br/>3.其它子程序相对简单,不再介绍。<br/>●.附源程序清单VA<br/>(defun *ERROR* (st)<br/>(menucmd "s=s")<br/>(command "osnap" "none")<br/>(command "layer" "s" cl "")<br/>(setvar "regenmode" 1)<br/>(princ st)<br/>(terpri)<br/>)<br/>(defun qs ()<br/>(setq fc (* 5.0 *bl))<br/>(menucmd "s=s")<br/>(initget "Y N")<br/>(if (not *yffl) (setq *yffl "N"))<br/>(princ "\n有否法兰: [ Y/N ]< ")<br/>(princ *yffl)<br/>(setq fl (getkword " >"))<br/>(if (not fl) (setq fl *yffl) (setq *yffl fl))<br/>) (defun dfw ( )<br/>(command "OSNAP" "NEAR")<br/>(setq e1 (entsel "\n阀心位置:"))<br/>(command "osnap" "none")<br/>(defun gy()<br/>(setq zx (cadr e1)<br/>e2 (entget (car e1))<br/>p01 (cdr (assoc 10 e2))<br/>p02 (cdr (assoc 11 e2))<br/>zj (+ (* (/ 1.0 2.0) pi) (angle p01 p02))<br/>l1 (/ fc 1.732)<br/>l2 (/ l1 1.0)<br/>p1 (polar zx (+ zj (* (/ 2.0 3.0) pi)) l2)<br/>p2 (polar zx (+ zj (* (/ 1.0 3.0) pi)) l2)<br/>p3 (polar zx (+ zj (* (/ 4.0 3.0) pi)) l2)<br/>p4 (polar zx (+ zj (* (/ 5.0 3.0) pi)) l2)<br/>p11 (polar zx (+ zj (* (/ 1.0 2.0) pi)) (* 0.867 l2))<br/>p21 (polar zx (+ zj (* (/ 2.0 3.0) pi)) (* 0.48 l1))<br/>p22 (polar zx (+ zj (* (/ 1.0 3.0) pi)) (* 0.48 l1))<br/>p23 (polar zx (+ zj (* (/ 4.0 3.0) pi)) (* 0.48 l1))<br/>p24 (polar zx (+ zj (* (/ 5.0 3.0) pi)) (* 0.48 l1)));setq<br/>(flsz)<br/>(command "break" p32 p33 )<br/>)<br/>(defun qf ( )<br/>(while e1<br/>(gy)<br/>(command "line" p21 p1 p2 p22 ""<br/>"line" p23 p3 p4 p24 ""<br/>"circle" zx (* 0.48 l1));command<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun jz ( )<br/>(while e1<br/>(gy)<br/>(command "line" p1 p2 p3 p4 p1 "")<br/>(dfw)<br/>(PRINC)<br/>)<br/>)<br/>(defun zf ( )<br/>(while e1<br/>(gy)<br/>(setq l3 (/ l2 2)<br/>p7 (polar zx (+ zj (* (/ 1.0 1.0) pi)) l3)<br/>p8 (polar zx (+ zj (* (/ 0.0 1.0) pi)) l3));setq<br/>(command "line" p1 p2 p3 p4 p1 ""<br/>"line" p7 p8 "" );command<br/>(dfw)<br/>(PRINC));while<br/>)<br/>(defun dx ( )<br/>(while e1<br/>(gy)<br/>(command "line" p1 p2 p3 p4 p1 ""<br/>"solid" zx p3 p4 "" "");command<br/>(xzjd)<br/>(command "rotate" "c" p2 p3 "" zx zj)<br/>(dfw)<br/>)<br/>(PRINC)<br/>)<br/>(defun xzjd()<br/>(initget "Y N")<br/>(if (not *xz) (setq *xz "N"))<br/>(princ "\n镜像旋转: [ Y/N ]< ")<br/>(princ *xz)<br/>(setq xz (getkword " >"))<br/>(if (not xz) (setq xz *xz) (setq *xz xz))<br/>(if (= xz "N") (setq zj 0.0) (setq zj 180.0))<br/>) (defun xs ( )<br/>(while e1<br/>(gy)<br/>(command "line" p1 p2 p3 p4 p1 ""<br/>"donut" 0 (* 0.8 l1) zx "");command<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun jl ( )<br/>(while e1<br/>(gy)<br/>(command "line" p1 p2 p3 p4 p1 ""<br/>"solid" zx p3 p4 "" ""<br/>"solid" zx p1 p2 "" "");command<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun jy ( )<br/>(while e1<br/>(gy)<br/>(command "line" p1 p3 p4 p2 p1 ""<br/>"line" p3 p11 p4 "");command<br/>(xzjd)<br/>(command "rotate" "c" p2 p3 "" zx zj)<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun gm ( )<br/>(while e1<br/>(gy)<br/>(setq p44 (polar zx (+ zj (* 0.0 pi)) (* 0.6 l1)))<br/>(command "line" p1 p2 p3 p4 p1 ""<br/>"arc" p24 p44 p22);command<br/>(dfw)<br/>);while<br/>(PRINC)<br/>) (defun df ( )<br/>(while e1<br/>(gy)<br/>(command "line" p1 p3 p4 p2 p1 ""<br/>"circle" zx (* 0.5 l1));command<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun ss ( )<br/>(while e1<br/>(gy)<br/>(setq p55 (polar zx (* 0.25 pi) (* 0.45 fc))<br/>p56 (polar zx (* 1.25 pi) (* 0.45 fc))<br/>p57 (polar zx (* 1.25 pi) (* 0.225 fc)));setq<br/>(command "pline" p57 "w" (* 0.45 fc) "" "a" "ce" zx "a" 180 ""<br/>"line" p55 p56 ""<br/>"circle" zx (* 0.45 fc) );command<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun kz ( )<br/>(while e1<br/>(gy)<br/>(setq k1 (polar zx zj (* l2 0.7))<br/>kzx (polar zx zj (* l2 0.35))<br/>k2 (polar k1 (+ zj (* (/ 1.0 2.0) pi)) (/ l2 2.0))<br/>k3 (polar k1 (+ zj (* (/ 3.0 2.0) pi)) (/ l2 2.0))<br/>k4 (polar k1 zj (/ l2 2.0)));setq<br/>(command "line" p1 p2 p3 p4 p1 ""<br/>"line" k2 k3 ""<br/>"line" k1 zx ""<br/>"arc" k2 k4 k3);command<br/>(xzjd)<br/>(command "rotate" "c" kzx k4 "" zx zj)<br/>(dfw)<br/>);while<br/>(PRINC)<br/>)<br/>(defun flsz()<br/>(if (= fl "Y")<br/>(progn<br/>(setq p32 (polar zx (+ zj (* (/ -1.0 2.0) pi)) (* 3.0 *bl))<br/>p33 (polar zx (+ zj (* (/ 1.0 2.0) pi)) (* 3.0 *bl))<br/>pf1 (polar p32 (+ zj (* 0.0 pi)) (* 0.5 l1))<br/>pf2 (polar p32 (+ zj (* 1.0 pi)) (* 0.5 l1))<br/>pf3 (polar p33 (+ zj (* 1.0 pi)) (* 0.5 l1))<br/>pf4 (polar p33 (+ zj (* 0.0 pi)) (* 0.5 l1)));setq<br/>(command "break" p32 p33 "line" pf1 pf2 ""<br/>"line" pf3 pf4 "");command<br/>);progn<br/>(setq p32 (polar zx (+ zj (* (/ -1.0 2.0) pi)) l2)<br/>p33 (polar zx (+ zj (* (/ 1.0 2.0) pi)) l2));setq<br/>);if<br/>(princ)<br/>)<br/>(defun va( )<br/>(if (and (/= *bl nil) (/= *dwgscale nil))<br/>(progn<br/>(setvar "cmdecho" 0)<br/>(setvar "regenmode" 0)<br/>(setq cl (getvar "clayer"))<br/>(command "blipmode" "off"<br/>"fill" "on"<br/>"layer" "m" "va" "s" "va"<br/>"lt" "continuous" "" "c" "green" "" "");command<br/>(initget "Q Z J D X L Y G W S K")<br/>(if (not *fm) (setq *fm "J"))<br/>(princ "\n球Q/闸Z/截J/单D/旋X/节L/减Y/隔G/蝶W/疏S/控K < ")<br/>(princ *fm)<br/>(setq fm (getkword " >:"))<br/>(if (not fm) (setq fm *fm) (setq *fm fm))<br/>(cond ((= fm "Q") (qs) (dfw) (qf))<br/>((= fm "Z") (qs) (dfw) (zf))<br/>((= fm "J") (qs) (dfw) (jz))<br/>((= fm "D") (qs) (dfw) (dx))<br/>((= fm "X") (qs) (dfw) (xs))<br/>((= fm "L") (qs) (dfw) (jl))<br/>((= fm "Y") (qs) (dfw) (jy))<br/>((= fm "G") (qs) (dfw) (gm))<br/>((= fm "W") (qs) (dfw) (df))<br/>((= fm "S") (qs) (dfw) (ss))<br/>((= fm "K") (qs) (dfw) (kz)));cond<br/>(command "layer" "s" cl "")<br/>(setvar "regenmode" 1)<br/>(princ)<br/>)<br/>)<br/>);end<br/>(va)<br/>princ)<br/>)<br/>)<br/>);end<br/>(va) </p>
页:
[1]