Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

dwgprefix and dwgname to attribute text

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
darryl.m.bowen
2216 Views, 5 Replies

dwgprefix and dwgname to attribute text

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.  

5 REPLIES 5
Message 2 of 6
_Tharwat
in reply to: darryl.m.bowen

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)

 

Message 3 of 6
pbejse
in reply to: darryl.m.bowen

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

 

 

Message 4 of 6
Lee_Mac
in reply to: darryl.m.bowen

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

Message 5 of 6
ethan.donnelly
in reply to: Lee_Mac

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?

Message 6 of 6
john.uhden
in reply to: ethan.donnelly

I am pretty sure that DOSLIB contains such a function.

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost