本帖最后由 cabinsummer 于 2016-12-24 15:08 编辑
- (defun c:bg(/ ename0 InsY Y Y0 loop code ename edata snap near blkdata scl pnt height fname)
- (setvar "CMDECHO" 0)
- (defun myerr(msg)
- (command "undo" "e")
- (if ename (entdel ename))
- (setq *error* olderr)
- )
- (defun create()
- (command "insert" "KUAI" '(0.0 0.0 0.0) scl scl "0" "0.000")
- (setq ename (entlast))
- (setq edata (entget (entnext ename)))
- )
- (defun insert()
- (setvar "DIMZIN" 0)
- (setq pnt0 (getpoint "请选择插入点\n"))
- (setq height (rtos (getreal "请输入基准标高\n") 2 3))
- (setq scl (getvar "dimscale"))
- (command ".insert" fname pnt0 scl scl "0" height)
- )
- (defun do_right()
- (setq loop nil)
- (entdel ename)
- )
- (defun do_move()
- (setq snap (cadr code))
- (entdel ename)
- (setq near (osnap snap "nea"))
- (entdel ename)
- (setq Y (nth 2 (assoc 10 (entget ename))))
- (setq Y (+ (/ (- Y InsY) 1000.0) Y0))
- (if near (setq snap near))
- (entmod (subst (cons 10 snap)(assoc 10 (setq blkdata (entget ename))) blkdata))
- (setq edata (subst (cons 10 (mapcar '+ (list (* scl 2.25)(* scl 3.42) 0.0) snap))(assoc 10 edata) edata))
- (entmod edata)
- (entmod (subst (cons 1 (rtos Y 2 3))(assoc 1 edata) edata))
- (entupd ename)
- (entupd (entnext ename))
- )
- (setq olderr *error*)
- (setq *error* myerr)
- (command "undo" "be")
- (if (or (and (not (tblsearch "block" "KUAI"))(setq fname (findfile "KUAI.dwg")))(not (ssget "x" '((0 . "INSERT")(2 . "KUAI")))))(insert))
- (if (and (setq ename0 (car (entsel "请选择标高基准\n")))(= (cdr (assoc 2 (entget ename0))) "KUAI"))
- (progn
- (setq InsY (nth 2 (assoc 10 (entget ename0))))
- (setq scl (cdr (assoc 41 (entget ename0))))
- (setq Y0 (atof (cdr (assoc 1 (entget (entnext ename0))))))
- (create)
- (setq loop T)
- (while loop
- (setq code (grread T 8))
- (cond
- ((= (car code) 5)(do_move))
- ((= (car code) 3)(create))
- ((or (= (car code) 11)(= (car code) 25))(do_right))
- )
- )
- )
- )
- (command "undo" "e")
- (setq *error* olderr)
- (princ)
- )
将KUAI.dwg放到支持目录里,加载bg.lsp
命令:BG
根据命令行提示操作,先选择基准标高。
左键选择,右键退出
|