找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 422|回复: 0

[必看]:如何用AutoCAD绘制三维螺旋楼梯

[复制链接]
发表于 2003-2-17 20:30:41 | 显示全部楼层 |阅读模式

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

您需要 登录 才可以下载或查看,没有账号?立即注册

×
如何用AutoCAD绘制三维螺旋楼梯  

一、〖说明〗

  本例程能够绘制建筑中的三维螺旋楼梯。根据指定的参数:圆心点、梯级高、最窄梯级宽、楼梯宽度、扶手高、底板厚度和层高,程序将自动计算并绘制出以3dface和tabsurf组成的三维螺旋楼梯模型。程序能在R12至R14版的AutoCAD中运行。

二、〖安装〗

  将"程序代码"一节的文本裁剪下来,保存成名为"3DSP.LSP"的文本文件;将这个文件拷贝到AutoCAD的系统目录中。

三、〖使用〗

  在AutoCAD命令行键入:(load "3dsp")然后执行:3dsp,按程序中的提示操作即可。(程序中的提示已改为中文,若需要英文提示可自行修改提示字符串或跟我联系)

四、〖程序代码〗


;;;begain 3dsp.lsp
(defun dtr (r)
(* r (/ pi 180.0)))
(defun rtd (r)
(* r (/ 180.0 pi)))

(defun 3dsp_err (s)
(if (not (member s (list "console break"
"Function cancelled"
"quit/exit abort")))
(princ (strcat "\n3DSP Error:" s))
)
(if cmd (setvar "cmdecho" cmd))
(if bli (setvar "blipmode" bli))
(if cla (setvar "clayer" cla))
(if os1 (setvar "osmode" os1))
(princ)
)

(defun spinfo (/ ht) ; staircase parameter
(setq cp (getpoint "\n螺旋梯圆心点: ")
lp (getpoint cp "\n首级内圆起始点: ")
riser (getdist "\n梯级高: ")
step (getdist "\n内圆最窄梯级宽: ")
wide (getdist "\n楼梯宽度: ")
hrl (getdist "\n扶手高: ")
thi (getdist "\n底板厚度: ")
ht (getdist "\n层高: ")
case (fix (/ ht riser))
riser (/ ht case)
ls (sqrt (+ (expt riser 2) (expt step 2)))
a (/ riser ls) ; sin A
b (/ step ls) ; cos A
c lp
)
); end SPINFO

