化工工藝流程圖閥門程序設計
提要:本文針對化工工藝流程圖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 *** ( )
(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) (***))
((= 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在化工工藝設計中的運用。文后提供的程序清單可在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 *** ( )
(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) (***))
((= 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)
評論
查看更多