Detect File Extension, Exit LISP or Run LISP

Anonymous

Detect File Extension, Exit LISP or Run LISP

Anonymous
Not applicable

Hi everyone,

 

So I am trying to prevent my LISP from being run on any file type (mainly the .dwg) and only run on a .dxf extension.  I've searched the solutions on here but to no avail and I'm hoping I can get a little help (as always Smiley LOL)

 

Basically I would think the LISP would work like the following:

(defun C:Test ()

;IF this is a .dxf THEN

(command "SomeCommand" "" "" "" "")

(command "SomeCommand" "" "" "" "")

(prompt "\nProcess complete.")
ELSE

 

(prompt "\nTCannot run LISP - wrong file type")

;Exit this LISP

 

A rough outline for sure, but the basic idea is there. 

 

Any help (which has been great since I've joined by the way) would be greatly appreciated. 

 

 

Thanks,

McG

0 Likes
Reply
Accepted solutions (1)
1,017 Views
6 Replies
Replies (6)

Ranjit_Singh2
Advisor
Advisor

Try something like this

(vl-load-com)
(cond ((= (vl-filename-extension (getvar 'dwgname)) ".dxf") (put your commands here) (T (prompt "\nTCannot run LISP - wrong file type")) )

 

john.uhden
Mentor
Mentor

@Ranjit_Singh2's response was excellent.

But if the user has to choose a file, then try


(if (setq file (getfiled "Select DXF File" "" "dxf" 33)) ... Be careful of the last parameter, in this case 33.
It is a flag which controls whether you are looking to
create a new file and other limitations.
Look at the help for getfiled. In this example the user
is restricted to select a DXF file only, but also can create
a new file name (dxf only).

John F. Uhden

0 Likes

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

... 

So I am trying to prevent my LISP from being run on any file type (mainly the .dwg) and only run on a .dxf extension.  ....


Or, a version without the need for (vl...) functions:

 

(defun C:TEST ()

  (if (wcmatch (getvar 'dwgname) "*.dxf")

    (progn; then

      (... do this ...)

      (... do that ...)

      (prompt "\nProcess complete.")

    ); progn

    (prompt "\nCannot run LISP - wrong file type."); else

  ); if

  (princ)

); defun

Kent Cooper, AIA

Anonymous
Not applicable
Yes! This is it. Works perfectly. Thank you very much
0 Likes

Anonymous
Not applicable
Not exactly what is was looking to do. I will take your code and try to play around with it though. Much appreciated.
0 Likes

Anonymous
Not applicable
Couldn't quite get it to work but after a few attempts tweaking it i got it working. Thanks!
0 Likes