找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3779|回复: 3

[AutoCAD] 求一个法兰LISP程序?

[复制链接]

40

主题

25

回帖

1416

积分

村里打铁的

UID
254
威望
0
机械币
267
活力
48
发表于 2011-6-29 13:34:10 | 显示全部楼层 |阅读模式
本帖最后由 无厌之求 于 2012-4-3 09:43 编辑

各位专家能否给我一个简单的法兰的LISP程序,让我学习一下,谢谢
        

3

主题

8

回帖

235

积分

机械厂工人

UID
154
威望
0
机械币
47
活力
0
发表于 2011-6-29 13:34:20 | 显示全部楼层

在这里应该有。楼主可以搜索一下,法兰主要就是读取数据库的问题。别的没有什么问题。
(defun c:falan()
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setq OS (GETVAR "OSMODE")) ;设置捕捉关闭
(setvar "OSMODE" 0)

(setq chklay (tblsearch "layer" "cen"))
(if (= chklay nil)
(command "layer" "n" "cen" "c" "1" "cen" "lt" "center2" "cen" "")
)
(setq chklay (tblsearch "layer" "dim"))
(if (= chklay nil)
(command "layer" "n" "dim" "c" "3" "dim" "")
)
(setq chklay (tblsearch "layer" "0"))
(if (= chklay nil)
(command "layer" "n" "0" "c" "7" "0" "")
)
(setq chksty (tblsearch "style" "技术要求")) ;确定文字样式
(if (= chksty nil)
(command "style" "技术要求" "ysr,hztxt" "" 0.75 "" "" "")
)



(huatu)
(setvar "OSMODE" os)
(prin1)
)
(defun huatu()
(setq dcl_id (load_dialog "falan"))
(if(< dcl_id 0) (exit))
(new_dialog "falan" dcl_id)
(set_tile "D7" "48.3") ;接管外径
(set_tile "D1" "41") ;法兰内径
(set_tile "D2" "155") ;法兰外径
(set_tile "D3" "114.5") ;螺栓孔位置
(set_tile "D4" "22") ;螺栓孔的直径
(set_tile "D5" "22.5") ;法兰厚度
(set_tile "D6" "70") ;法兰径的直径
(set_tile "H" "62") ;法兰高度
(set_tile "H2" "25") ;法兰径高度
(set_tile "R" "5") ;法兰倒圆弧半径
(set_tile "D9" "73") ;凸台内径
(set_tile "H3" "5") ;凹凸台的高度
(set_tile "D10" "74.5") ;凹台内径
(set_tile "D11" "80") ;凹台外径

(sub_rb1)
(set_tile "rb1" "1")

(sub_rb2)
(set_tile "rb2" "2")
(action_tile "rb1" "(sub_rb1)") ;添加图形
(action_tile "rb2" "(sub_rb2)")

(action_tile "aotu" "(getd)(done_dialog 1)")
(action_tile "ao" "(getd)(done_dialog 2)")
(action_tile "tu" "(getd)(done_dialog 3)")
(setq dd (start_dialog))
(cond ((= dd 1) (c:aotu))
((= dd 2) (c:ao))
((= dd 3) (c:tu))
(t (alert "<<<傻瓜,懒蛋什么也没画!>>>"))
)
)

(defun sub_rb1()
(setq ddtype 1)
(show_sld "aofl" "aofl")
)
(defun sub_rb2()
(setq ddtype 2)
(show_sld "tufl" "tufl")
)
(defun show_sld(key sld)
(setq x (dimx_tile key))
(setq y (dimy_tile key))
(start_image key)
(fill_image 0 0 x y -2)
(slide_image 0 0 x y sld)
(end_image)
)


