lisp编程 滑动轴承的auto_「autolisp」Autolisp:利用AuoCAD之Lisp编程案例之智能加工齿轮的演示程序 - seo实验室...

本文介绍了一篇关于使用AutoCAD的Lisp编程案例,详细展示了如何编写一个智能加工齿轮的演示程序。通过对话框设置模数、齿数、压力角等参数,并进行齿轮的绘制和参数显示。程序包括齿条轮廓线绘制、面域处理和参数读取等功能。
摘要由CSDN通过智能技术生成

autolisp

Autolisp:利用AuoCAD之Lisp编程案例之智能加工齿轮的演示程序

目录

实现结果

实现代码

实现结果

实现代码

(defun dlg1();初始化对话一

(set_tile "_m" "5");模数列表第6项

(set_tile "_z" "20");齿数20

(set_tile "_alf" "2");压力角第3项

(set_tile "s_z" "20");齿数滑动条

(set_tile "cut" "2");齿廓列表第3项

(action_tile "_m" "(setq msh_ $value)")

(action_tile "s_z" "(fsz)")

(action_tile "_z" "(fz)")

(action_tile "s_x" "(fs_x)")

(action_tile "_x" "(f_x)")

(action_tile "_alf" "(setq ylj_ $value)")

(action_tile "prec0" "(setq qxcsh 5)")

(action_tile "prec1" "(setq qxcsh 10)")

(action_tile "prec2" "(setq qxcsh 15)")

(action_tile "accept" "(getd)(done_dialog 1)")

(action_tile "cancel" "(done_dialog 0)")

(action_tile "help" "(dlg3)")

)

;定义获取控件当前数据的函数

(defun getd()

(setq msh_ (get_tile "_m"))

(setq msh (atof(nth (atoi msh_) m_lst)));模数

(setq ylj_ (get_tile "_alf"))

(setq ylj (atof(nth (atoi ylj_) alf_lst)));压力角

(setq bwxsh(atof(get_tile "_x")));变位系数

(setq chsh(atoi(get_tile "_z")));齿数

)

;定义齿数编辑框的活动的函数

(defun fz(/ gz)

(setq gz(atoi $value))

(if (or (< gz 9)(> gz 100))

(progn

(set_tile $key (get_tile "s_z"))

(setq chsh(atoi $value))

)

(progn

(set_tile "s_z" (itoa gz))

(setq chsh gz)

)

)

)

;定义齿数滑动条的活动的函数

(defun fsz()

(set_tile "_z" $value)

(setq chsh (atoi $value))

)

;定义变位系数滑动条的活动的函数

(defun fs_x(/ xx)

(setq xx (atof $value))

(setq bwxsh(* 0.01 xx))

(setq xx(rtos bwxsh 2 2))

(set_tile "_x" xx)

)

;定义变位系数编辑框的活动的函数

(defun f_x(/ xx )

(setq xx(atof $value))

(if (or (< xx -1)(> xx 1))

(progn

(setq xx (get_tile "s_x"))

(setq xx(atof xx))

(setq bwxsh(* 0.01 xx))

(set_tile $key (rtos bwxsh 2 2))

)

(progn

(setq bwxsh xx)

(setq xx(* 100 xx))

(set_tile "s_x" (itoa xx))

)))

;定义齿轮加工的函数

