(defun DRAW_END_CAP (/ BA# BF# BF1# BF2# BF3# CUS DCL_ID DUNT$ FLG# HTHK$ HTHK# HOD$ HOD# HID# HOD_LST ;
HTHK_LST IDR# IKR# INPT IANG LNAM$ LOOP$ SFLG$ SFLG# SFLG_LST THKL$ VRT# bf4# bf5# bf6#)
;
; (setq DH:HOD$ (rtos N6)) ;default OD dia, take from DIM file
; (setq DH:HTHK$ (rtos N9)) ;default wall thickness, take from DIM file
; (setq DH:SFLG$ (rtos N3)) ;default Straight Flange (required), take from DIM file
(setq DH:HOD$ "610.0")
(setq DH:HTHK$ "12.7")
(setq DH:SFLG$ "138")
(setq INPT (getpoint "\nSpecify Insertion point of End Cap: "))
(setq IANG (getpoint INPT "\nDrag cursor to select head orientation angle.")
INPT (trans INPT 1 0)
IANG (trans IANG 1 0)
)
(DH_SSP)
) ;end DRAW_END_CAP
;
; Set Size Parameters Function.
;
(defun DH_SSP ()
(setq HOD$ DH:HOD$ ;HOD$ is the main OD.
HTHK$ DH:HTHK$ ;HTHK# is the wall thickness.
SFLG$ DH:SFLG$ ;SFLG$ is the flange straight length.
HOD# (distof HOD$ 2) ;distof converts string to real value, with 2 = decimal
HTHK# (distof HTHK$ 2)
SFLG# (distof SFLG$ 2)
HID# (- HOD# (* HTHK# 2))
THKL$ DH:THKL$)
;
(setq IDR# (* HID# 0.9045) ;Head Rad ; change these if require to get profile shape (* HID# 0.9045)
IKR# (* HID# 0.1727) ;Knuckle Rad ; change these if require to get profile shape (* HID# 0.1727)
)
(DH_CDH)
)
;
; - Calculate Dished Head Function.
;
(defun DH_CDH (/ A1# A2# BA# CP01 CP02 CP03 DEG# PT01 PT02 PT03 PT04 PT05 PT06 PT07 PT08 PT09
RAD# RAD#A Sa# Sa2# Sb# Sc# TP01 TP02 TP03 TP04)
;
(setq RAD# (angle INPT IANG)
DEG# (DH_RTD RAD#))
;
(setq Sb# (- (/ HID# 2.0) IKR#)
Sc# (- IDR# IKR#)
Sa2# (- (* Sc# Sc#)(* Sb# Sb#))
Sa# (sqrt Sa2#)
RAD#A (/ Sb# Sc#)
A1# (DH_RTD RAD#A)
A2# (- 360 A1#)
);end setq
;
(setq BA# (list -64.3743 -52.7755)) ;part of LWPolyline bulge calculation
;
(setq PT01 (polar INPT (DH_DTR (+ DEG# 90))(/ HID# 2)) ;from insertion point.
PT03 (polar PT01 (DH_DTR (+ DEG# 0)) SFLG#)
PT02 (polar INPT (DH_DTR (+ DEG# 270))(/ HID# 2)) ;from insertion point.
PT04 (polar PT02 (DH_DTR (+ DEG# 0)) SFLG#)
PT05 (polar PT01 (DH_DTR (+ DEG# 90)) HTHK#)
PT07 (polar PT05 (DH_DTR (+ DEG# 0)) SFLG#)
PT06 (polar PT02 (DH_DTR (+ DEG# 270)) HTHK#)
PT08 (polar PT06 (DH_DTR (+ DEG# 0)) SFLG#)
PT09 (polar INPT (DH_DTR (+ DEG# 0)) SFLG#)
CP01 (polar PT03 (DH_DTR (+ DEG# 270)) IKR#)
CP02 (polar PT09 (DH_DTR (+ DEG# 180)) Sa#)
CP03 (polar PT04 (DH_DTR (+ DEG# 90)) IKR#)
TP01 (polar CP01 (DH_DTR (+ DEG# A1#)) IKR#)
TP03 (polar CP01 (DH_DTR (+ DEG# A1#))(+ IKR# HTHK#))
TP02 (polar CP03 (DH_DTR (+ DEG# A2#)) IKR#)
TP04 (polar CP03 (DH_DTR (+ DEG# A2#))(+ IKR# HTHK#))
BF1# (DH_ETC (/ (DH_DTR (nth 0 BA#)) 4)) ;bulge factor for curved lwpolylines
BF2# (DH_ETC (/ (DH_DTR (nth 1 BA#)) 4)) ;bulge factor for curved lwpolylines
BF3# (DH_ETC (/ (DH_DTR (nth 0 BA#)) 4)) ;bulge factor for curved lwpolylines
bf4# (* bf1# -1)
bf5# (* bf2# -1)
bf6# (* bf3# -1)
)
(DH_OLL) ; outside arc Point/Bulge list (DH_OLL)
)
;
; - Outline List Function.
;
(defun DH_OLL ()
(setq VRT# (list PT01 PT05 PT07 TP03 TP04 PT08 PT06 PT02 pt04 tp02 tp01 pt03)
BF# (list 0.0 0.0 BF1# BF2# BF3# 0.0 0.0 0.0 bf6# bf5# bf4# 0.0) FLG# 1)
(DH_DDH)
)
;
; - Draw Dished Head Function.
;
(defun DH_DDH ()
(entmakex
(list
(cons 0 "LWPOLYLINE") ;defines draw a LWPOLYLINE remember ""'s
(cons 100 "AcDbEntity") ;defines draw an entity
;-----------(cons 8 LNAM) ;defines the layer specifics, if ommited uses default (is that current?)
(cons 100 "AcDbPolyline") ;defines draw a LWPOLYLINE
(cons 90 (length VRT#))
(cons 70 1)
(cons 10 PT01) ;(cons 10 PNT number)
(cons 42 0.0) ;(cons 42 BF number)
(cons 10 PT05)
(cons 42 0.0)
(cons 10 PT07)
(cons 42 BF1#)
(cons 10 TP03)
(cons 42 BF2#)
(cons 10 TP04)
(cons 42 BF3#)
(cons 10 PT08)
(cons 42 0.0)
(cons 10 PT06)
(cons 42 0.0)
(cons 10 PT02)
(cons 42 0.0)
(cons 10 PT04)
(cons 42 BF6#)
(cons 10 TP02)
(cons 42 BF5#)
(cons 10 TP01)
(cons 42 BF4#)
(cons 10 PT03)
(cons 42 0.0)
)
)
;--------------------------------------------------------------------
; - draw 3D end Cap
(progn
(command "ucs" "ZA" INPT IANG)
(setq ENT1 (entlast))
(command "revolve" ENT1 "" "0,0,0" "0,0,100" "180") ; aim is for this (command "revolve" ENT1 INPT IANG "180")
(command "ucs" "_P")
)
)
;
; degree To Radians
;
(defun DH_DTR (a)(* pi (/ a 180.0)))
;
; Radian To Degrees
;
(defun DH_RTD (RAD#)(* 180.0 (/ RAD# pi)))
;
; Elbow Tangent Calculation Function.
;
(defun DH_ETC (a) (/ (sin a) (cos a)))
;
Just over a week ago I posted on Cadtutor asking for help with modifying code from their forum.I found many error/s inside yoursource.lisp
Unfortunately I've had no replies.
Now I did contact their Admin to ask if copying/modifying code from their site was OK before posting, the reply was yes.**3)I recovery all math'equation/s for C++, C# compatibilty
/*c2s: rad23=angle(inpt,iang),
deg23=dh_rtd(rad23),
sb23=(hid23/2.0)-ikr23),
sc23= (idr23-ikr23),
sa223=((sc23*sc23)- (sb23*sb23)),
sa23=sqrt(sa223),
rad23a=(sb23/sc23),
a123=dh_rtd(rad23a),
a223=(360-a123);
ba23=list(-64.3743,-52.7755),
wsahelp=";part of lwpolyline bulge calculation";
pt01=polar(inpt,dh_dtr( (deg23+90)), (hid23/2)),
wsahelp=";from insertion point",
pt03=polar(pt01,dh_dtr( (deg23+0)),sflg23),
pt02=polar(inpt,dh_dtr( (deg23+270)), (hid23/2)),
wsahelp=";from insertion point",
pt04=polar(pt02,dh_dtr( (deg23+0)),sflg23),
pt05=polar(pt01,dh_dtr( (deg23+90)),hthk23),
pt07=polar(pt05,dh_dtr( (deg23+0)),sflg23),
pt06=polar(pt02,dh_dtr( (deg23+270)),hthk23),
pt08=polar(pt06,dh_dtr( (deg23+0)),sflg23),
pt09=polar(inpt,dh_dtr( (deg23+0)),sflg23),
cp01=polar(pt03,dh_dtr( (deg23+270)),ikr23),
cp02=polar(pt09,dh_dtr( (deg23+180)),sa23),
cp03=polar(pt04,dh_dtr( (deg23+90)),ikr23),
tp01=polar(cp01,dh_dtr( (deg23+a123)),ikr23),
tp03=polar(cp01,dh_dtr( (deg23+a123)), (ikr23+hthk23)),
tp02=polar(cp03,dh_dtr( (deg23+a223)),ikr23),
tp04=polar(cp03,dh_dtr( (deg23+a223)), (ikr23+hthk23)),
bf123=dh_etc( (dh_dtr(nth(0,ba23))/4)),
wsahelp=";bulge factor for curved lwpolylines",
bf223=dh_etc( (dh_dtr(nth(1,ba23))/4)),
wsahelp=";bulge factor for curved lwpolylines",
bf323=dh_etc( (dh_dtr(nth(0,ba23))/4)),
wsahelp=";bulge factor for curved lwpolylines",
bf423= (bf123*-1),bf523= (bf223*-1),bf623= (bf323*-1);
dh_oll("outside arc point/bulge list")
*/
/*c2s: hod24=dh_hod24,
wsahelp="hod24 is the main od",
hthk24=dh_hthk24,
wsahelp=";hthk23 is the wall thickness.",
sflg24=dh_sflg24,
wsahelp=";sflg24 is the flange straight length.",
hod23=distof(hod24,2),
hthk23=distof(hthk24,2),
sflg23=distof(sflg24,2),
hid23= (hod23- (hthk23*2)),
thkl24=dh_thkl24;
idr23= (hid23*0.9045),
wsahelp=";head rad\011\011; change these if require to get profile shape (* hid23 0.9045)",
ikr23= (hid23*0.1727),
wsahelp=";knuckle rad\011; change these if require to get profile shape (* hid23 0.1727)";
$rr=dh_cdh();
*/
/*c2s: dh_hod24="610.0",
dh_hthk24="12.7",
dh_sflg24="138",
inpt=getpoint("\nspecify insertion point of end cap: ");
iang=getpoint(inpt,"\ndrag cursor to select head orientation angle."),
inpt=trans(inpt,1,0),
iang=trans(iang,1,0);
dh_ssp();
*/
The left end cap (red) was created by the earlier lisp code by selecting the end point of the white line as the insertion point and the end of the vertical yellow line as the orientation point. The end cap is created as expected.**4) you must use (princ ..) after (entmakex......)
The Right hand (closed lwpolyline) shape was created by selecting the RH end point of the blue line as the insertion point and the LH endpoint of the same line as the orientation point.
(setq $rr (entlast))
(setq doublecheck (entmakex (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length vrt23)) (cons 70 1) (cons 10 pt01) (cons 42 0.0) (cons 10 pt05) (cons 42 0.0) (cons 10 pt07) (cons 42 bf123) (cons 10 tp03) (cons 42 bf223) (cons 10 tp04) (cons 42 bf323) (cons 10 pt08) (cons 42 0.0) (cons 10 pt06) (cons 42 0.0) (cons 10 pt02) (cons 42 0.0) (cons 10 pt04) (cons 42 bf623) (cons 10 tp02) (cons 42 bf523) (cons 10 tp01) (cons 42 bf423) (cons 10 pt03) (cons 42 0.0)))
(princ)
**5) for(;dyn!="N";)
{ dyn=dfn_getx_readkey("[YRLFB10Nn]","\nDo you wish RevolveOptions?(Y.revolve)(R.right)(L.left)\n(F.forw)(B.backz)(P.pow)(1.allone)(N.needexit):");
if (dyn=="R") command("-vpoint","1,0,0");else
if (dyn=="L") command("-vpoint","-1,0,0");else
if (dyn=="F") command("-vpoint","0,-1,0");else
if (dyn=="B") command("-vpoint","0,1,0");else
if (dyn=="P") command("-vpoint","0,0,1");else
if (dyn=="1") command("_.vpoint","1,1,1");else
if (dyn=="Y")
{ command("ucs","ZA",INpt,IANG);
command("revolve",ent1,"","0,0,0","0,0,100","180");
command("ucs","_P");
dyn="0";
};
if (dyn=="0")
vla.Regen(con_acdoc,acActiveViewport);
};
@d2010
Thank you for your post, it will take me a bit of time to digest as there is quite a lot I do not understand.
Sample drawing attached, one is 2007 & the other is 2010 (my default, for compatibility with other software)
Steve
(F.forw)(B.backz)(P.pow)(1.allone)(N.needexit):F-vpoint Unknown command
"-VPOINT". Press F1 for help.
Command: 0,-1,0 Unknown command "0,-1,0". Press F1 for help.
Command:
Do you wish RevolveOptions?(Y.revolve)(R.right)(L.left)
(F.forw)(B.backz)(P.pow)(1.allone)(N.needexit):B-vpoint Unknown command
"-VPOINT". Press F1 for help.
Command: 0,1,0 Unknown command "0,1,0". Press F1 for help.
C:Q1=I need help, why the command("VPOint"..) not exists?This exists within the CAD package (CMS Intellicad 10).
;-----------------------------------------------------------------------;
; copied and modified code from https://www.cadtutor.net/forum/topic/20659-pressure-vessel-dished-head-lisp
;
(defun DRAW_END_CAP (/ BA# BF# BF1# BF2# BF3# CUS DCL_ID DUNT$ FLG# HTHK$ HTHK# HOD$ HOD# HID# ;
IDR# IKR# INPT IANG LNAM$ SFLG$ SFLG# THKL$ VRT# bf4# bf5# bf6# ENT1 ENT2)
;
(setq DH:HOD$ (rtos N6)) ;default OD dia, take from DIM file
(setq DH:HTHK$ (rtos N9)) ;default wall thickness, take from DIM file
(setq DH:SFLG$ (rtos N3)) ;default Straight Flange (required), take from DIM file
(setq EC1 (nth 1 SIZE_DIMS))
;
(setq INPT (getpoint "\nSpecify Insertion point of Fittng: "))
(setq IANG (getpoint INPT "\nDrag cursor to select Fitting orientation angle. ")
INPT (trans INPT 1 0) ; translates INPT from UCS to WORLD???
IANG (trans IANG 1 0)
)
(DH_SSP)
) ;end DRAW_END_CAP
;
; Set Size Parameters Function.
;
(defun DH_SSP ()
(setq HOD$ DH:HOD$ ;HOD$ is the main OD.
HTHK$ DH:HTHK$ ;HTHK# is the wall thickness.
SFLG$ DH:SFLG$ ;SFLG$ is the flange straight length.
HOD# (distof HOD$ 2) ;distof converts string to real value, with 2 = decimal
HTHK# (distof HTHK$ 2)
SFLG# (distof SFLG$ 2)
HID# (- HOD# (* HTHK# 2))
THKL$ DH:THKL$)
;
(setq IDR# (* HID# 0.9045) ;Head Rad ; change these if require to get profile shape (* HID# 0.9045)
IKR# (* HID# 0.1727) ;Knuckle Rad ; change these if require to get profile shape (* HID# 0.1727)
)
(DH_CDH)
)
;
; - Calculate Dished Head Function.
;
(defun DH_CDH (/ A1# A2# BA# CP01 CP02 CP03 DEG# PT01 pt01z1 PT02 pt02z1 PT03 pt03z1 PT04 pt04z1 PT05 PT06 PT07 PT08 PT09
RAD# RAD#A Sa# Sa2# Sb# Sc# TP01 tp01z1 TP02 tp02z1 TP03 TP04 P1 P2)
;
(setq ORIG (GETVAR 'UCSORG)) ;UCS ORG co-ords
(setq P1 ORIG)
(setq P2 (list 100 0 0))
;
; (setq RAD# (angle INPT IANG)
(setq RAD# (angle P1 P2)
DEG# (DH_RTD RAD#))
;
(setq Sb# (- (/ HID# 2.0) IKR#)
Sc# (- IDR# IKR#)
Sa2# (- (* Sc# Sc#)(* Sb# Sb#))
Sa# (sqrt Sa2#)
RAD#A (/ Sb# Sc#)
A1# (DH_RTD RAD#A)
A2# (- 360 A1#)
);end setq
;
(setq BA# (list -64.3743 -52.7755)) ;part of LWPolyline bulge calculation
;
(setq PT01 (polar ORIG (DH_DTR (+ DEG# 90))(/ HID# 2)) ;from insertion point.
PT01z1 (POLAR PT01 (DH_DTR (+ DEG# 342))(* 1.5 HTHK#))
PT03 (polar PT01 (DH_DTR (+ DEG# 0)) SFLG#)
PT03z1 (polar PT01z1 (DH_DTR (+ DEG# 0))(- SFLG# (* 1.5 HTHK#)))
PT02 (polar ORIG (DH_DTR (+ DEG# 270))(/ HID# 2)) ;from insertion point.
PT02z1 (POLAR PT02 (DH_DTR (+ DEG# 18))(* 1.5 HTHK#))
PT04 (polar PT02 (DH_DTR (+ DEG# 0)) SFLG#)
PT04z1 (polar PT02z1 (DH_DTR (+ DEG# 0))(- SFLG# (* 1.5 HTHK#)))
PT05 (polar PT01 (DH_DTR (+ DEG# 90)) HTHK#)
PT07 (polar PT05 (DH_DTR (+ DEG# 0)) SFLG#)
PT06 (polar PT02 (DH_DTR (+ DEG# 270)) HTHK#)
PT08 (polar PT06 (DH_DTR (+ DEG# 0)) SFLG#)
PT09 (polar ORIG (DH_DTR (+ DEG# 0)) SFLG#)
CP01 (polar PT03 (DH_DTR (+ DEG# 270)) IKR#)
CP02 (polar PT09 (DH_DTR (+ DEG# 180)) Sa#)
CP03 (polar PT04 (DH_DTR (+ DEG# 90)) IKR#)
TP01z1 (polar CP01 (DH_DTR (+ DEG# A1#))(- IKR# (* 0.5 HTHK#)))
TP03 (polar CP01 (DH_DTR (+ DEG# A1#))(+ IKR# HTHK#))
TP02z1 (polar CP03 (DH_DTR (+ DEG# A2#))(- IKR# (* 0.5 HTHK#)))
TP04 (polar CP03 (DH_DTR (+ DEG# A2#))(+ IKR# HTHK#))
BF1# (DH_ETC (/ (DH_DTR (nth 0 BA#)) 4)) ;bulge factor for curved lwpolylines
BF2# (DH_ETC (/ (DH_DTR (nth 1 BA#)) 4)) ;bulge factor for curved lwpolylines
BF3# (DH_ETC (/ (DH_DTR (nth 0 BA#)) 4)) ;bulge factor for curved lwpolylines
bf4# (* bf1# -1)
bf5# (* bf2# -1)
bf6# (* bf3# -1)
)
(DH_OLL) ; outside arc Point/Bulge list
)
;
; - Outline List Function.
;
(defun DH_OLL ()
(setq VRT# (list PT01 PT05 PT07 TP03 TP04 PT08 PT06 PT02 PT02z1 pt04z1 tp02z1 tp01z1 pt03z1 PT01z1)
BF# (list 0.0 0.0 0.0 BF1# BF2# BF3# 0.0 0.0 0.0 0.0 bf6# bf5# bf4# 0.0) FLG# 1)
(DH_DDH)
)
;
; - Draw Dished Head Profile Function.
;
(defun DH_DDH ( / ENT1 ENT2 )
(entmakex
(list
(cons 0 "LWPOLYLINE") ;defines draw a LWPOLYLINE remember ""'s
(cons 100 "AcDbEntity") ;defines draw an entity
;-----------(cons 8 LNAM) ;defines the layer specifics, if ommited uses default (is that current?)
(cons 100 "AcDbPolyline") ;defines draw a LWPOLYLINE
(cons 90 (length VRT#))
(cons 70 1) ; 1 for closed 0 overwise
(cons 10 PT01) ;(cons 10 PNT number)
(cons 42 0.0) ;(cons 42 BF number)
(cons 10 PT05)
(cons 42 0.0)
(cons 10 PT07)
(cons 42 BF1#)
(cons 10 TP03)
(cons 42 BF2#)
(cons 10 TP04)
(cons 42 BF3#)
(cons 10 PT08)
(cons 42 0.0)
(cons 10 PT06)
(cons 42 0.0)
(cons 10 PT02)
(cons 42 0.0)
(cons 10 PT02z1)
(cons 42 0.0)
(cons 10 PT04z1)
(cons 42 BF6#)
(cons 10 TP02z1)
(cons 42 BF5#)
(cons 10 TP01z1)
(cons 42 BF4#)
(cons 10 PT03z1)
(cons 42 0.0)
(cons 10 PT01z1)
(cons 42 0.0)
)
)
;--------------------------------------------------------------------
; - draw 3D end Cap
(progn
(command "ucs" "w" "")
(setq ENT1 (entlast))
(command "revolve" ENT1 "" "0,0,0" "100,0,0" "180")
(setq ENT2 (entlast))
(command "erase" ENT1 "")
(command "-block" EC1 "0,0,0" "L" "")
(command "erase" ENT2 "")
(command "ucs" "ZA" INPT IANG)
(command "insert" EC1 "0,0,0" "" "" "90")
(COMMAND "_ROTATE3D" "L" "" "x" "0,0,0" "90") ;"x" INPT "90")
(command "ucs" "w" "")
)
)
;
; degree To Radians
(defun DH_DTR (a)(* pi (/ a 180.0)))
;
; Radian To Degrees
(defun DH_RTD (RAD#)(* 180.0 (/ RAD# pi)))
;
; Elbow Tangent Calculation Function.
(defun DH_ETC (a) (/ (sin a) (cos a)))
Select objects: L 1 found
Select objects:
Specify first point on axis or define axis by
[Object/Last/View/Xaxis/Yaxis/Zaxis/2points]: x Specify a point on the X axis
<0,0,0>: 0,0,0
Specify rotation angle or [Reference]: 90
Command: ucs
Current ucs name: *NO NAME*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis]
<World>: w
Command:
RevolveOptions?(1.revolve)(R.right)(L.left)
(F.forw)(B.backz)(P.pow)(o.1+1+1)(N.
Hi All.Update:I have made progress and now have the End Caps working, though probably not as slick as some, but working
; - draw 3D end Cap
(progn
(command "ucs" "w" "")
(setq ENT1 (entlast))
; (command "revolve" ENT1 "" "0,0,0" "100,0,0" "180")
; (setq ENT2 (entlast))
; (command "erase" ENT1 "")
; (command "-block" EC1 "0,0,0" "L" "")
; (command "erase" ENT2 "")
; (command "ucs" "ZA" INPT IANG)
; (command "insert" EC1 "0,0,0" "" "" "90")
; (COMMAND "_ROTATE3D" "L" "" "x" "0,0,0" "90")
; (command "ucs" "w" "")
)
)