Find the extension .dwg!

Find the extension .dwg!

boyds86
Enthusiast Enthusiast
405 Views
3 Replies
Message 1 of 4

Find the extension .dwg!

boyds86
Enthusiast
Enthusiast

(defun c:TEST()
(setq A (getvar "dwgname"))
(setq B "dwg")
(if (equal (substr A (- (strlen A) 3)(strlen A)) B)
(command "QSAVE")(command "_.close" "y" ""))

(princ)
)

--------------

 

Hello,

 

I am trying to build a lisp that if filename extention is .dwg will be close without save (for any change). Otherwise, It will be saved (specify that filename is .dxf).

But the lisp above is not working. It alway (command "_.close" "y" "") for any .dwg&.dxf.

Does anybody know the reason why?

Thank you for yourtime!

0 Likes
Accepted solutions (1)
406 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi

The substr function index is 1 based (i.e. the first character in the string is position 1).

You should write:

 

(if (equal (substr A (- (strlen A) 2) (strlen A)) B) ...)

 

Or, simply:

(if (= (vl-filename-extension A) ".dwg") ...)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

boyds86
Enthusiast
Enthusiast
Wow! It is great, Thank you very much!
0 Likes
Message 4 of 4

WeTanks
Mentor
Mentor

the address where the file is saved,
Can it be added as a fixed place?
For example, C:\1

(defun c:TEST()
(setq A (getvar "dwgname"))
(setq B "dwg")
(if 
(= (vl-filename-extension A) ".dwg")
(command "QSAVE")
(command "_.close" "y" "")
)
(princ)
)

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes