Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

file name without the dwg.

3 REPLIES 3
Reply
Message 1 of 4
darryl.m.bowen
1071 Views, 3 Replies

file name without the dwg.

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

 

3 REPLIES 3
Message 2 of 4


@darryl.m.bowen wrote:

I can get just the file name but I cannot get rid of the ".dwg". 

 


 

(vl-filename-base (getvar "dwgname"))

Message 3 of 4
jggerth1
in reply to: darryl.m.bowen

You could also use a FIELD, and set the attribute value that way.

Message 4 of 4
doni49
in reply to: darryl.m.bowen

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.  Smiley Embarassed  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




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

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

Post to forums  

Autodesk Design & Make Report

”Boost