I can get just the file name but I cannot get rid of the ".dwg". I have tried the (vl-string-position but to no avail. I have seen several lisp on here and have tried to compile them to make it work but that too has failed.
I have included the lisp below, Works with any attribute.
(defun c:flnm ( ;put the current drawing filename into an attribute
/ ;no arguments
) ;end of local variable list
(cond
((not (setq ent (nentsel)))
nil
)
((not (setq
elist (entget (car ent))
temp (= "ATTRIB" (cdr (assoc 0 elist)))
) ;_ end of setq
) ;_ end of not
(princ "\nNot an attribute. ")
)
(T
(setq
elist
(subst
(cons 1 (strcat (getvar "dwgname")))
(assoc 1 elist)
elist
) ;_ end of subst
) ;_ end of setq
(entmod elist)
(entupd (cdr (assoc -1 elist)))
)
) ;_ end of cond
(princ)
) ;_ end of defun
@darryl.m.bowen wrote:I can get just the file name but I cannot get rid of the ".dwg".
(vl-filename-base (getvar "dwgname"))
If you're trying to use AutoLISP to return just the filename portion (without the period or extension) of the current file:
(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))
Substr will extract a portion of the specified string. The 1 tells it to start with the 1st character. Then this says to figure out how long the string is and stop 4 characters from the end.
EDIT: or there's what Jason said. I haven't worked much with the VL functions so I didn't pick up on that. I decided to try what he sauggested but only thought to do so after I posted.
Don Ireland
Engineering Design Technician