(defun getd()
(setq D1 (atof (get_tile "D1")))
(setq D2 (atof (get_tile "D2")))
(setq D3 (atof (get_tile "D3")))
(setq D4 (atof (get_tile "D4")))
(setq D5 (atof (get_tile "D5")))
(setq D6 (atof (get_tile "D6")))
(setq D7 (atof (get_tile "D7")))

(setq D9 (atof (get_tile "D9")))
(setq D10 (atof (get_tile "D10")))
(setq D11 (atof (get_tile "D11")))
(setq H (atof (get_tile "H")))
(setq H2 (atof (get_tile "H2")))
(setq H3 (atof (get_tile "H3")))
(setq R (atof (get_tile "R")))
)
(defun c:aotu()
(setq A0 (getpoint"输入法兰的中心点:"))

(setq HE 5)
(dingdian)
(GONGYONG)
(command "pline" A6 A7 A8 B0 "")
(command "pline" A1 A9 "")
(MIRROR)
(biaozhu)
(FALZL)
(command "text" t1 "" 0 (strcat "凸面(突面)法兰重量=" (rtos Sz 2)))
(command "LAYER" "s" "0" "")
(setq At (polar A0 (* pi 1.5) (* h 6)))
(setq A0 at)
(dingdian)
(setq B8 (polar B0 0 (/ D10 2)))
(setq B9 (polar B0 0 (/ D11 2)))
(setq B6 (polar B1 0 (+ (/ D11 2) H3)))
(setq B7 (polar B1 0 (/ D10 2)))
(setq B5 (polar B1 0 (/ D1 2)))
(GONGYONG)
(command "pline" A6 B6 B9 B8 B0 "")
(command "pline" B8 B7 B5 b1 "")
(command "pline" A1 B5 "")
(MIRROR)
(biaozhu)
(FALZL)
(command "text" t1 "" 0 (strcat "凹面法兰重量=" (rtos Sa 2)))

)
(defun c:ao()
(setq A0 (getpoint"输入法兰的中心点:"))
(dingdian)
(setq B8 (polar B0 0 (/ D10 2)))
(setq B9 (polar B0 0 (/ D11 2)))
(setq B6 (polar B1 0 (/ D11 2)))
(setq B7 (polar B1 0 (/ D10 2)))
(setq B5 (polar B1 0 (/ D1 2)))
(setq t1 (polar B0 (* pi 0.5) 10))
(GONGYONG)
(command "pline" A6 B6 B9 B8 B0 "")
(command "pline" B8 B7 B5 b1 "")
(command "pline" A1 B5 "")
(MIRROR)
(biaozhu)
(FALZL)
(command "text" t1 "" 0 (strcat "凹面法兰重量=" (rtos Sa 2)))
)
(defun c:tu()
(setq A0 (getpoint"输入法兰的中心点:"))
(dingdian)
(GONGYONG)
(command "pline" A6 A7 A8 B0 "")
(command "pline" A1 A9 "")
(MIRROR)

(biaozhu)
(FALZL)
(command "text" t1 "" 0 (strcat "凸面(突面)法兰重量=" (rtos Sz 2)))

)

(defun biaozhu()
(command "LAYER" "s" "dim" "")

(command "dimlinear" A1 (polar A1 pi D1) "t" (strcat "%%c" (rtos D1 2)) (polar A0 (* pi 1.5) (+ D5 10)))
(command "dimlinear" A2 (polar A2 pi D7) "t" (strcat "%%c" (rtos D7 2)) (polar A0 (* pi 1.5) (+ D5 20)))
(command "dimlinear" A4 (polar A4 pi D6) "t" (strcat "%%c" (rtos D6 2)) (polar A0 (* pi 1.5) (+ D5 30)))
(command "dimlinear" A6 (polar A6 pi D2) "t" (strcat "%%c" (rtos D2 2)) (polar B0 (* pi 0.5) (+ D5 40)))
(command "dimlinear" A12 (polar A12 pi D3) "t" (strcat "%%c" (rtos D3 2)) (polar B0 (* pi 0.5) (+ D5 30)))

)

(defun dingdian() ;确定凸面法兰点位置

(setq A1 (polar A0 0 (/ D1 2)))
(setq B0 (polar A0 (* pi 0.5) H))
(setq B1 (polar B0 (* pi 1.5) H3))
(setq B2 (polar B1 (* pi 1.5) D5))
(setq A2 (polar A0 0 (/ D7 2)))
(setq A3 (polar A2 (/ pi 2) (- H H3 D5 H2)))
(setq A9 (polar B0 0 (/ D1 2)))
(setq A8 (polar B0 0 (/ D9 2)))
(setq A7 (polar A8 (* pi 1.5) H3))
(setq A6 (polar B1 0 (/ D2 2)))
(setq A5 (polar A6 (* pi 1.5) D5))
(setq A4 (polar B2 0 (/ D6 2)))
(setq A11 (polar B2 0 (/ D3 2)))
(setq A12 (polar B1 0 (/ D3 2)))
(setq A13 (polar A11 0 (/ D4 2)))
(setq A14 (polar A12 0 (/ D4 2)))
(setq A15 (polar A11 PI (/ D4 2)))
(setq A16 (polar A12 PI (/ D4 2)))
(setq t1 (polar B0 (* pi 0.5) 20))

)

