角度转度分秒lisp函数_自改小程序,提示错误,运行另一个lisp后就不会出错,求帮忙!...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

;;主程序

(defun c:qxys( / r an ps pe pc dis1)

(setvar "cmdecho" 0)

(command "layer" "m" "曲线要素" "c" 1 "" "")

(command "style" "样式1" "simplex,hztxt" "0" ".7" "0" "n" "n" "n")

(command "units" 2 3 2 4 "" "")

(command "graphscr")

(if (setq ent (car (entsel "\n请选择圆弧:")))

(if (= (cdr (assoc 0 (setq db (entget ent)))) "ARC")

(progn

(setq pc (cdr (assoc 10 db)) ;圆心

r (cdr (assoc 40 db)) ;半径

a0 (cdr (assoc 50 db))

a1 (cdr (assoc 51 db))

ps (polar pc a0 r);起点

pe (polar pc a1 r);止点

pd (mapcar '* '(0.5 0.5) (mapcar '+ ps pe))

pm (polar pc (angle pc pd) r);中点

an (- a1 a0) ;圆心角

hc (abs (* r an));弧长

) ;end setq

;;;判断是角度 坐标系

(if (< an 0) (setq an (+ an (* 2.0 pi))))

(if (not (equal '(0 0 0) (setq org (getvar "ucsorg"))))

(setq pc (mapcar '- pc org)

ps (mapcar '- ps org)

pe (mapcar '- pe org)

m (mapcar '- pm org)

);end setq

) ;end if

;求出切线长

(setq t1 (* (/ (sin (/ an 2)) (cos (/ an 2))) r))

;;弧度转换为度

;;度转换为度分秒

(setq a6 (fix (/ (* an 180) 3.1415926)));;;;;;;度

(setq a7 (fix (* (- a5 a6) 60)));;;;;;;;分

(setq a8 (fix (* (- (* (- a5 a6) 60) a7) 60)));;;;;;;;秒

(command "osnap" "off")

;(setq dis1 (getint "\n已选择圆弧,标注文字高度:默认:"))

;(if (equal dis1 nil);默认为3.0

;(setq dis1 3)

;)

(setq dis1 3 )

(setq dis2 (* dis1 8))

(setq dis3 (* dis1 8))

(setq d1 (list (+ (car pc) dis2) (+ (cadr pc) dis3)))

(command "rectang" pc d1 )

(command "line" ps pc "")

(command "line" pc pe "")

(setq f1 (list (+ (car pc) 1) (+ (cadr pc) 1)))

(setq f2 (list (car f1) (+ (cadr f1) (* dis1 2))))

(setq f3 (list (car f2) (+ (cadr f2) (* dis1 2))))

(setq f4 (list (car f3) (+ (cadr f3) (* dis1 2))))

(command "text" f4 dis1 "0" (strcat "R=" (rtos r 2 3) "m"))

(command "text" f3 dis1 "0" (strcat "a=" (rtos a6 2 0) "%%d" (rtos a7 2 0) "\U+2032" (rtos a8 2 0) "\U+2033"))

(command "text" f2 dis1 "0" (strcat "T=" (rtos t1 2 3) "m"))

(command "text" f1 dis1 "0" (strcat "L=" (rtos hc 2 3) "m"))

) ;end progn

(alert "所选取的不是圆弧!")

);end "ARC")

) ;end if

(setvar "osmode" 16383);打开对象捕捉

(command "LAYER" "s" "0" "");返回0层

(princ )

)

运行后提示:错误: 参数类型错误: numberp: nil

但是如果运行网友的另一个以后就能正常用了:

网友的:

(VL-Load-Com)

(SetQ **SysVarNL** '("AUNITS" "AUPREC" "ATTDIA" "BLIPMODE" "CECOLOR" "CELTYPE"

"CLAYER" "CMDECHO" "EXPERT" "HIGHLIGHT" "LUNITS" "LUPREC"

"OSMODE" "ORTHOMODE" "TEXTSTYLE" "PLINEWID"

)

)

(Defun-Q SetIErr (/ sv)

(If (= 'LIST (Type *error*))

(Alert "注意:最后一个(SetIErr)函数没有配对的(ReErr)!")

(Progn (SetQ **svarl** '())

(ForEach sv **SysVarNL**

(SetQ **svarl** (Cons (GetVar sv) **svarl**))

)

(ForEach sv '("ATTDIA" "BLIPMODE" "CMDECHO" "HIGHLIGHT"

"OSMODE" "ORTHOMODE"

)

(SetVar sv 0)

)

(SetVar "EXPERT" 5)

(Defun-Q *error* (st) (ReErr))

)

)

)

(Defun-Q ReErr ()

(If (= 'List (Type *error*))

(Progn (MapCar 'SetVar **SysVarNL** (Reverse **svarl**))

(SetQ *error* nil) (PrinC)

)

(Alert "注意:没有对应引用 (SetIErr)!")

)

)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;主程序

(defun C:qxjs()

(setierr)

(vl-load-com)

(setq acadobject(vlax-get-acad-object)

acaddocument(vla-get-activedocument acadobject)

mspace1(vla-get-modelspace acaddocument)

mspace2(vla-get-modelspace acaddocument))

(command "layer" "m" "曲线要素" "c" 1 "" "")

(command "style" "standard" "txt,hztxt" "0" ".8" "0" "n" "n" "n")

(command "units" 2 3 2 4 "" "")

(command "graphscr")

(ysjs);;;;;;;;调用要素计算函数(YSJS)

(princ)

(reerr)

(princ)

)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;要素计算

(defun ysjs ()

(princ "\n※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")

(princ "\n※※※※※※※※※※※欢迎使用本程序,Thank You!※※※※※※※※※※※※")

(princ "\n※※※曲线要素计算程序 V1.0 版本 作者:谢亮 2003年10月15日 于娄底。※※※")

(princ "\n※※※※※※※※※※※※※※※※※说明※※※※※※※※※※※※※※※※※")

(princ "\n※※※※※※本程序的功能是:通过分别选取两条直线上的每两个点,※※※※※※")

(princ "\n※※※※※※及输入的半径把曲线要素标注出来,并画弧。※※※※※※※※※※")

(princ "\n※※※※※※注意:如果两直线共线则程序退出!※※※※※※※※※※※※※※※")

(princ "\n※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")

;;;;;;;;;;;;;;;;;;;计算方角

(command "osmode" 16383)

;;;;;;;;;;;;;选择直线上的点以计算方位角

(setq a10 (getpoint"\n请选择一直线上一点:"))

;;;;;;;出错循环

(while (= nil a10)

(setq a10 (getpoint"\n请重新选择直线上一点:")))

(setq a11 (getpoint"\n请选择直线上另一点:"))

;;;;;;;出错循环

(while (or (= nil a11)

(= a11 a10))

(setq a11 (getpoint"\n请重新选择直线上另一点:")))

(setq a20 (getpoint"\n请选择另一直线上一点:"))

;;;;;;;出错循环

(while (or (= nil a20)

(= a20 a11)

(= a20 a10))

(setq a20 (getpoint"\n请重新选择另一直线上一点:")))

(setq a21 (getpoint"\n请选择直线上另一点:"))

;;;;;;;出错循环

(while (or (= nil a21)

(= a21 a11)

(= a21 a10)

(= a21 a20))

(setq a21 (getpoint"\n请重新选择直线上另一点:")))

;;;;;;;得到选中点(a10与a11、a20与a21)的X、Y坐标及增量

(setq a10x (car a10))

(setq a10y (cadr a10))

(setq a11x (car a11))

(setq a11y (cadr a11))

(setq a20x (car a20))

(setq a20y (cadr a20))

(setq a21x (car a21))

(setq a21y (cadr a21))

(setq da1y (- a11y a10y))

(setq da1x (- a11x a10x))

(setq da2x (- a21x a20x))

(setq da2y (- a21y a20y))

;;;;;;;;;;;判断除数是否为零(方位角是否为:0、90、180、270、360度)

(if (= da1x 0) (setq da1x (+ da1x 0.000000000000001)))

(if (= da1y 0) (setq da1y (+ da1y 0.000000000000001)))

(if (= da2x 0) (setq da2x (+ da2x 0.000000000000001)))

(if (= da2y 0) (setq da2y (+ da2y 0.000000000000001)))

;;;;;;;;判断方位角象限(一、二、三、四)

;;;;;;;;;判断直线一

;;;;;;;;;一象限

(if (and (> da1x 0)

(> da1y 0))

(setq a1 (atan (/ da1y da1x))))

;;;;;;;;;二象限

(if (and (< da1x 0)

(> da1y 0))

(setq a1 (+ 3.1415926 (atan (/ da1y da1x)))))

;;;;;;;;;三象限

(if (and (< da1x 0)

(< da1y 0))

(setq a1 (+ 3.1415926 (atan (/ da1y da1x)))))

;;;;;;;;;四象限

(if (and (> da1x 0)

(< da1y 0))

(setq a1 (+ (* 2 3.1415926) (atan (/ da1y da1x)))))

;;;;;;;;;判断直线二

;;;;;;;;;一象限

(if (and (> da2x 0)

(> da2y 0))

(setq a2 (atan (/ da2y da2x))))

;;;;;;;;;二象限

(if (and (< da2x 0)

(> da2y 0))

(setq a2 (+ 3.1415926 (atan (/ da2y da2x)))))

;;;;;;;;;三象限

(if (and (< da2x 0)

(< da2y 0))

(setq a2 (+ 3.1415926 (atan (/ da2y da2x)))))

;;;;;;;;;四象限

(if (and (> da2x 0)

(< da2y 0))

(setq a2 (+ (* 2 3.1415926) (atan (/ da2y da2x)))))

;;;;;;;;;;;;;;;;;;判断a1(直线一)、a2(直线二)的方位角(逆时针)、(顺时针)是否大于一个圆周(360度)

;;;;;;;;;;;;;;;判断a1(直线一)的方位角(逆时针)是否大于一个圆周(360度)

(if (> a1 (* 2 3.1415926))

(setq a1 (- a1 (* 2 3.1415926))))

;;;;;;;;;;;;;;;判断a1(直线一)的方位角(顺时针)是否大于一个圆周(360度)

(if (< a1 (* -2 3.1415926))

(setq a1 (+ a1 (* 2 3.1415926))))

;;;;;;;;;;;;;;;判断a2(直线二)的方位角(逆时针)是否大于一个圆周(360度)

(if (> a2 (* 2 3.1415926))

(setq a2 (- a2 (* 2 3.1415926))))

;;;;;;;;;;;;;;;判断a2(直线二)的方位角(顺时针)是否大于一个圆周(360度)

(if (< a2 (* -2 3.1415926))

(setq a2 (+ a2 (* 2 3.1415926))))

;;;;;;;;;;;求点

(setq u1 (sin a1))

(setq u2 (cos a1))

(setq u3 (/ u1 u2))

;;;;;;;;;;(直线2斜率

(setq w1 (sin a2))

(setq w2 (cos a2))

(setq w3 (/ w1 w2))

;;;;;;;;判断斜率是否等

(setq k1 (- w3 u3))

(if (= 0 k1)

(setq k1 (+ k1 0.000000000000001)))

;;;;;;;;;求交点

(setq jd1x (/ (+ (* -1 u3 a10x) (* w3 a20x) (* -1 a20y) a10y) k1));;;;;交点X坐标

(setq jd1y (+ a10y (* u3 jd1x) (* -1 u3 a10x)));;;;;;;;交点Y坐标

;;;;;;;;;求出1与交点方位角,交点与4方位角

(setq da10xjd1x (- jd1x a10x))

(setq da10yjd1y (- jd1y a10y))

(setq djd1xa21x (- a21x jd1x))

(setq djd1ya21y (- a21y jd1y))

;;;;;;;;;;;判断除数是否为零(方位角是否为:0、90、180、270、360度)

(if (= da10xjd1x 0) (setq da10xjd1x (+ da10xjd1x 0.000000000000001)))

(if (= da10yjd1y 0) (setq da10yjd1y (+ da10yjd1y 0.000000000000001)))

(if (= djd1xa21x 0) (setq djd1xa21x (+ djd1xa21x 0.000000000000001)))

(if (= djd1ya21y 0) (setq djd1ya21y (+ djd1ya21y 0.000000000000001)))

;;;;;;;;判断方位角象限(一、二、三、四)

;;;;;;;;;判断直线一

;;;;;;;;;一象限

(if (and (> da10xjd1x 0)

(> da10yjd1y 0))

(setq a1j (atan (/ da10yjd1y da10xjd1x))))

;;;;;;;;;二象限

(if (and (< da10xjd1x 0)

(> da10yjd1y 0))

(setq a1j (+ 3.1415926 (atan (/ da10yjd1y da10xjd1x)))))

;;;;;;;;;三象限

(if (and (< da10xjd1x 0)

(< da10yjd1y 0))

(setq a1j (+ 3.1415926 (atan (/ da10yjd1y da10xjd1x)))))

;;;;;;;;;四象限

(if (and (> da10xjd1x 0)

(< da10yjd1y 0))

(setq a1j (+ (* 2 3.1415926) (atan (/ da10yjd1y da10xjd1x)))))

;;;;;;;;;判断直线二

;;;;;;;;;一象限

(if (and (> djd1xa21x 0)

(> djd1ya21y 0))

(setq a2j (atan (/ djd1ya21y djd1xa21x))))

;;;;;;;;;二象限

(if (and (< djd1xa21x 0)

(> djd1ya21y 0))

(setq a2j (+ 3.1415926 (atan (/ djd1ya21y djd1xa21x)))))

;;;;;;;;;三象限

(if (and (< djd1xa21x 0)

(< djd1ya21y 0))

(setq a2j (+ 3.1415926 (atan (/ djd1ya21y djd1xa21x)))))

;;;;;;;;;四象限

(if (and (> djd1xa21x 0)

(< djd1ya21y 0))

(setq a2j (+ (* 2 3.1415926) (atan (/ djd1ya21y djd1xa21x)))))

;;;;;;;;;;;;;;;;;;判断a1(直线一)、a2(直线二)的方位角(逆时针)、(顺时针)是否大于一个圆周(360度)

;;;;;;;;;;;;;;;判断a1(直线一)的方位角(逆时针)是否大于一个圆周(360度)

(if (> a1j (* 2 3.1415926))

(setq a1j (- a1j (* 2 3.1415926))))

;;;;;;;;;;;;;;;判断a1(直线一)的方位角(顺时针)是否大于一个圆周(360度)

(if (< a1j (* -2 3.1415926))

(setq a1j (+ a1j (* 2 3.1415926))))

;;;;;;;;;;;;;;;判断a2(直线二)的方位角(逆时针)是否大于一个圆周(360度)

(if (> a2j (* 2 3.1415926))

(setq a2j (- a2j (* 2 3.1415926))))

;;;;;;;;;;;;;;;判断a2(直线二)的方位角(顺时针)是否大于一个圆周(360度)

(if (< a2j (* -2 3.1415926))

(setq a2j (+ a2j (* 2 3.1415926))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;求出(直线一)与(直线二)偏角

(setq a31 (abs (- a1j a2j)))

(if (= "3.14159" a31) (quit))

(setq a3 a31)

;;;;;;;;;;;;;;;判断偏角是否大于180度

(if (> a3 3.1415926)

(setq a3 (- (* 2 3.1415926) a3)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;半偏角、半圆角

(setq a4 (/ a3 2))

;;;;;;;;;;;;;输入半径

(setq r1 (getreal "\n圆角半径:"))

;;;;;;;半径数值出错循环

(while (= nil r1)

(setq r1 (getreal "\n圆角半径:")))

;;;;;;;;求出切线长

(setq n1 (sin a4))

(setq n2 (cos a4))

(setq n3 (/ n1 n2))

(setq t1 (* n3 r1))

;;;;;;;;;求出外距长

(setq e1(- (/ r1 n2) r1))

;;;;;;;;;求出曲线长

(setq m1 (* a3 180))

(setq m2 (/ m1 3.1415926))

(setq m3 (/ m2 360))

(setq m4 (* 2 3.1415926 r1))

(setq l1 (* m3 m4))

;;;;;;;;;角度转换

;;;;;;;;弧度转换为度

(setq a5 (/ (* a3 180) 3.1415926))

;;;;;;;;度转换为度分秒

(setq a6 (fix a5));;;;;;;度

(setq a7 (fix (* (- a5 a6) 60)));;;;;;;;分

(setq a8 (fix (* (- (* (- a5 a6) 60) a7) 60)));;;;;;;;秒

(hjx);;;;;;;;调用画矩形函数(HJX)

(princ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;画矩形

(defun hjx()

(command "osnap" "off")

(setq d0 (getpoint "\n标注基点:"));;;;;;;;;;;标注基点

(while (= nil d0)

(setq d0 (getpoint "\n标注基点:")))

(setq d1 (list (+ (car d0) 23) (+ (cadr d0) 25)))

(command "rectang" d0 d1 )

(bzwz);;;;;;;;调用标注文字函数(BZWZ)

(princ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;标注文字

(defun bzwz()

(setq f1 (list (+ (car d0) 1) (+ (cadr d0) 1)))

(setq f2 (list (car f1) (+ (cadr f1) 5)))

(setq f3 (list (car f2) (+ (cadr f2) 5)))

(setq f4 (list (car f3) (+ (cadr f3) 5)))

(setq f5 (list (car f4) (+ (cadr f4) 5)))

(command "text" f5 "2.5" "0" (strcat "a=" (rtos a6 2 0) "%%d" (rtos a7 2 0) "\U+2032" (rtos a8 2 0) "\U+2033"))

(command "text" f4 "2.5" "0" (strcat "R=" (rtos r1 2 3) "m"))

(command "text" f3 "2.5" "0" (strcat "T=" (rtos t1 2 3) "m"))

(command "text" f2 "2.5" "0" (strcat "L=" (rtos l1 2 3) "m"))

(command "text" f1 "2.5" "0" (strcat "E=" (rtos e1 2 3) "m"))

(reerr)

(princ)

(yj);;;;;;;;调用圆角函数(YJ)

(princ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;圆角

(defun yj()

(setierr)

(command "fillet" "r" r1)

(command "fillet" )

(princ)

)

;*************************************************************

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值