我试图修改李·麦克几周前为我写的LISP,我用它在与现有块相同的插入点插入一个块。Lee的代码使用excell电子表格作为输入,用于在图形中查找块列表。由于代码已经找到了每个块,我认为它应该也能够插入新块。我就是不知道如何在不让用户点击的情况下编码插入点。
- (defun c:BLOCKINSERT (/ file nl lst Minp Maxp pts elst ipt)
- (vl-load-com)
- (if (setq file
- (getfiled "Select Text File"
- (if *load
- *load
- ""
- )
- "txt"
- 8
- )
- )
- (progn
- (setq *load file
- file (open file "r")
- )
- (while (setq nl (read-line file))
- ;(princ nl)
- (setq lst (cons (car (StrBrk nl 9)) lst))
- )
- (close file)
- (princ "\n<< Closed file >>")
- (if (setq elst (vl-remove-if
- 'null
- (mapcar 'handent
- (mapcar
- (function
- (lambda (x)
- (substr x 2)
- )
- )
- (reverse lst)
- )
- )
- )
- )
- (foreach Obj (mapcar 'vlax-ename->vla-object elst)
- (vla-getBoundingBox Obj 'Minp 'Maxp)
- (setq pts (mapcar 'vlax-safearray->list (list Minp Maxp)))
- (vla-ZoomCenter
- (vlax-get-acad-object)
- (vlax-3D-point
- (polar (car pts)
- (apply 'angle pts)
- (/ (apply 'distance pts) 2.)
- )
- )
- 400.
- )
- [color=red](setq ipt (assoc 10 entget (Obj))) [/color]
- [color=red] (command "-insert" "KEY_MG_RED" ipt 1 1 0)[/color]
- )
- )
- )
- (princ "\n<< No File Selected >>")
- )
- (princ)
- )
- (defun StrBrk (str chrc / pos lst)
- (while (setq pos (vl-string-position chrc str))
- (setq lst (cons (substr str 1 pos) lst)
- str (substr str (+ pos 2))
- )
- )
- (reverse (cons str lst))
- )
有人能给我指出正确的方向吗?
格伦 |