本帖最后由 Gu_xl 于 2012-3-26 19:09 编辑
回复 cj52000 的帖子
;;;动态调整填充比例 作者:Gu_xl
- ;;;2007以上版本适用
- (defun c:dhatchscale (/ flag p1 p2 p3 en enline gr d scale oldscale newscale enl obj olderr myerr origin)
- (defun myerr(msg)
- (setq *error* olderr)
- (command "_.undo" "_b")
- (princ)
- )
- (setq olderr *error* *error* myerr )
- (command "_.undo" "m")
- (setq flag t)
- (while flag
- (setq en (entsel "\n选择填充:"))
- (if (and en (= "HATCH" (cdr (assoc 0 (entget (car en))))))
- (setq flag nil)
- )
- )
- (setq obj (vlax-ename->vla-object (setq en (car en))))
- (vla-GetBoundingBox obj 'p2 'p3)
- (setq p2 (vlax-safearray->list p2)
- p3 (vlax-safearray->list p3)
- p1 (mapcar '(lambda (x) (* 0.5 x)) (mapcar '+ p2 p3))
- )
-
- (setq d (* 0.1 (getvar "viewsize")))
- (setq scale (vla-get-PatternScale obj)
- AssociativeHatch (vla-get-AssociativeHatch obj)
- origin (vla-get-Origin obj)
- oldscale scale)
- (entmake (list (cons 0 "line") (cons 62 2) (cons 10 p1) (cons 11 (polar p1 0 d))))
- (setq enline (entlast))
- (vla-copy obj)
- (setq obj (vlax-ename->vla-object (entlast)))
- (vla-put-Origin obj origin)
- (vla-put-AssociativeHatch obj :vlax-false)
- (entdel en)
-
- (setq flag t)
- (while flag
- (setq gr (grread T 1))
- (if (= (car gr) 5)
- (progn
- (setq p2 (cadr gr))
- (entdel enline)
- (entmake (list (cons 0 "line") (cons 62 2) (cons 10 p1) (cons 11 p2)))
- (setq enline (entlast))
- (setq newscale (* scale (/ (distance p1 p2) d)))
- (if (not (equal newscale oldscale 0.01))
- (progn
- (vla-copy obj)
- (vla-delete obj)
- (setq obj (vlax-ename->vla-object (entlast)))
- (vla-put-PatternScale obj newscale)
- ;(vla-update obj)
- (setq oldscale newscale)
- )
- )
- )
- (progn
- (entdel enline)
- (setq flag nil)
- )
- )
- )
- (vla-delete obj)
- (entdel en)
- (setq obj (vlax-ename->vla-object en))
- (vla-put-PatternScale obj newscale)
- ;(vla-update obj)
- (setq *error* olderr )
- (princ)
- )
|