I have a title block that has attributed text. And in one of the fields we put the file path. I am looking for a lisp that will extract the dwgprefix to that block/attribute.
Information you might need.
Block name - ECCH_TITLE
Tag name - FILE_NAME
I will need it to get the drive all the way to the drawing name minus the .dwg.
Side note this is acad 2002.
Solved! Go to Solution.
Solved by _Tharwat. Go to Solution.
This ... ?
(defun c:Test (/ s n) ;; Tharwat 16. Jan. 2014 ;; (if (setq s (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1) (2 . "ECCH_TITLE")) ) ) (foreach x (vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'getattributes ) (if (eq (strcase (vla-get-tagstring x)) "FILE_NAME") (vla-put-textstring x (substr (setq n (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME))) 1 (- (strlen n) 4) ) ) ) ) ) (princ) ) (vl-load-com)
Another
(defun c:Test2 (/ s ) ;;; pBeJan. 2014 ;;; (if (setq s (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1) (2 . "ECCH_TITLE")) ) ) (vl-some (function (lambda (x) (if (eq (strcase (vla-get-tagstring x)) "FILE_NAME") (vla-put-textstring x (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME)) ) ) ) ) ) (vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'getattributes ) ) ) (princ) ) (vl-load-com)
HTH
Here's another (vanilla version):
(defun c:dwgatt ( / e f i s v x ) (setq v (strcat (getvar 'dwgprefix) (cadr (fnsplitl (getvar 'dwgname))))) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "ECCH_TITLE") (66 . 1)))) (repeat (setq i (sslength s)) (setq e (entnext (ssname s (setq i (1- i)))) x (entget e) f nil ) (while (and (not f) (= "ATTRIB" (cdr (assoc 0 x)))) (if (= "FILE_NAME" (strcase (cdr (assoc 2 x)))) (setq f (entmod (subst (cons 1 v) (assoc 1 x) x))) ) (setq e (entnext e) x (entget e) ) ) ) ) (princ) )
Though, in my opinion, it would be better to use RTEXT with a DIESEL expression set to:
$(getvar,dwgprefix)$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),4))
This way, the RTEXT would automatically update if the filename or path is altered.
Lee
I'm using the rtext method with the expression you provided, but is there any way to get it to display the UNC path instead of the mapped drive?