Autolisp编程求助(autolisp编程求助)
autolisp编程求助
(defun c:tiqu(/ a b c)
(setq c(getstring"输入点号:"))
(setq a(getpoint"\n选取点:"))
(terpri)(terpri)
(setq b(open "C:\\Documents and Settings\\Administrator\\桌面\\坐标.txt" "a"))
(print (list c a) b)
(close b)
(princ)
(c:tiqu)
)
好,我就再帮你一次吧,看看是不是这个效果?
(defun c:tiqu(/ a b i)
(setq i (uint 1 "" "\n起始编号:" 1))
(while
(setq a(getpoint"\n选取点:"))
(terpri)
(setq b(open "C:\\Documents and Settings\\Administrator\\桌面\\坐标.txt" "a"))
(print (list i a) b)
(close b)
(setq i (+ 1 i))
(princ)))
(defun ureal (bit kwd msg def / inp)
(if def
(setq msg (strcat "\n" msg "<" (rtos def 2) ">: ")
bit (* 2 (fix (/ bit 2))) )
(setq msg (strcat "\n" msg ": ")) )
(initget bit kwd)
(setq inp (getreal msg))
(if inp
inp
def ) )
(defun uint (bit kwd msg def / inp)
(if def
(setq msg (strcat "\n" msg "<" (itoa def) ">: ")
bit (* 2 (fix (/ bit 2))) )
(setq msg (strcat "\n" msg ": ")) )
(initget bit kwd)
(setq inp (getint msg))
(if inp
inp
def ))
AUTOLISP编程求助,如何得到屏幕的中点的坐标?
很简单的一个系统变量就能获得,参见下面代码:
(setq pt (getvar "viewctr"))
如果你还想获得屏幕的四个角点的坐标,可以利用系统变量viewsize screensize配合上面得到的屏幕中心坐标获得。
下面在给你个代码,可以获得当前拾取框的高度,在你选取实体的时候这个代码很有用:
;|
求拾取框的高度
|;
(defun $XDLSP_Drawing_getPickboxHeight ()
(* (/ (getvar "pickbox") (cadr (getvar "screensize"))) (getvar "viewsize"))
)
上面代码摘自晓东工具箱里面的系统代码库里面的代码。
这是cad的autolisp的编程题,求助啊、、、
;;;计算某直线外一点到直线的最短距离,即为垂线,不判断垂足点是否在直线上
;;;设定命令为mm
(defun c:mm()
(setvar "cmdecho" 0)
(setq pt1 (getpoint "第1点"))
(setq pt2 (getpoint "第2点"))
(setq pt3 (getpoint "第3点"))
(command "line" pt1 pt2 "")
(command "point" pt3 "")
;;;
;;;不判断pt1、2、3是否共线,
;;; 方法一:
;;;pt4x,pt4y点的确定
;;;
;;;分别获取pt1、2、3的坐标值
(setq pt1x (car pt1))
(setq pt1y (cadr pt1))
(setq pt2x (car pt2))
(setq pt2y (cadr pt2))
(setq pt3x (car pt3))
(setq pt3y (cadr pt3))
;;;计算方法:
;;;pt4与pt1 pt2 共线
;;;(pt4x-pt1x)/(pt4y-pt1y)=(pt2x-pt1x)/(pt2y-pt1y)
;;;
;;;pt4 pt3的斜率与pt1 pt2的斜率乘积为1
;;;(pt4x-pt3x)/(pt4y-pt3y)*(pt2x-pt1x)/(pt2y-pt1y)=-1
;;;自行解方程计算出pt4x、y的表达式
;;;计算pt3到直线pt1 pt2的最短距离
(setvar dist (sqrt( (pt4x-pt3x)*(pt4x-pt3x)+(pt4y-pt3y)*(pt4y-pt3y) ) ) )
;;;方法二:
;;;使用getdist函数,不计算具体的垂足点的坐标
;;;开启对象捕捉仅为垂足点
(setq dist (getdist pt3 (“选择垂足点”)))
(princ)
)
autolisp编程求助
听着都很复杂啊~~