(defun GONGYONG() ;公用段函数
(command "LAYER" "s" "0" "")
(command "pline" A0 A2 "")
(command "line" A2 A3 "")
(setq EN1 (ENTLAST))
(command "pline" A5 A6 "")
(command "line" A3 A4 "")
(setq EN2 (ENTLAST))
(command "line" A4 A5 "")
(setq EN3 (ENTLAST))
(command "FILLET" "R" R)
(command "FILLET" EN1 EN2)
(command "FILLET" "R" R)
(command "FILLET" EN2 EN3)

(command "pline" A13 A14 "")
(command "pline" A15 A16 "")
(command "LAYER" "s" "cen" "")
(command "pline" (polar A11 (* pi 1.5) 10) (polar A12 (* pi 0.5) 10) "")
;绘画中心线D5仅仅是中心线的起点确定
(command "pline" (polar A0 (* pi 1.5) D5) (polar B0 (* pi 0.5) D5) "")
(command "ZOOM" "E")
(command "LAYER" "s" "0" "")



)

(defun MIRROR()
(command "MIRROR" "C" (polar A0 (* pi 1.9) D2) (polar A9 (* pi 0.6) H3) "" A0 B0 "")
(command "ZOOM" "E")
(command "REGEN")

)

(defun FALZL() ;计算法兰重量
(Setq p (/ 7.85 1000000))
(setq s1 (/ (* pi D2 D2 D5) 4)) ;法兰盘重量
(setq s2 (/ (* pi D9 D9 h3) 4)) ;凸台的体积
(setq r7 (/ d7 2))
(setq r6 (/ d6 2))
(setq s31 (* pi h2 (+ (* r7 r7) (* r6 r6) (* r7 r6))))
(setq s3 (/ s31 3)) ;锥体的体积
(setq h4 (- h h2 h3 d5)) ;直段长度
(setq s4 (* pi r7 r7 h4)) ;直边段体积
(setq r1 (/ d1 2)) ;法兰内半径
(setq s10 (* pi r1 r1 (- h h3))) ;内部法兰多于体积1
(setq s11 (* pi r1 r1 h3)) ;凸台多余体积
(setq s5 (/ (* pi D11 D11 h3) 4)) ;凹台的外体积
(setq s6 (/ (* pi D10 D10 h3) 4)) ;凹台的外体积
(setq s7 (- s5 s6))

(setq sz1 (+ s1 s2 s3 s4))
(setq sz2 (- sz1 s10 s11))
(setq sz (* sz2 p))
(setq sa (- (+ s1 s3 s4 s7) s10))
(setq sa (* sa p))
)
(prompt"\n<<FALAN>>用于绘制法兰,先绘凸面法兰")
(prin1)

0

主题

10

回帖

10

积分

初入机械村

UID
63412
威望
0
机械币
2
活力
4
发表于 2019-7-30 16:06:10 | 显示全部楼层
;编程实例CH17-2.lsp圆形法兰
(defun C:DRAW1()
  (setq pt (getpoint "Enter circle center:\n"))
  (setq r1 3 r2 6 r3 9 r4 1.5)
  (setq ptt (polar Pt 0 (+ r3 2)))
;设置点划线所在层、颜色和线型
  (command "layer" "m" "center" "c" "3" "" "LT" "center" "" "")
  (set_ltscale 2)
  (command "LINE" pt ptt "")
  (command "select" pt "")
  (command "ARRAY" "p" "" "P" pt 8 360 "y")
  (command "CIRCLE" pt r2)
;设置轮廓线所在层、颜色和线型
  (command "layer" "m" "轮廓线" "c" "1" "" "")
  (command "CIRCLE" pt r1)
  (command "CIRCLE" pt r3)
  (command "CIRCLE" (polar pt 0  r2) r4)
;设置文字所在层、颜色和线型
  (command "ARRAY" "L" "" "P" PT 8 360 "N")
  (command "layer" "m" "文本层" "c" "4" "" "")
  (setq stpt (getpoint "输入文字书写位置:\n"))
  (command "-STYLE" "standard" "simsun.ttf" "" "" "" "" "")
  (command "text" "j" "mc" stpt "3.5" "0" "AutoLISP绘图实例" "")
;计算图形挖去圆孔后的面积
  (setq area (* PI (- (* r3 r3) (* r1 r1) (* 8 r4 r4))))
;在屏幕显示面积的计算结果
  (print "area value:")
  (prin1 area)
  (print \n)
;在屏幕上最大范围显示图形
  (command  "zoom" "e")
)
(defun set_ltscale(scale)
    (command "ltscale" scale)
)

0

主题

4

回帖

1

积分

防灌水审核

UID
64305
威望
0
机械币
0
活力
1
发表于 2019-9-25 10:40:52 | 显示全部楼层
好深奥啊 !
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|机械村 ( 渝ICP备17010994号-1|渝公网安备50022702001048号 )

GMT+8, 2024-11-23 05:53 , Processed in 0.015189 second(s), 3 queries , Gzip On, Redis On.

Powered by 机械村

Copyright © 2012- Jixiecun.com

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