本帖最后由 林霄云 于 2014-1-21 12:16 编辑
标高符号v2——调整逻辑,支持UCS
原版本 标高符号源码解析与测试(左击缩小grread,生成对象entmakex应用)
http://bbs.mjtd.com/forum.php?mo ... 087&fromuid=7303580
子程序- elev-symbol(str pt)
- ;函数elev-symbol(str pt),参数str:string pt:point(UCS下),返回值,生成对象的选择集
- ;Desiged by 林霄云 2014年1月20日
复制代码 进行如下修改,以增加UCS支持,感谢G版照顾与其坐标系统解读。- (setq ucszdir (trans '(0 0 1) 1 0 T ));生成OCS法向量
- (setq ang (angle '(0 0 0) (trans (getvar "UCSXDIR") 0 ucszdir)));生成UCS在OCS的角度,不通过组码,通过旋转实现
- (setq pte (trans (trans pt 1 0) 0 ucszdir ));将插入点从UCS转WCS后转OCS
对硬编码的点,转换到OCS坐标系下- (setq pt-text10 (mapcar '+ pte (trans '(350 325 0) 0 ucszdir)))
- (setq pt-text11 (mapcar '+ pte (trans '(460 325 0) 0 ucszdir )))
- (setq pt-pl1 (mapcar '+ pte (trans '(225 225 0) 0 ucszdir )))
- (setq pt-pl2 (mapcar '+ pte (trans '(-225 225 0) 0 ucszdir )))
- (setq pt-pl3 (mapcar '+ pte (trans '(1145 225 0) 0 ucszdir )))
- (setq pt-l1 (mapcar '+ pte (trans '(-275 0 0) 0 ucszdir )))
- (setq pt-l2 (mapcar '+ pte (trans '(275 0 0) 0 ucszdir )))
将entmakex里的组码210修改为加入旋转,通过command实现,pt为UCS下的点- (command "rotate" ss "" pt (angtos ang 0))
主函数逻辑修改,主要针对grread函数- (prompt "\n缩小一半左击或S,放大一倍A,逆时针旋转R,顺时针旋转E,右击确认继续")
- (while (and (setq ptr (grread t 15 2))
- (not (and (= 2 (car ptr)); 键盘事件
- (or (= 13 (cadr ptr)) (= 32 (cadr ptr))) ;_Enter Space
- ))
- (not (or (= (car ptr) 11) (= (car ptr) 25)));_Mouse Right button
- )
- ; (redraw)
- (cond ((= (car ptr) 3);_Mouse Left button
- (command "scale" ss "" pt 0.5) ;左键进行0.5倍缩小,测试ss选择集方式可行。
- ))
- (cond ((= (car ptr) 2);键盘事件
- (if (or (= (ascii "S") (cadr ptr)) (= (ascii "s") (cadr ptr))) (command "scale" ss "" pt 0.5))
- (if (or (= (ascii "A") (cadr ptr)) (= (ascii "a") (cadr ptr))) (command "scale" ss "" pt 2))
- (if (or (= (ascii "R") (cadr ptr)) (= (ascii "r") (cadr ptr))) (command "rotate" ss "" pt 90))
- (if (or (= (ascii "E") (cadr ptr)) (= (ascii "e") (cadr ptr))) (command "rotate" ss "" pt -90))
- ))
- );while
值得注意的是,command Rotate 时,可以接收string类型作为角度值。
结论:
较强的逻辑性,更加丰富的grread应用。
|