本帖最后由 Gu_xl 于 2011-1-28 18:54 编辑
回复 cj52000 的帖子
- ;;;(tk 图块名) 2010.12.14 By Gu_xl
- (defun tk(tkname p1 p2 / pp1 pp2 v h v1 h1 xscale yscale)
-
- (setq pp1 (mapcar '(lambda (x)(apply 'min x)) (apply 'mapcar (cons 'list (list p1 p2))))
- pp2 (mapcar '(lambda (x)(apply 'max x)) (apply 'mapcar (cons 'list (list p1 p2))))
- v (- (cadr pp2) (cadr pp1))
- h (- (car pp2) (car pp1))
- )
- (if (> h v)
- (setq v (/ h (/ 420. 297.)))
- (setq h (/ v (/ 420. 297.)))
- )
- (command "insert" tkname pp1 1 1 0)
- (setq en (entlast))
- (vla-getboundingbox (vlax-ename->vla-object en) 'p1 'p2)
- (setq pl (mapcar 'vlax-safearray->list (list p1 p2)))
- (setq p1 (vlax-safearray->list p1)
- p2 (vlax-safearray->list p2)
- v1 (- (cadr p2) (cadr p1))
- h1 (- (car p2) (car p1))
- )
- (cond ((and (> h v) (>= h1 v1))
- (setq xscale (/ h h1)
- yscale (/ v v1)
- rot 0
- )
- )
- ((and (> h v) (>= v1 h1))
- (setq yscale (/ h v1)
- xscale (/ v h1)
- rot -90
- )
- )
- ((and (> v h) (>= v1 h1))
- (setq xscale (/ v v1)
- yscale (/ h h1)
- rot 0
- )
- )
- ((and (> v h) (>= h1 v1))
- (setq yscale (/ v h1)
- xscale (/ h v1)
- rot 90
- )
- )
- )
- (entdel en)
- (command "insert" tkname pp1 xscale yscale rot)
- (setq en (entlast))
- (vla-getboundingbox (vlax-ename->vla-object en) 'p1 'p2)
- (setq pl (mapcar 'vlax-safearray->list (list p1 p2)))
- (setq p1 (vlax-safearray->list p1)
- p2 (vlax-safearray->list p2)
- )
- (command "move" en "" p1 pp1)
- (setq obj (vlax-ename->vla-object en))
- (if (= :vlax-true (vla-get-HasAttributes obj))
- (command "eattedit" en)
- )
- (princ)
- )
- ;;;测试
- (defun c:tk()
- (setq oldcmdecho (getvar "cmdecho"))
- (setq attreq (getvar "attreq"))
- (setvar "cmdecho" 0)
- (setvar "attreq" 0)
- (setq blkname (getstring "\n输入要插入的图框名称:"))
- (while (and (setq p1 (getpoint "\n插入图框角点:"))
- (setq p2 (GETCORNER p1 "图框另一角点")
- )
- )
- (tk blkname p1 p2)
- )
- (setvar "cmdecho" oldcmdecho)
- (setvar "attreq" attreq)
- (princ)
- )
|