- 积分
- 2609
- 明经币
- 个
- 注册时间
- 2014-11-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2015-1-12 14:28:30
|
显示全部楼层
- ;问题:
- ;按esc键值留在屏上
- ;自定义粗糙值只输入数字没有搞定.
- (defun c:rough_mech()
- (princ "\n表面粗糙度标注程序")
- (setvar "cmdecho" 0)
- (setq os (getvar "OSMODE"))
- (setvar "OSMODE" 0)
- (setq hh (getvar "textsize"))
- (setq ccd_t "3.2")
- (setq roughtype "1")
- (repeat 99
- (initialize_rough)
- (roughdraw)
- (move_rough)
- )
- (setvar "cmdecho" 1)
- (setvar "osmode" os)
- (prin1)
- )
- (prompt "c:rough_mech表面粗糙度")
- (prin1)
- (defun set_ccd()
- (initget "H h c C 1 2 3")
- (setq type_t (strcat "\n设置粗糙度标注类型或字高【字高(H)/去除材料(1)/不去除材料(2)/任意(3)】<1>:"))
- (setq dimtype (getkword type_t))
- (if (= dimtype nil) (set_ccd))
- (cond ( (or (= dimtype "H") (= dimtype "h"))
- (set_ccdh)
- )
- ((= dimtype "1") (setq roughtype "1") )
- ((= dimtype "2") (setq roughtype "2") )
- ((= dimtype "3") (setq roughtype "3") )
- )
- )
- (defun set_ccdh()
- (setq hht (getvar "textsize"))
- (setq str_hh (strcat"\n文字高度<"(rtos hht)">:"))
- (setq hh (getdist str_hh))
- (if (= hh nil) (setq hh hht)) ;设置为默认
- (setvar "textsize" hh)
- )
- (defun initialize_rough()
- (setq pa '(0 0)) ;插入点
- (setq h (* (/ hh 2) 3))
- (setq 2h (* 2 h))
- (setq lb (/ h (sin (/ pi 3))))
- (setq lc (/ 2h (sin (/ pi 3))))
- (setq pb (polar pa (* (/ pi 3) 2 ) lb)) ;左端点
- (setq pc (polar pa (/ pi 3) lc) ) ;右
- (setq pd (polar pa (/ pi 3) lb)) ;右中
- (setq tc (polar pa (* pi 0.5) (* h 1.5)))
- (setq cc (polar pa (* pi 0.5) (* (/ h 3) 2)))
- )
-
-
- (defun roughdraw()
- (cond
- ((= roughtype "1") (rough1) )
- ((= roughtype "2") (rough2) )
- ((= roughtype "3") (rough3) )
- )
- )
- (defun rough1()
- ;;;下面的相当重要,做图块
- (entmake (list '(0 . "BLOCK") (cons 2 "*U") '(70 . 1) (cons 10 pa))) ;*u无块名,70插入行数,10插入点
- (entmake (list '(0 . "LINE") (cons 10 pa) (cons 11 pb))) ;
- (entmake (list '(0 . "LINE") (cons 10 pa) (cons 11 pc)))
- (entmake (list '(0 . "LINE") (cons 10 pb) (cons 11 pd)))
- (setq blk (entmake '((0 . "ENDBLK")))) ;块命令结束
- ;;;;;;;分隔线.
- (entmake (list '(0 . "INSERT") (cons 10 pa) (cons 2 blk))) ;10插入点,2图块名称
- (setq ename0 (entlast))
- (setq edata0 (entget ename0))
- (entmake (list '(0 . "TEXT") (cons 10 tc) (cons 11 tc) (cons 40 hh) '(62 . 3)'(72 . 4) '(41 . 0.8) (cons 1 ccd_t) ));10第一对齐点,11第二对齐点,62颜色,72水平文字中央对正4代表中央,1文字内容
- (setq ename1 (entlast))
- (setq edata1 (entget ename1))
- )
- (defun rough2()
- (entmake (list '(0 . "BLOCK") (cons 2 "*U") '(70 . 1) (cons 10 pa))) ;*u无块名,70插入行数,10插入点
- (entmake (list '(0 . "LINE") (cons 10 pa) (cons 11 pb))) ;
- (entmake (list '(0 . "LINE") (cons 10 pa) (cons 11 pc)))
- (entmake (list '(0 . "CIRCLE") (cons 10 cc) (cons 40 (/ h 3))));10中心点,40半径
- (setq blk (entmake '((0 . "ENDBLK"))))
- (entmake (list '(0 . "INSERT") (cons 10 pa) (cons 2 blk))) ;10插入点,2图块名称
- (setq ename0 (entlast))
- (setq edata0 (entget ename0))
- (entmake (list '(0 . "TEXT") (cons 10 tc) (cons 11 tc) (cons 40 hh) '(62 . 3)'(72 . 4) '(41 . 0.8) (cons 1 ccd_t) ));10第一对齐点,11第二对齐点,62颜色,72水平文字中央对正4代表中央,1文字内容
- (setq ename1 (entlast))
- (setq edata1 (entget ename1))
- )
- (defun rough3()
- (entmake (list '(0 . "BLOCK") (cons 2 "*U") '(70 . 1) (cons 10 pa))) ;*u无块名,70插入行数,10插入点
- (entmake (list '(0 . "LINE") (cons 10 pa) (cons 11 pb))) ;
- (entmake (list '(0 . "LINE") (cons 10 pa) (cons 11 pc)))
- (setq blk (entmake '((0 . "ENDBLK"))))
- ;;;;;;;分隔线.
- (entmake (list '(0 . "INSERT") (cons 10 pa) (cons 2 blk))) ;10插入点,2图块名称
- (setq ename0 (entlast))
- (setq edata0 (entget ename0))
- (entmake (list '(0 . "TEXT") (cons 10 tc) (cons 11 tc) (cons 40 hh) '(62 . 3) '(72 . 4) '(41 . 0.8) (cons 1 ccd_t) ));10第一对齐点,11第二对齐点,62颜色,72水平文字中央对正4代表中央,1文字内容
- (setq ename1 (entlast))
- (setq edata1 (entget ename1))
- )
-
-
- (defun move_rough()
- ;**************************************明经代码
- (prompt "\n指定基点/【取值0-9)】/【S设置类型】<指定基点>:")
- (setq tag T) ;;;设定跳出while循环的标志
- (while tag
- (setq code (grread T 8 )) ;;;读取输入
- (setq mod (car code)) ;;;取得输入模式
- (cond
- ((= mod 5) (do_move) ) ;;左键动作程序
-
- ((= mod 3)
- (setq tag nil)
- (setq ipt0 (cadr code))
- ) ;;;如果鼠标左键点击,则设定while循环结束
- ((or (= mod 11 ) (= mod 25) ) (setq tag nil)) ;右键或右键设为enter.
- ((= mod 2) (do_keybd) ) ;;;处理键盘
- (T );;;处理其它情况
- ) ;;cond
- ) ;;;while
- )
- ;;;;鼠标捕捉函数,捕捉对象,并与之垂直.
- (defun do_move()
- (setq ipt0 (cadr code))
- (entdel ename0 )
- (entdel ename1)
- (setq neapt (osnap ipt0 "nea")) ;;;取得最近的捕捉点
- (entdel ename0 )
- (entdel ename1) ;用entdel可解决图块跳动
- (if neapt
- (progn
- (setq ang1 (angle neapt ipt0))
- (setq ang (- ang1 (* pi 0.5)))
- (cond ((= ang1 0 ) (setq ang2 (+ ang pi)))
- ((< 0 ang1 pi) (setq ang2 ang) )
- ((= ang1 pi) (setq ang2 ang) )
- ((< pi ang1 (* pi 2)) (setq ang2 (- ang pi )))
- )
- (setq pa neapt)
- (setq tc (polar pa ang1 (* h 1.5)))
- (setq edata0 (subst (cons 10 neapt) (assoc 10 edata0) edata0)) ;图块插入点替换
- (setq edata0 (subst (cons 50 ang) (assoc 50 edata0) edata0)) ;图块插入点替换
- (setq edata1 (subst (cons 10 tc) (assoc 10 edata1) edata1)) ;图块插入点替换
- (setq edata1 (subst (cons 11 tc) (assoc 11 edata1) edata1)) ;图块插入点替换
- (setq edata1 (subst (cons 50 ang2) (assoc 50 edata1) edata1)) ;图块插入点替换
- (entmod edata0)
- (entmod edata1)
-
- ; (entupd ename0) ;;;更新一个对象的屏幕景像,当聚合线或图块修改后,复合对象不会立即更新.
- ;(entupd ename1)
- ;(entupd ename2)
- )
- (progn
- (setq pa ipt0)
- (setq ang 0 )
- (setq ang2 ang)
- (setq tc (polar pa (* pi 0.5) (* h 1.5)))
- (setq edata0 (subst (cons 10 ipt0) (assoc 10 edata0) edata0)) ;图块插入点替换
- (setq edata0 (subst (cons 50 ang) (assoc 50 edata0) edata0)) ;图块插入点替换
- (setq edata1 (subst (cons 10 tc) (assoc 10 edata1) edata1)) ;图块插入点替换
- (setq edata1 (subst (cons 11 tc) (assoc 11 edata1) edata1)) ;图块插入点替换
- (setq edata1 (subst (cons 50 ang2) (assoc 50 edata1) edata1))
- (entmod edata0)
- (entmod edata1)
- )
-
- ) ;if
- )
- (defun do_keybd() ;很关键的输入
- (princ"\n 0-空/1-0.2/2-0.4/3-0.8/4-1.6/5-3.2/6-6.3/7-12.5/8-0.1/9自定义")
- (setq pnum (cadr code))
- (if (or (<= 48 pnum 57) (= pnum 83) (= pnum 115))
- (setq pstr1 (chr pnum)) ;转化为字符串
- )
- (cond
- ((= pstr1 "0") (setq ccd_t ""))
- ((= pstr1 "1") (setq ccd_t "0.2"))
- ((= pstr1 "2") (setq ccd_t "0.4"))
- ((= pstr1 "3") (setq ccd_t "0.8"))
- ((= pstr1 "4") (setq ccd_t "1.6"))
- ((= pstr1 "5") (setq ccd_t "3.2"))
- ((= pstr1 "6") (setq ccd_t "6.3"))
- ((= pstr1 "7") (setq ccd_t "12.5"))
- ((= pstr1 "8") (setq ccd_t "0.1"))
- ((= pstr1 "9") (set_ccd_t))
- (( or (= pstr1 "s") (= pstr1 "S"))
- (progn
- (entdel ename0 )
- (entdel ename1) ;删除对象.
- (set_ccd)
- (repeat 99
- (initialize_rough)
- (roughdraw)
- (move_rough)
- )
- )
- )
- (t (setq ccd_t "3.2") )
- )
-
- (setq edata1 (subst (cons 1 ccd_t ) (assoc 1 edata1) edata1))
- (entmod edata1)
- ;(entupd ename)
- )
- (defun set_ccd_t()
- (setq ccd_2 (strcat "\n新值<"ccd_t">:"))
- (setq ccd_tmp (getstring ccd_2 ))
- (if (= ccd_tmp nil) (setq ccd_tmp ""))
- (setq ccd_t ccd_tmp)
- )
-
-
|
|