本帖最后由 菜卷鱼 于 2015-6-27 17:21 编辑
因为系统带的find查找命令,完成之后总是要重生成一遍,大图纸就在那里卡卡卡卡卡卡,所以直接做了一个查找定位命令,现在只支持text,mtext,attdef文字,属性块。
提问:
1,find命令的定位效果如何实现的(效果见附图)?
2,多重引线的文字定位怎么做?
3,找到的多行文字里那些乱七八糟的格式代码如何去掉?
下面是我的源码,代码根据以前编的改的,没去做简化
- (defun sslist (ss / i ll)
- (setq i -1)
- (repeat (sslength ss)
- (setq ll(cons (ssname ss (setq i(1+ i)))ll))
- )
- )
- (defun c:see
- ( / str s2 ssme info opp adn1
- ad0 ad2 counter pp conte ad1 adn1 adn0
- sl)
- (setq *error* see_err)
- (setq sl nil)
- (if (= ostr nil)(setq ostr "#"))
- (mapcar 'princ (list "\nThe Characters wish to Find <" ostr ">:"))
- (setq str(getstring ))
- (if (= str "")(setq str ostr)(setq ostr str))
(setq searchword (strcat "*" str "*"))
(setq s1 (ssget "x"
(list '(-4 . "<or")
'(-4 . "<AND")
'(0 . "text,mtext") (cons 1 searchword)
'(-4 . "AND>")
'(-4 . "<AND")
'(0 . "ATTDEF") (cons 2 searchword)
'(-4 . "AND>")
;;;'(-4 . "<AND")
;; '(0 . "MULTILEADER") (cons 304 searchword)
;;'(-4 . "AND>") ;;;;不知道怎么定位文字,所以没加进去
'(-4 . "or>"))
))
(if (/= s1 nil)(setq sl(sslist s1)))
(setq ss2 (ssget "x" '((0 . "insert") (66 . 1)) ))
(if (/= ss2 nil)
(progn
(setq i -1)
(repeat (sslength ss2)
(setq en(ssname ss2 (setq i(1+ i))))
(setq nextobj (entnext en))
(setq adn0 (cdr(assoc 0(entget nextobj))))
(while (= adn0 "ATTRIB")
(setq adn1(obj2str nextobj))
;(setq adn1(cdr(assoc 1 (entget nextobj))))
(if (wcmatch adn1 searchword )
(progn
(if (= sl nil)(setq sl(list nextobj))
(setq sl(cons nextobj sl)))
)
)
(setq nextobj (entnext nextobj))
(setq adn0(cdr(assoc 0(entget nextobj))))
)
)
))
(setq x (length sl))
(setq sl(vl-sort sl (function(lambda (x1 x2)
(< (car(cdr(assoc 10(entget x1))))
(car(cdr(assoc 10(entget x2)))))
)))
)
(setq sl(vl-sort sl (function(lambda (x1 x2)
(> (cadr(cdr(assoc 10(entget x1))))
(cadr(cdr(assoc 10(entget x2)))))
)))
)
(setvar 'cmdecho 0)
(setq i 0)
(while (< i x)
(setq ssme(nth i sl))
(setq info(entget ssme))
(setq ad0 (cdr(assoc 0 info)))
(cond
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
((numberp(vl-string-search "ATTDEF" ad0))
(setq ad2(cdr(assoc 2 info)))
(if (/= (vl-string-search (strcase str) (strcase ad2))nil)
(progn
(princ (strcat "\nSearch results: " ad2))
(setq counter (1+ counter))
(setq pp(cornerp ssme))
(setvar 'NOMUTT 1)
;(command "zoom" (car pp)(cadr pp))
;(command "zoom" "s" "0.05x")
(IF (= (EQUAL PP OPP) NIL)
(command "zoom"
(mapcar '+ (car pp) (mapcar '(lambda (x) (* x 3))(mapcar '- (cadr pp)(car pp)) ) )
(mapcar '+ (cadr pp) (mapcar '(lambda (x) (* x 3))(mapcar '- (car pp)(cadr pp)) ) )
))
(setvar 'NOMUTT 0)
(redarrow (mapcar '/ (mapcar '+ (car pp)(cadr pp)) (list 2 2 2)))
)
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
((numberp(vl-string-search "TEXT" ad0))
(setq ad1(obj2str ssme))
(if
(/= (vl-string-search (strcase str) (strcase ad1))nil)
(progn
(princ (strcat "\nSearch results: " ad1))
(setq pp (text-box info 0))
(setvar 'NOMUTT 1)
(IF (= (EQUAL PP OPP) NIL)
(command "zoom"
(mapcar '+ (car pp) (mapcar '(lambda (x) (* x 3))(mapcar '- (cadr pp)(car pp)) ) )
(mapcar '+ (cadr pp) (mapcar '(lambda (x) (* x 3))(mapcar '- (car pp)(cadr pp)) ) )
))
(setvar 'NOMUTT 0)
(redarrow (mapcar '/ (mapcar '+ (car pp)(cadr pp)) (list 2 2 2)))
)
)) ;if,progn,cond()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
((= ad0 "ATTRIB")
(progn
(setq adn1(obj2str ssme))
(princ (strcat "\nSearch results: " adn1))
(setq pp(cornerp ssme))
(setvar 'NOMUTT 1)
(IF (= (EQUAL PP OPP) NIL)
(command "zoom"
(mapcar '+ (car pp) (mapcar '(lambda (x) (* x 3))(mapcar '- (cadr pp)(car pp)) ) )
(mapcar '+ (cadr pp) (mapcar '(lambda (x) (* x 3))(mapcar '- (car pp)(cadr pp)) ) )
))
(setvar 'NOMUTT 0)
(redarrow (mapcar '/ (mapcar '+ (car pp)(cadr pp)) (list 2 2 2)))
) progn
)
) ;(cond)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (= 1(- x i))(princ "\nThe last result!"))
(setq conte(getstring "\nBack or Continue [B/Yes/No]:<Yes>"))
(if (= (strcase conte) "B")
(progn
(setq i (- i 2))
(if(< i 0)
(progn
(setq i -1)
(princ "\nCan't back more!"))
)
))
(if (= (strcase conte) "N")(exit)(prin1))
(SETQ OPP PP)
(setq i(1+ i))
)
(princ "\nThe search is finished!")
(if (= sl nil)(princ "\nCharacters is not found!"))
(redraw)
;(UNDOE)
(setvar 'cmdecho 1)
(prin1)
)
;(PRINC "\nThe program if made by Caoyu\n")
(PRIN1)
(defun text-box ( enx off / b h j l m n o p r w )
(if
(setq l
(cond
( (= "TEXT" (cdr (assoc 0 enx)))
(setq b (cdr (assoc 10 enx))
r (cdr (assoc 50 enx))
l (textbox enx)
)
(list
(list (- (caar l) off) (- (cadar l) off))
(list (+ (caadr l) off) (- (cadar l) off))
(list (+ (caadr l) off) (+ (cadadr l) off))
(list (- (caar l) off) (+ (cadadr l) off))
)
)
( (= "MTEXT" (cdr (assoc 0 enx)))
(setq n (cdr (assoc 210 enx))
b (trans (cdr (assoc 10 enx)) 0 n)
r (angle '(0.0 0.0 0.0) (trans (cdr (assoc 11 enx)) 0 n))
w (cdr (assoc 42 enx))
h (cdr (assoc 43 enx))
j (cdr (assoc 71 enx))
o (list
(cond
((member j '(2 5 8)) (/ w -2.0))
((member j '(3 6 9)) (- w))
(0.0)
)
(cond
((member j '(1 2 3)) (- h))
((member j '(4 5 6)) (/ h -2.0))
(0.0)
)
)
)
(list
(list (- (car o) off) (- (cadr o) off))
(list (+ (car o) w off) (- (cadr o) off))
(list (+ (car o) w off) (+ (cadr o) h off))
(list (- (car o) off) (+ (cadr o) h off))
)
)
)
)
( (lambda ( m ) (mapcar '(lambda ( p ) (mapcar '+ (mxv m p) b)) l))
(list
(list (cos r) (sin (- r)) 0.0)
(list (sin r) (cos r) 0.0)
'(0.0 0.0 1.0)
)
)
)
)
;; Matrix x Vector - Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n
(defun mxv ( m v )
(mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
)
(defun obj2str (obj)
(vlax-get (vlax-ename->vla-object obj) 'TextString)
)
(defun redarrow (pting)
(redraw)
(setq arrowsize (* 0.005 (getvar "viewsize")))
(setq rowpt1 (polar pting (angtof "240") (* arrowsize 24)))
(setq rowpt2 (polar rowpt1 0 (* arrowsize 9)))
(setq rowpt3 (polar rowpt2 (angtof "270") (* arrowsize 20)))
(setq rowpt4 (polar rowpt3 (angtof "60") (* arrowsize 6)))
(setq rowpt5 (polar rowpt4 (angtof "300") (* arrowsize 6)))
(setq rowpt6 (polar rowpt5 (angtof "90") (* arrowsize 20)))
(setq rowpt7 (polar rowpt6 0 (* arrowsize 9)))
(setq rowpt8 (polar rowpt7 (angtof "120") (* arrowsize 24)))
(grvecs (list
1 pting rowpt1
1 rowpt1 rowpt2
1 rowpt2 rowpt3
1 rowpt3 rowpt4
1 rowpt4 rowpt5
1 rowpt5 rowpt6
1 rowpt6 rowpt7
1 rowpt7 rowpt8
1 rowpt8 pting)
)
(prin1)
)
(defun see_err (s)
(redraw)
(setvar 'NOMUTT 0)
;(UNDOE)
(setvar "cmdecho" 1)
(prin1))
- (defun sslist (ss / i ll)
- (setq i -1)
- (repeat (sslength ss)
- (setq ll(cons (ssname ss (setq i(1+ i)))ll))
- )
- )
|