(defun spcalc (/ os1)
(setq os1 (getvar "osmode"))
(initget "L R B N")
(setq ans (getkword "\n选择扶手(L)左/(R)右/(B)双边/(N)无: "))
(if (not ans)(setq ans "N"))
(setq blksp (open "blksp.lst" "r"))
(if (not (equal blksp nil))
(setq blk (read-line blksp))
)
(if (equal blk nil)
(setq blk "sp1")
(setq blk (strcat "sp"
(itoa (1+ (atoi (substr blk 3)))))
)
)
(setq r (distance cp lp))
(setq ang (/ step r)) ; determines the angle of the step
(setq ac (angle cp lp))
(setq rp (polar lp ac wide)
lp1 (list (car lp) (cadr lp) riser)
lp4 (list (car rp) (cadr rp) riser)
count 0
el riser
al ang
)
(setq diag (+ ac ang))
(setq lp2 (list (car (polar cp diag r))
(cadr (polar cp diag r))
riser)
lp3 (list (car (polar cp diag (+ r wide)))
(cadr (polar cp diag (+ r wide)))
riser)
lh (polar cp (+ ac (/ ang 2)) (+ r (/ wide 15))) ; left bottom hrl
lh1 (list (car lh) (cadr lh) (+ (caddr lh) riser))
lh2 (list (car lh1) (cadr lh1) (+ (caddr lh1) hrl)); left top hrl
sht (polar cp diag (+ r (/ wide 15)))
shb (polar cp ac (+ r (/ wide 15)))
sh1 (list (car shb) (cadr shb) (+ (caddr shb) (+ hrl (/ riser 2))))
sh2 (list (car sht) (cadr sht) (+ (caddr sht) hrl (* riser 1.5)))
)
(setq tlp (list (car lp) (cadr lp) (- (caddr lp) (/ thi b)))
tl1 (list (car lp2) (cadr lp2) (- (caddr lp2) (/ thi b)))
trp (list (car rp) (cadr rp) (- (caddr rp) (/ thi b)))
tr1 (list (car lp3) (cadr lp3) (- (caddr lp3) (/ thi b))))
(command "layer" "m" "spiral" "" ; set spiral layer and color
"layer" "c" "blue" "" "")
(setvar "osmode" 0)
(command "3dface" lp1 "i" lp2 lp3 lp4 ""; draw the step
"3dface" lp lp1 lp4 rp "" ; draw the riser
"3dface" lp3 lp4 "i" rp "" "" ; draw the right side face
"3dface" lp2 lp1 "i" lp "" "" ; draw the left side face
"3dface" "i" trp "i" rp "i" lp3 tr1 ""; draw the thickness
"3dface" "i" tlp "i" lp "i" lp2 tl1 ""
"3dface" "i" trp tlp "i" tl1 tr1 ""); draw the bottom face
(command "layer" "m" "scolumn" "" ; set handrail column layer
"layer" "c" "cyan" "" "" ; and color
"layer" "m" "shandrail" "" ; set handrail layer and
"layer" "c" "red" "" "") ; and color
(if (or (= ans "L") (= ans "B"))
(progn
(command "layer" "s" "scolumn" "")
(command "circle" lh1 (/ step 18)) ; draw the handrail column
(setq cir (entlast))
(command "line" lh1 lh2 "")
(setq lc (entlast))
(command "tabsurf" (list cir lh1) (list lc lh1))
(setq tcl (entlast))
(command "layer" "s" "shandrail" "")
(command "circle" sh1 (/ step 15) ; draw the handrail
"ucs" "y" 90)
(setq c1 (entlast)) (setq sh1r (trans sh1 0 1))
(command "rotate" c1 "" sh1r (rtd (- b))
"ucs" "")
(command "line" sh1 sh2 "")
(setq l1 (entlast))
(command "tabsurf" (list c1 sh1) (list l1 sh1))
(setq thl (entlast))
)
)
(if (or (= ans "R")(= ans "B"))
(progn ; draw the right handrail
(setq dis (- wide (* 2 (/ wide 15)))
sr1 (polar sh1 ac dis)
sr2 (polar sh2 diag dis)
rh1 (polar lh1 (+ ac (/ ang 2)) dis)
rh2 (polar lh2 (+ ac (/ ang 2)) dis )
)
(command "layer" "s" "scolumn" "")
(command "circle" rh1 (/ step 18))
(setq cir1 (entlast))
(command "line" rh1 rh2 "")
(setq rc (entlast))
(command "tabsurf" (list cir1 rh1) (list rc rh1))
(setq tcr (entlast))
(command "layer" "s" "shandrail" "")
(command "circle" sr1 (/ step 15)
"ucs" "y" 90)
(setq c2 (entlast)) (setq sr1r (trans sr1 0 1))
(command "rotate" c2 "" sr1r (rtd (- b)) "ucs" ""
"circle" sr2 (/ step 15)
"ucs" "y" 90)
(setq c3 (entlast)) (setq sr2r (trans sr2 0 1))
(command "rotate" c3 "" sr2r (rtd (- b))
"ucs" "")
(command "line" sr1 rh2 "") (setq l2 (entlast))
(command "line" rh2 sr2 "") (setq l3 (entlast))
(command "tabsurf" (list c2 sr1) (list l2 sr1)
"tabsurf" (list c3 sr2) (list l3 sr2))
(setq thr (entlast))))
(if (= ans "L")
(command "block" blk lp "c" tlp lp4 tr1 tcl thl "" "oops"))
(if (= ans "R")
(command "block" blk lp "c" tlp lp4 tr1 tcr thr "" "oops"))
(if (= ans "B")
(command "block" blk lp "c" tlp lp4 tr1 tcl tcr thl thr "" "oops"))
(if (= ans "N")
(command "block" blk lp "c" tlp lp4 tr1 "" "oops"))
(setvar "clayer" cla)
(setq count (1+ count) ; initialize counters for loop
lp (list (car (polar cp diag r))
(cadr (polar cp diag r))
riser
)
riser (+ riser el)
diag (+ ang ang ac)
)
(setvar "osmode" os1)
) ; end SPCALC

(defun sbuild (/ os1)

(command "INSERT" blk lp "" "" (rtd ang))
(setq lp (list (car (polar cp diag r))
(cadr (polar cp diag r))
riser)
count (1+ count) ; increment all counters
ang (+ ang al)
diag (+ diag al)
riser (+ riser el)
)
(if (< count case) ; get last set of coordinates
(progn ; to form ending face
(setq lp2 (list (car (polar cp diag r))
(cadr (polar cp diag r))
riser)
lp3 (list (car (polar cp diag (+ r wide)))
(cadr (polar cp diag (+ r wide)))
riser)
tl1 (list (car lp2) (cadr lp2)
(- (caddr lp2) (/ thi b)))
tr1 (list (car lp3) (cadr lp3) (- (caddr lp3) (/ thi b)))
)
)
)
) ; end SBUILD

(defun C:3DSP (/ bli cmd cla blksp cp lp riser step wide count
hrl blk thi lp1 lp2 lp3 lp4 case el rp diag al
ang a tr1 tl1 os1 olderr)
(setq olderr *error* *error* 3dsp_err)
(setq bli (getvar "blipmode")
cmd (getvar "cmdecho")
cla (getvar "clayer")
)
(setvar "blipmode" 0)
(setvar "cmdecho" 0)

(setq os1 (getvar "osmode" os1))
(setvar "osmode" 0)

(spinfo)
(spcalc)

(while (< count case)
(sbuild)
)
(command "layer" "s" "spiral" "" ; draw ending face
"3dface" "i" lp3 tr1 "i" tl1 "i" lp2 "")
(setvar "cecolor" "bylayer")
(setvar "blipmode" bli)
(setvar "cmdecho" cmd)
(setvar "clayer" cla)
(if (not (equal blksp nil))
(close blksp)
)
(setq blksp
(open "blksp.lst" "w")
)
(write-line blk blksp)
(close blksp)

(setvar "osmode" os1)
(setq *error* olderr)
(princ)
) ; end SP.LSP
(princ "\n**3D Spiral Stair Maker loaded, type '3dsp' to start.")
(princ)
;;;end 3dsp.lsp
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-17 22:33 , Processed in 0.176216 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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