如何根据鼠标点击坐标智能插入图块?
请问如何实现鼠标点击自动插入文件的功能,路径文件名格式如c:\tuku\756512-10.dwg。涉及到鼠标取点、运算,最后插入功能。具体如下:1、在图形界面上用鼠标点击任一点取个坐标,如(512325.22,3756252.55),X取前三位512,y舍掉第一位后取三位756组成文件名部分756512
2、另外文件名部分取剩下数值(325.22,252.55)计算,规则如下:把1000*1000大小的正方形分成4行4列16个正方形,赋给编号如下
1,2, 5,6
3,4, 7,8
9, 10, 13, 14
11,12, 15, 16
根据(325.22,252.55)计算知道该点在10这个方格内,得出文件名为756512-10,插入c:\tuku\756512-10.dwg这个文件。
本帖最后由 Gu_xl 于 2011-8-5 18:19 编辑
回复 myzwsc 的帖子
(DEFUN C:TT (/ PT X STRX Y X0 STRY Y0 STRNUM FILENAME inspt)
(while
(setq pt (getpoint "\n选取点位置:"))
(setq x (car pt)
strX (itoa (fix (* x 0.001)))
y (cadr pt)
x0 (- x (* 1000 (fix (* x 0.001))))
strY (itoa (fix (* 0.001 (- y (* 1e6 (fix (* y 1e-6)))))))
y0 (- y (* 1000 (fix (* y 0.001))))
)
(cond ((< x0 250)
(cond ((< y0 250)
(setq strNum "11")
(setq inspt (list (* 1000 (fix (* x 0.001)))
(* 1000 (fix (* y 0.001)))
0
)
)
)
((< y0 500)
(setq strNum "9")
(setq inspt (list (* 1000 (fix (* x 0.001)))
(+ 250 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 750)
(setq strNum "3")
(setq inspt (list (* 1000 (fix (* x 0.001)))
(+ 500 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 1000)
(setq strNum "1")
(setq inspt (list (* 1000 (fix (* x 0.001)))
(+ 750 (* 1000 (fix (* y 0.001))))
0
)
)
)
)
)
((< x0 500)
(cond ((< y0 250)
(setq strNum "12")
(setq inspt (list (+ 250 (* 1000 (fix (* x 0.001))))
(* 1000 (fix (* y 0.001)))
0
)
)
)
((< y0 500)
(setq strNum "10")
(setq inspt (list (+ 250 (* 1000 (fix (* x 0.001))))
(+ 250 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 750)
(setq strNum "4")
(setq inspt (list (+ 250 (* 1000 (fix (* x 0.001))))
(+ 500 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 1000)
(setq strNum "2")
(setq inspt (list (+ 250 (* 1000 (fix (* x 0.001))))
(+ 750 (* 1000 (fix (* y 0.001))))
0
)
)
)
)
)
((< x0 750)
(cond ((< y0 250)
(setq strNum "15")
(setq inspt (list (+ 500 (* 1000 (fix (* x 0.001))))
(* 1000 (fix (* y 0.001)))
0
)
)
)
((< y0 500)
(setq strNum "13")
(setq inspt (list (+ 500 (* 1000 (fix (* x 0.001))))
(+ 250 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 750)
(setq strNum "7")
(setq inspt (list (+ 500 (* 1000 (fix (* x 0.001))))
(+ 500 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 1000)
(setq strNum "5")
(setq inspt (list (+ 500 (* 1000 (fix (* x 0.001))))
(+ 750 (* 1000 (fix (* y 0.001))))
0
)
)
)
)
)
((< x0 1000)
(cond ((< y0 250)
(setq strNum "16")
(setq inspt (list (+ 750 (* 1000 (fix (* x 0.001))))
(* 1000 (fix (* y 0.001)))
0
)
)
)
((< y0 500)
(setq strNum "17")
(setq inspt (list (+ 750 (* 1000 (fix (* x 0.001))))
(+ 250 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 750)
(setq strNum "8")
(setq inspt (list (+ 750 (* 1000 (fix (* x 0.001))))
(+ 500 (* 1000 (fix (* y 0.001))))
0
)
)
)
((< y0 1000)
(setq strNum "6")
(setq inspt (list (+ 750 (* 1000 (fix (* x 0.001))))
(+ 750 (* 1000 (fix (* y 0.001))))
0
)
)
)
)
)
)
;;;补足三位数
(repeat (- 3 (strlen strY))
(setq strY (strcat "0" strY))
)
(repeat (- 3 (strlen strX))
(setq strX (strcat "0" strX))
)
;;;得到文件名
(setq filename (strcat strY strX "-" strNum ".dwg"))
;;;插入块
(if (setq filename (findfile (strcat "c:\\tuku\\" filename)))
(command "insert" filename inspt 1 1 0)
)
)
)
回复 Gu_xl 的帖子
太感谢版主了,你帮我解决了一个大问题。
使用过程中发现点问题:
1、第159行(setq filename (strcat strY strX "-" strNum))要改(setq filename (strcat strY strX "-" strNum ".dwg))才可以用;
2、我的图块插入点默认都是(0,0)过程简单很多,借鉴你的代码用(list 0 0 0)代替inspt
3、能否加个循环点击插图?
4、个别图没反应,手工尝试insert可以,是不是图纸原因? 回复 myzwsc 的帖子
(DEFUN C:TT (/ PT X STRX Y X0 STRY Y0 STRNUM FILENAME inspt)
(while
(setq pt (getpoint "\n选取点位置:"))
.
.
.
)
) 干嘛用得?用不上。。。G版真是超帅啊 插入地形图用的,文件名是有规律的,根据坐标命名的。 本帖最后由 qfkxc 于 2011-8-15 12:37 编辑
取消1000*1000方格限制,以1:500标准图幅250*250图名以上代码如何修改?
图幅排序如下:
82009100 82009125 82009150 82009175
81759100 81759125 81759150 81759175
81509100 81509125 81509150 81509175
图号名取X值坐标整米数前4位,Y值坐标前4位。
太专业了..用不上..看起来也是个繁琐的工序,有程序就好很多了 本帖最后由 myzwsc 于 2013-8-19 21:38 编辑
Gu_xl 发表于 2011-8-5 18:18 static/image/common/back.gif
回复 myzwsc 的帖子
(DEFUN C:TT (/ PT X STRX Y X0 STRY Y0 STRNUM FILENAME inspt)
谢谢版主,这个程序省很多插图时间。现在有点问题:插图点击过程中会出现插入错误,提示“**引用自身”,这时必须把这个文件找出来改个文件名就可以用insert命令插入,请教版主:有没有办法判断插入是否成功,如文件存在且插入不成功就把此文件复制到c:\temp下,更换文件名,再插入它。或者在插入的过程中直接改名,但原文件要保持不变。
再次谢谢版主。
页:
[1]