明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1621|回复: 4

请高手帮忙

[复制链接]
发表于 2004-5-24 21:44:00 | 显示全部楼层 |阅读模式
网上down了一个绘制螺栓的lisp程序,加载运行后提示:错误: AutoCAD 变量设置被拒绝: "clayer" "xshx" 本人很菜,请各位高手看以下如何修改。 程序如下 ;绘制螺栓
;bolt.lsp (defun dtr (a)
(* pi (/ a 180.00))
) ;绘制螺栓头
(defun headface ()
(setq f (- d 0.025))
(setq dist1 (/ (- head_dia f) 2))
(setq pt27 (polar pt8 0 dist1))
(setq pt28 (polar pt7 (dtr 180) dist1))
(setq pt29 (polar pt9 0 dist1))
(setq pt30 (polar pt10 (dtr 180) dist1))
(command "line" pt29 pt27 "")
(command "line" pt30 pt28 "")
(setq pt31a (polar pt9 0 (/ DIST1 2)))
(SETQ pt31 (polar pt31a (dtr 90) (float (/ head_thick 10))))
(setq pt32a (polar pt2 (dtr 90) head_thick))
(setq pt32 (polar pt32a (dtr 90) (float (/ head_thick 10))))
(setq pt33a (polar pt30 0 (/ dist1 2)))
(setq pt33 (polar pt33a (dtr 90) (float (/ head_thick 10))))
(command "arc" pt29 pt31 pt9)
(command "arc" pt30 pt32 pt29)
(command "arc" pt10 pt33 pt30)
(command "erase" erase_ent "")
(command "line" pt31 pt33 "")
) ;绘制螺母
(defun nutface ()
(setq pt18 (polar pt14 0 dist1))
(setq pt17 (polar pt15 0 dist1))
(setq pt19 (polar pt13 pi dist1))
(setq pt20 (polar pt12 pi dist1))
(command "line" pt18 pt17 "")
(command "line" pt19 pt20 "")
(setq pt21a (polar pt15 0 (/ DIST1 2)))
(SETQ pt21 (polar pt21a (dtr 270) (float (/ nut_thick 20))))
(setq pt22 (polar pt11 (dtr 270) (float (/ nut_thick 10))))
(setq pt23a (polar pt20 0 (/ dist1 2)))
(setq pt23 (polar pt23a (dtr 270) (float (/ nut_thick 20))))
(command "arc" pt20 pt23 pt12)
(command "arc" pt17 pt22 pt20)
(setq e8 (entlast))
(command "arc" pt15 pt21 pt17)
(command "explode" ent )
(command "erase" pt11 "")
(command "line" pt21 pt23 "")
(setq dist2 (distance pt21 pt23))
(setq picpt (polar pt21 0 (/ dist2 2)))
(command "trim" e8 "" picpt "")
) ;绘制螺栓端部
(defun hexagon ()
(if (< l 6)
(setq thread_len (+ (* 2 d) 0.25))
(setq thread_len (+ (* 2 d) 0.5))
)
(if (> (* 2 d) l)
(setq thread_len (* 1.5 d))
)
(setq head_dia (* 2 d)) ;d为螺栓头宽度
(setq head_thick (* 0.66667 d)) ;d为螺栓头厚度
(setq nut_thick (* 0.9 d))
(setq halfdia (/ d 2))
(setq p1 (polar pt 0 (- halfdia 0.5)))
(setq p2 (polar p1 (dtr 90) thread_len))
(setq p3 (polar p2 pi (- d 1)))
(setq p4 (polar pt pi (- halfdia 0.5)))
(setq pt2 (polar pt (dtr 90) l))
(setq pt3 (polar pt2 0 (/ d 2)))
(setq pt4 (polar pt2 pi (/ d 2)))
(setq pt5 (polar pt 0 (/ d 2)))
(setq pt6 (polar pt pi (/ d 2)))
(setq pt7 (polar pt2 0 (/ head_dia 2)))
(setq pt8 (polar pt2 pi (/ head_dia 2)))
(setq pt9 (polar pt8 (dtr 90) head_thick))
(setq pt10 (polar pt7 (dtr 90) head_thick))
(setq p2a (polar p2 0 0.5))
(setq p3a (polar p3 pi 0.5))
(setq thpt1 (polar pt6 (dtr 90) 0.5))
(setq thpt2 (polar pt5 (dtr 90) 0.5))
(setvar "clayer" "xshx")
(command "line" p2 p1 "")
(command "line" p3 p4 "")
(setvar "clayer" "shx")
(command "line" p2a p3a "")
(command "pline" pt4 thpt1 p4 p1 thpt2 pt3 "")
(command "line" thpt1 thpt2 "")
(setq entit (entlast))
(setq pt11 (getpoint "\n选择螺母底部中心: "))
(setq pt12 (polar pt11 0 (/ head_dia 2)))
(setq pt13 (polar pt12 (dtr 90) nut_thick))
(setq pt14 (polar pt13 pi head_dia))
(setq pt15 (polar pt14 (dtr 270) nut_thick))
(command "line" pt10 pt7 pt8 pt9 "")
(command "pline" pt12 pt13 pt14 pt15 "c")
(setq ent (entlast))
(setq pt16 (polar pt (dtr 90) (+ l (* 3 head_thick))))
(command "circle" pt16 "d" (* 1.732 d) )
(command "polygon" "6" pt16 "c" (/ (* 1.732 d) 2))
) (defun hexagon1 ()
(if (< l 6)
(setq thread_len (+ (* 2 d) 0.25))
(setq thread_len (+ (* 2 d) 0.5))
)
(if (> (* 2 d) l)
(setq thread_len (* 1.5 d))
)
(setq head_dia (* 2 d)) ;d为螺栓头宽度
(setq head_thick (* 0.66667 d)) ;d为螺栓头厚度
(setq nut_thick (* 0.9 d))
(setq halfdia (/ d 2))
(setq p1 (polar pt 0 (- halfdia 0.5)))
(setq p2 (polar p1 (dtr 90) thread_len))
(setq p3 (polar p2 pi (- d 1)))
(setq p4 (polar pt pi (- halfdia 0.5)))
(setq pt2 (polar pt (dtr 90) l))
(setq pt3 (polar pt2 0 (/ d 2)))
(setq pt4 (polar pt2 pi (/ d 2)))
(setq pt5 (polar pt 0 (/ d 2)))
(setq pt6 (polar pt pi (/ d 2)))
(setq pt7 (polar pt2 0 (/ head_dia 2)))
(setq pt8 (polar pt2 pi (/ head_dia 2)))
(setq pt9 (polar pt8 (dtr 90) head_thick))
(setq pt10 (polar pt7 (dtr 90) head_thick))
(setq p2a (polar p2 0 0.5))
(setq p3a (polar p3 pi 0.5))
(setq thpt1 (polar pt6 (dtr 90) 0.5))
(setq thpt2 (polar pt5 (dtr 90) 0.5))
(setvar "clayer" "xshx")
(command "line" p2 p1 "")
(command "line" p3 p4 "")
(setvar "clayer" "shx")
(command "line" p2a p3a "")
(command "pline" pt4 thpt1 p4 p1 thpt2 pt3 "")
(command "line" thpt1 thpt2 "")
(setq entit (entlast))
(command "line" pt7 pt10 "")
(command "line" pt10 pt9 "")
(setq erase_ent(entlast))
(command "line" pt9 pt8 "")
(command "line" pt8 pt7 "" )
(setq entit (entlast))
(setq pt16 (polar pt (dtr 90) (+ l (* 3 head_thick))))
(command "circle" pt16 "d" (* 1.732 d) )
(command "polygon" "6" pt16 "c" (/ (* 1.732 d) 2))
) (defun C:bolt ()
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(setq snaps (getvar "snap"))
(setq l (getdist "\n输入螺栓长度: "))
(setq d (getdist "\n输入螺栓直径: "))
(setq new_snap (/ d 2))
(command "snap" new_snap)
(setq pt (getpoint "\n输入螺栓中心点: "))
(initget 1 "Y y n N")
(setq answer (getkword "\n需要螺母吗?(Y/N): "))
(if (= answer "Y")
(progn
(hexagon)
(headface)
(nutface)
)
(progn
(hexagon1)
(headface)
)
)
(setvar "snapmode" 0)
(setvar "osmode" 1023)
)
发表于 2004-5-24 21:46:00 | 显示全部楼层
程序我没有看,你运行程序前,先添加一个层吧,命名为xshx,再试一下
 楼主| 发表于 2004-5-24 21:53:00 | 显示全部楼层
谢谢指点。


新建层后仍出现错误提示,但画出两条直线,如螺栓直12,则两线间距11。


继续求教。
发表于 2004-5-24 23:56:00 | 显示全部楼层
再加一个层:shx
 楼主| 发表于 2004-5-25 21:53:00 | 显示全部楼层
按楼上指点可以绘出螺栓螺母了,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-6 02:49 , Processed in 0.194733 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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