(defun makegear()

(setq chlzhx '(0 0));齿轮中心

(setq ylj (* pi (/ ylj 180.0)));度转换为弧度

(setq chgao (* msh (+ chdgaoxsh bwxsh)));齿高=1

(setq fdybj (* 0.5 (* msh chsh)));分度圆半径

(setq dybj (+ fdybj (* msh (+ chdgaoxsh bwxsh))));齿顶圆半径

(setq kbj (* 0.25 dybj));轮孔半径

(setq lm1 (list (- (car chlzhx) (* 2 dybj)) (+ (last chlzhx) dybj)));图纸界限的左下角

(setq lm2 (list (+ (* 5 msh) (car chlzhx) dybj) (- (last chlzhx) (+ 10.0 (* chdjx msh)) dybj)));图纸界限的右上角

(command "zoom" lm1 lm2)

(setq jybj (+ fdybj (* bwxsh msh)));节圆半径=分度圆半径+变位量

(setq temy1 (* msh (+ chdjx chdgaoxsh)));齿顶高1+齿顶间隙0.25

(setq chtgen (+ jybj temy1));齿轮中心到齿条根部的距离

(setq chtdi (+ chtgen 3.0));齿轮中心到齿条底根部的距离

(setq chtdi (- (cadr chlzhx) chtdi));齿条下底的y

(setq chtzuo (- (car chlzhx) (* 2 jybj)));齿条左边x

(setq p01 (list chtzuo chtdi))

(setq chw (* pi msh));周节

(setq chtgeny(+ chtdi 3.0));齿条根y

(setq p0 (list chtzuo chtgeny))

(setq chh (* 2.0 temy1));齿条全齿高

(setq chb (/ (* chh (sin ylj)) (cos ylj)))

(setq cha (* 0.25 (- chw (* 2 chb))))

(setq chnu(* 0.5 chsh));齿条的齿数

(setq chnum 0.0)

(command "color" "green")

(setq chtemp p0)

(command "pline" p01 p0 )

(while(< chnum chnu);绘制齿条轮廓线

(setq chnum (1+ chnum))

(command (setq p1 (list (+ cha (car p0)) (cadr p0))))

(command (setq p2 (list (+ chb (car p1)) (+ chh (cadr p1)))))

(command (setq p3 (list (+ (* 2.0 cha) (car p2)) (cadr p2))))

(command (setq p4 (list (+ chb (car p3)) (- (cadr p3) chh))))

(command (setq p5 (list (+ cha (car p4)) (cadr p4))))

(setq p0 p5)

)

(setq p02 (list (+ chtzuo (* chnum chw)) chtdi))

(command p02 p01 "c");齿条轮廓线绘制完毕

(setq e1(entlast));获取齿条的图元名

(command "region" e1 "");将齿条转换为面域

(setq tiao(entlast));获取转换为面域的齿条的图元名

(command "color" "white")

(command "circle" chlzhx dybj);绘制齿顶圆

(setq c1(entlast));获取齿顶圆的图元名

(command "region" c1 "");将齿顶圆转换为面域

(setq c1(entlast));获取转换为面域的齿顶圆的图元名

(command "circle" chlzhx kbj);绘制轮孔圆

(setq c2(entlast));获取轮孔圆的图元名

(command "region" c2 "");将轮孔圆转换为面域

(setq c2(entlast));获取转换为面域的轮孔圆的图元名

(command "subtract" c1 "" c2 "");齿顶圆的面域减去轮孔圆的面域

(setq lun(entlast));获取齿轮毛坯的图元名

(setq dphi(/ 360.0 (* chsh qxcsh)));齿轮毛坯每次旋转角度

(setq chtydjl (/ chw qxcsh));齿条每次移动距离

(setq shjqxcsh 0);实际切削次数

(setq ydjl 0.0);累计移动距离

(while (<= shjqxcsh (* qxcsh chsh))

(setq ydjl (+ ydjl chtydjl))

(setq dx chtydjl);齿条移动距离

(if (>= ydjl chw)

(progn;ydjl大于等于周节chw

(setq ydjl 0.0)

(setq dx (* (- 1 qxcsh) chtydjl));齿条退回一个周节

)

)

(command "copy" tiao "" '(0 0) '(0 0));原地复制齿条

(setq tiao1(entlast))

(command "subtract" lun "" tiao1 "");齿轮毛坯减去齿条

(command "rotate" lun "" chlzhx dphi);齿轮毛坯旋转dphi

(command "move" tiao "" '(0.0 0.0) (list dx 0.0));齿条移动dx

(setq shjqxcsh (1+ shjqxcsh))

)

)

;定义齿轮参数显示的函数

(defun showdata()

(if (not (new_dialog "gear_list" id))(exit))

(setq x1(dimx_tile "image2")) ;设置x1为图象宽

(setq y1(dimy_tile "image2")) ;设置y1为图象高

(start_image "image2") ;开始建立图象

(slide_image -10 -10 (+ x1 20) y1 "d:/example/sld/13-2-21") ;-10 -10 (+ x1 20) y1

(end_image) ;图象建立毕

(set_tile "t1" (strcat "模数m: " (rtos msh 2 2)))

(set_tile "t2" (strcat "齿数z: " (itoa chsh)))

(setq ylj(* 180 (/ ylj pi)))

(set_tile "t3" (strcat "压力角a: " (rtos ylj 2 2) "?" ));jlj0

(set_tile "t4" (strcat "变位系数x: " (rtos bwxsh 2 2)))

(set_tile "t5" (strcat "分度圆直径d: " (rtos (* 2 fdybj) 2 2)))

(set_tile "t6" (strcat "齿顶圆直径da: " (rtos (* 2 dybj) 2 2)))

(set_tile "t7" (strcat "齿根圆直径df: " (rtos (* 2 (- dybj (* 2.25 msh))) 2 2)))

(action_tile "accept" "(done_dialog 1)")

(action_tile "xwj" "(done_dialog 2)")

(if (> (start_dialog) 1)(fwfile))

)

;定义将齿轮参数写到指定文件的函数

(defun fwfile()

(setq fname(getfiled "输入存放齿轮参数的文件" "" "txt" 1))

(setq fp(open fname "w"))

(write-line (strcat "模数m: " (rtos msh 2 2)) fp)

(write-line (strcat "齿数z: " (itoa chsh))fp)

(write-line (strcat "压力角a: " (rtos ylj 2 2) "?" )fp)

(write-line (strcat "变位系数x: " (rtos bwxsh 2 2))fp)

(write-line (strcat "分度圆直径d: " (rtos (* 2 fdybj) 2 2))fp)

(write-line (strcat "齿顶圆直径da: " (rtos (* 2 dybj) 2 2))fp);

(write-line (strcat "齿根圆直径df: " (rtos (* 2 (- dybj (* 2.25 msh))) 2 2))fp)

(close fp)

)

; 主函数

(defun c:niu( / bwxsh c1 c2 cha chb chdgaoxsh chdjx chgao chh chnu chnum chsh chlzhx chtdi chtemp chtgen chtgeny chtydjl chtzuo chw dphi dx dybj e1 fdybj fname fp jybj kbj lm1 lm2 lun msh msh_ p0 p01 p02 p1 p2 p3 p4 p5 qxcsh shjqxcsh temy1 tiao tiao1 x0 x1 y0 y1 ydjl ylj ylj_ zhxx zhxy)

(setvar "cmdecho" 0)

(setvar "blipmode" 0)

(setvar "osmode" 0)

(setq chdgaoxsh 1.0);齿高系数

(setq chdjx 0.25);齿间隙

(setq qxcsh 15)

(setq id(load_dialog "d:/example/dcl/13-2")) ;装入对话框文件

(if (< id 0)(exit))

(setq what 3)

(while (> what 1)

(if (not (new_dialog "mgear" id))(exit))

(setq x1(dimx_tile "image1")) ;设置x1为图象宽

(setq y1(dimy_tile "image1")) ;设置y1为图象高

(start_image "image1") ;开始处理图象

(slide_image -10 -25 (+ x1 100) y1 "d:/example/sld/13-2-1") ;-10 -25 (+ x1 20) y1

(end_image) ;图象处理完毕

(setq m_lst(list "1" "1.25" "1.5" "2" "2.5" "3" "4" "5" "6" "8" "10"))

(start_list "_m") ;开始处理模数列表

(mapcar 'add_list m_lst)

(end_list);模数列表处理完毕

(setq alf_lst(list "14.5" "15" "20" "22.5" "25"))

(start_list "_alf");开始处理压力角列表

(mapcar 'add_list alf_lst)

(end_list);压力角列表处理完毕

(dlg1) ;初始化对话框一

(if (/= what 2) (setq what (start_dialog)))

) ;while结束

(if (= what 1)

(progn

(makegear);调用加工齿轮的函数

(showdata);调用显示齿轮参数的函数

)

)

(unload_dialog id);卸载对话框文件

)

相关阅读

新房装修好,一切东西都要换新啦,家里那台老旧泛黄的噪音空调终于“光荣下岗”,立即入手心仪已久的智米变频空调!这款智

距离2018年结束只剩下7天了,一到年终岁末,回顾、盘点就成为最常出现的词语。本文也不例外,纵观这一年,你会发现今年的营销圈格外热闹,

快播看起来不可能再重获新生,它曾是中国最好、用户规模最大的视频播放软件,但无法做到大而不倒。在所有的转型机遇面前,它一次次错失

若小米直达服务能成为现象级的产品时,手机能随时使用到的应用数量将趋于无限。以下为本文目录:一、 直达服务的背景1、互联网发展趋

简介

模拟退火算法(Simulate Anneal,SA)是一种通用概率演算法,用来在一个大的搜寻空间内找寻命题的最优解。其思想借鉴于固体的退火

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值