- 积分
- 4263
- 明经币
- 个
- 注册时间
- 2011-3-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2012-5-2 14:40:54
|
显示全部楼层
本帖最后由 snddd2000 于 2012-5-3 08:57 编辑
更新内容
添加简单的轴承绘图部分(不带剖面线和圆角)替换原来的一个圆。
增加判断块名是否存在,如存在则不再创建直接插入块。
将数据表另存为txt文件,测试时需更改lsp文件里面的目录
dcl文件没有什么变动,添加的按钮<添加新规格...>目前点击无效。
- (defun c:q1 ()
- ;;;风的画图通用函数
- (defun DefBlock (BlockName) ;_定义有名块
- (entmake (list '(0 . "BLOCK") '(10 0.0 0.0 0.0) '(70 . 0) (cons 2 BlockName)))
- );_ (setq blockname (entmake '((0 . "ENDBLK"))));_与此句配对使用且不可嵌套。
- (defun RefBlock (BlockName PNT) ;_插入块返回图元名
- (entmakex (list '(0 . "INSERT") (cons 2 BlockName) (cons 10 PNT)))
- )
- (defun CheckBlockName (BlockName)
- (setq re nil)
- (setq BlockList (tblnext "block" T))
- (while BlockList
- (if (eq BlockName (cdr (assoc 2 BlockList)))
- (setq re T)
- )
- (setq BlockList (tblnext "block"))
- (if re (setq BlockList nil))
- )
- re
- )
-
- ;;;画图函数
- (defun DrawingBearing (BearingDataList index1 index2)
- ;;;;;;;_起始模拟捕捉图元,
- (setq r1 (/ (getvar "viewsize") 500))
- (setq r1 (* (read (getenv "AutoSnapSize")) r1))
- (setq pt1 '(0 0))
- (setq lst1 '()
- setp0 (/ pi 10)
- )
- (repeat 5
- (setq lst1 (cons (polar pt1 setp0 r1) lst1))
- (setq setp0 (+ setp0 (/ (* 2 pi) 5)))
- )
- (setq entlist00 (entmake
- (append
- (list
- (cons 0 "LWPOLYLINE")
- (cons 100 "AcDbEntity")
- (cons 100 "AcDbPolyline")
- (cons 90 (length lst1))
- (cons 70 1)
- (cons 62 (read (getenv "AutoSnapColor")))
- (cons 43 (/ r1 5))
- )
- (mapcar '(lambda (p) (cons 10 p)) lst1)
- )
- )
- )
- (setq ent00 (entlast)
- pd t
- )
- (entdel ent00)
- (setq pd00 nil) ;_起始模拟捕捉图元,先挂起;标记pd00为nil则不显示
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (setq List2Data (cdr (nth (atoi index1) BearingDataList)))
- (setq List3Data (cadr (nth (atoi index2) List2Data)))
- (setq BlockName (strcat "mjtd_" (car (nth (atoi index1) BearingDataList)) "_" (car (nth (atoi index2) List2Data))));_块名
- (setq dInside (nth 0 List3Data)) ;_内径
- (setq DOutside (nth 1 List3Data)) ;_外径
- (setq BWidth (nth 2 List3Data)) ;_轴向厚度
- (setq AWidth (/ (- DOutside dInside) 2.0));_径向厚度
- (setq 2cirRa (/ AWidth 4.0));_两个小圆弹珠的半径
- (setq 4PointList (list (list (- 0 (/ DOutside 2.0)) 0 0)
- (list (- 0 (/ DOutside 2.0)) BWidth 0)
- (list (/ DOutside 2.0) BWidth 0)
- (list (/ DOutside 2.0) 0 0)
- ));_外围四点表
- (setq mm (grread t 15 0))
- (setq pt0 (cadr mm))
- ;;;判断块名是否已存在
- (if (null (CheckBlockName BlockName))
- (progn
- ;;;块定义头
- (DefBlock BlockName)
- ;;;块定义图形
- (setq cir1 (entmakex (list (cons 0 "CIRCLE")
- (cons 10 (setq cir1cent (list (/ (- DOutside AWidth) 2.0) (/ BWidth 2.0) 0)))
- (cons 40 2cirRa))))
- (setq cir2 (entmakex (list (cons 0 "CIRCLE")
- (cons 10 (setq cir2cent (list (/ (- AWidth DOutside) 2.0) (/ BWidth 2.0) 0)))
- (cons 40 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (+ (/ dInside 2.0) (* 0.375 AWidth)) 0.0 0.0))
- (cons 11 (polar cir1cent (* pi (/ 240 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (+ (/ dInside 2.0) (* 0.625 AWidth)) 0.0 0.0))
- (cons 11 (polar cir1cent (* pi (/ 300 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (+ (/ dInside 2.0) (* 0.375 AWidth)) BWidth 0.0))
- (cons 11 (polar cir1cent (* pi (/ 120 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (+ (/ dInside 2.0) (* 0.625 AWidth)) BWidth 0.0))
- (cons 11 (polar cir1cent (* pi (/ 60 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (- 0 (+ (/ dInside 2.0) (* 0.375 AWidth))) 0.0 0.0))
- (cons 11 (polar cir2cent (* pi (/ 300 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (- 0 (+ (/ dInside 2.0) (* 0.625 AWidth))) 0.0 0.0))
- (cons 11 (polar cir2cent (* pi (/ 240 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (- 0 (+ (/ dInside 2.0) (* 0.375 AWidth))) BWidth 0.0))
- (cons 11 (polar cir2cent (* pi (/ 60 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (- 0 (+ (/ dInside 2.0) (* 0.625 AWidth))) BWidth 0.0))
- (cons 11 (polar cir2cent (* pi (/ 120 180.0)) 2cirRa))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (/ dInside 2.0) 0.0 0.0))
- (cons 11 (list (/ dInside 2.0) BWidth 0.0))))
- (entmakex (list '(0 . "LINE")
- (cons 10 (list (- 0 (/ dInside 2.0)) 0.0 0.0))
- (cons 11 (list (- 0 (/ dInside 2.0)) BWidth 0.0))))
-
- (entmakex (append
- (list
- (cons 0 "LWPOLYLINE")
- (cons 100 "AcDbEntity")
- (cons 100 "AcDbPolyline")
- (cons 90 (length 4PointList))
- (cons 70 1)
- )
- (mapcar '(lambda (p) (cons 10 p)) 4PointList)
- )
- )
- ;;;块定义尾
- (setq BlockName (entmake '((0 . "ENDBLK"))))
- ;;;块定义结束
- ));_end if 已有同名块则不创建块
- ;;;插入块
- (RefBlock BlockName pt0)
- (setq ent1 (entlast)
- ent1list (entget ent1)
- pd T)
-
- (while pd
- (setq mm (grread t 15 0))
- (setq pdMode (car mm))
- (cond
- ((= 5 pdMode)
- (progn
- (setq pt0 (cadr mm))
- (entdel ent1)
- (if pd00
- (progn (entdel ent00)
- (setq pd00 nil)
- )
- )
- (setq pt1 (osnap pt0 "_EXT,_end,_int"))
- (entdel ent1)
- (if pt1
- (setq pt0 pt1)
- )
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (if pt1
- (progn
- (setq r1 (/ (getvar "viewsize") 500))
- (setq r1 (* (read (getenv "AutoSnapSize")) r1))
- (setq lst1 '()
- setp0 (/ pi 10)
- )
- (if (null pd00)
- (progn (entdel ent00)
- (setq pd00 t) ;_捕捉图元,显示,标记pd00为t则显示
- )
- ) ;_end if
- (setq entlist00 (entget ent00))
- (setq entlist00
- (mapcar
- '(lambda (e)
- (cond
- ((= 10 (car e))
- (progn
- (setq e (cons 10 (polar pt1 setp0 r1)))
- (setq setp0 (+ setp0 (/ (* 2 pi) 5)))
- (setq e e)
- ) ;_end progn
- )
- ((= 43 (car e)) (setq e (cons 43 (/ r1 5))))
- (t (setq e e))
- ) ;_end cond
- ) ;_end lambda
- entlist00
- ) ;_end mapcar
- ) ;_end setq entlist00
- (entmod entlist00)
- )
- )
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (setq ent1list (subst (cons 10 pt0) (assoc 10 ent1list) ent1list))
- (entmod ent1list)
- (setq pd T)
- ))
- ((= 3 pdMode)
- (progn (setq pd nil)
- (print (car mm))
- (if pd00
- (progn (entdel ent00)
- (setq pd00 nil)
- )
- )
- )) ;_左键确认
- ((= 25 pdMode) (progn (entdel ent1) (setq pd nil))) ;_右键取消
- )
- )
- )
-
- ;;;定义局域函数
- (defun BearingDataListToList2Data (BearingDataList index)
- (setq List2Data (cdr (nth (atoi index) BearingDataList)))
- (setq List2Data (mapcar '(lambda (x)
- (car x)
- )
- List2Data
- ))
- List2Data
- )
- (defun BearingDataListToList3Data (BearingDataList index1 index2)
- (setq List2Data (cdr (nth (atoi index1) BearingDataList)))
- (setq List3Data (cadr (nth (atoi index2) List2Data)))
- (setq DimzinOld (getvar "DIMZIN"))
- (setvar "DIMZIN" 8)
- (setq List3Data (mapcar '(lambda (x)
- (rtos x 2 4)
- )
- List3Data
- ))
- (setvar "DIMZIN" DimzinOld)
- (setq n -1)
- (setq List3Data (mapcar '(lambda (x)
- (setq n (1+ n))
- (strcat (nth n BearingKeyUnit) x)
- )
- List3Data
- ))
- List3Data
- )
- (defun InputNewDataToList (lst key mode) ;_list str str
- (start_list key (atoi mode))
- (mapcar 'add_list lst)
- (end_list)
- )
- ;;;
- (setq BearingKeyUnit (list "d(mm) ="
- "D(mm) ="
- "B(mm) ="
- "da(mm) ="
- "Da(mm) ="
- "ra(mm) ="
- "d2(mm) ="
- "D2(mm) ="
- "r(mm) ="
- "Cr(KN) ="
- "C0r(KN) ="
- "脂(r.min-1) ="
- "油(r.min-1) ="
- "W(Kg) ="))
-
- ;;;;;; (setq BearingDataList ;_d/mm,D/mm,B/mm,da/mm,Da/mm,ra/mm,d2/mm,D2/mm,r/mm,Cr/KN,C0r/KN,脂/r.min-1,油/r.min-1,W/Kg.
- ;;;;;; (list
- ;;;;;; (list
- ;;;;;; "60000"
- ;;;;;; (list "613"
- ;;;;;; (list 3 8 3 4.2 6.8 0.15 4.5 6.5 0.15 0.45 0.15 38000 48000 0.0008))
- ;;;;;; (list "623"
- ;;;;;; (list 3 10 4 4.2 8.8 0.15 5.2 8.1 0.15 0.65 0.22 38000 48000 0.002))
- ;;;;;; ;_添加60000型规格....
- ;;;;;; )
- ;;;;;; (list
- ;;;;;; "60000-Z"
- ;;;;;; (list "613-Z"
- ;;;;;; (list 3 8 3 4.2 6.8 0.15 4.5 6.8 0.15 0.45 0.15 38000 48000 0.0008))
- ;;;;;; (list "623-Z"
- ;;;;;; (list 3 10 4 4.2 8.8 0.15 5.2 8.3 0.15 0.65 0.22 38000 48000 0.002))
- ;;;;;; ;_添加60000-Z型规格....
- ;;;;;; )
- ;;;;;; ;_添加其他型及其规格....
- ;;;;;; )
- ;;;;;; )
- (setq BearingData (open "I:\\BearingData.txt" "r"))
- (setq BearingDataList (read (read-line BearingData)))
- (close BearingData)
-
- ;;;--- Load the dcl file
- (setq dcl_id (load_dialog "BEARING.dcl"))
- ;;;--- Load the dialog definition if it is not already loaded
- (if (not (new_dialog "BEARING" dcl_id))
- (progn
- (alert "The BEARING.DCL file could not be loaded!")
- (exit)
- )
- )
- ;;;--- load data to list1
- (setq List1Data (mapcar '(lambda (x)
- (car x)
- )
- BearingDataList
- ))
- (start_list "list1" 3)
- (mapcar 'add_list List1Data)
- (end_list)
- ;;;--- load data to list2---test!!!
- ;;; (setq List2Data (mapcar '(lambda (x)
- ;;; (cadr x)
- ;;; )
- ;;; BearingDataList
- ;;; ))
- ;;; (setq List2Data (mapcar '(lambda (x)
- ;;; (car x)
- ;;; )
- ;;; List2Data
- ;;; ))
- ;;; (start_list "list2" 3)
- ;;; (mapcar 'add_list List2Data)
- ;;; (end_list)
- ;;;--- If an action event occurs, do this function
- (action_tile "accept" "(setq ddiag 2)(done_dialog)")
- (action_tile "cancel" "(setq ddiag 1)(done_dialog)")
- (action_tile "list1" (strcat
- "(InputNewDataToList (BearingDataListToList2Data BearingDataList (get_tile \"list1\")) \"list2\" \"3\")"
- "(InputNewDataToList (list) \"list3\" \"3\")"
- "(setq Index1 (get_tile \"list1\"))(setq Index2 nil)"
- ))
- (action_tile "list2" (strcat
- "(InputNewDataToList (BearingDataListToList3Data BearingDataList (get_tile \"list1\") (get_tile \"list2\")) \"list3\" \"3\")"
- "(setq Index2 (get_tile \"list2\"))"
- ))
- ;;;--- Display the dialog box
- (start_dialog)
- ;;;--- Unload the dialog box
- ;;; (unload_dialog dcl_id)
- ;;;--- If the user pressed the Cancel button
- (if (= ddiag 1)
- (princ "\n Sample3 cancelled!")
- )
- ;;;--- If the user pressed the Okay button
- (if (= ddiag 2)
- (progn
- (if (and Index1 Index2)
- (DrawingBearing BearingDataList Index1 Index2)
- (progn (alert "没有选择规格,需重新选择!") (c:q1))
- )
- (princ "\n The user pressed Okay!")
- )
- )
- )
- BEARING : dialog {
- label = "Sample Dialog Box Routine " ;
- :boxed_row {
- label = "SELECT...";
- : list_box {
- key = "list1" ;
- label ="Choose Item";
- height = 15;
- list = "" ;
- value = ""; }
- :list_box {
- key = "list2" ;
- label ="Choose Item";
- height = 15;
- list = "" ;
- value = ""; }
- :list_box {
- key = "list3" ;
- label ="Show Item";
- width = 20;
- height = 15;
- list = "" ;
- value = "";
- //is_enable = false;
- }
- }
- ok_cancel;
- :boxed_column{
- label = "添加新规格...";
- :button{
- key = "addnew";
- label = "添加新规格...";
- }
- }
- }
- BearingAddNew : dialog {
- label = "Add New Item Dialog Box Routine " ;
- :boxed_column {
- label = "Item...";
- : edit_box {
- label ="d =";
- key = "EditBox1";
- edit_width = 10;
- value = "";
- }
- : edit_box {
- label ="D =";
- key = "EditBox2";
- edit_width = 10;
- value = "";
- }
- : edit_box {
- label ="B =";
- key = "EditBox3";
- edit_width = 10;
- value = "";
- }
- }
- ok_cancel;
- }
- (("60000" ("613"( 3 8 3 4.2 6.8 0.15 4.5 6.5 0.15 0.45 0.15 38000 48000 0.0008))("623" (3 10 4 4.2 8.8 0.15 5.2 8.1 0.15 0.65 0.22 38000 48000 0.002)))("60000-Z"( "613-Z"( 3 8 3 4.2 6.8 0.15 4.5 6.8 0.15 0.45 0.15 38000 48000 0.0008))("623-Z"(3 10 4 4.2 8.8 0.15 5.2 8.3 0.15 0.65 0.22 38000 48000 0.002))))
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|