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

Custom lisp-script error: no function definition

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Anonymous
6980 Views, 16 Replies

Custom lisp-script error: no function definition

Hi

 

I've made a custom lisp-script to save my file to a new directory, make some changes, save it and open the old file. So far so good.

I've added it to APPLOAD (and bound it to a button). Works fine the first time, but when I want to run it the next time I get this error:

 

Command: _savefile ; error: no function definition: C:SAVEFILE

 When I look in APPLOAD it looks fine, the lisp-file is still there but it still can't find the command.

 

What can be wrong here?

 

Thanks!

 

 
16 REPLIES 16
Message 2 of 17
thavasi1982
in reply to: Anonymous

lnclude (vl-load-com)

Message 3 of 17
Anonymous
in reply to: thavasi1982

I've tried that, but with same result as before.

Message 4 of 17
thavasi1982
in reply to: Anonymous

Can you show the code.

Message 5 of 17
Anonymous
in reply to: thavasi1982

(vl-load-com)

(defun c:savemyfile ( / )
  (setq file (getvar "DWGNAME"))
  (setq path (getvar "DWGPREFIX"))
  (setq pathfile (strcat path file))

  (setq newpathfile (strcat "c:\\newfolder\\" file))

  (command "qsave")

  (vl-file-delete newpathfile)
  (princ)
  (command "_saveas" "2013" newpathfile)

  (command "PURGE" "ALL" "*" "N")
  (command "PURGE" "REGAPPS" "*" "N")
  (command "XREF" "D" "*")

  (command "qsave")

  (command "fileopen" pathfile)
)

 

Message 6 of 17
hmsilva
in reply to: Anonymous

Change the command name SAVEFILE is a System Variable...

Henrique

EESignature

Message 7 of 17
Anonymous
in reply to: hmsilva

I changed the name before I posted it here, its really called something else that's not a system variable, but I didn't think too much before going with savefile =P I'll just edit that in my last post.

Message 8 of 17
hmsilva
in reply to: Anonymous


@Anonymous wrote:

I changed the name before I posted it here, its really called something else that's not a system variable, but I didn't think too much before going with savefile =P I'll just edit that in my last post.


Try changing your button macro to something like this

(if (not c:YourCommandName)(load "YourLispFileName"));YourCommandName;

 

HTH

Henrique

EESignature

Message 9 of 17
thavasi1982
in reply to: Anonymous

I think your lisp open the new drawing from a new path with same file name. You need to load your Lisp again in the new drawing file. Otherwise you can add your lisp file in "Startup suite".

 

Try this. it may work.

 

STM

Message 10 of 17
Anonymous
in reply to: thavasi1982

Thanks, but I've already added it to the startup suite. Still the same result.... 😞
Message 11 of 17
thavasi1982
in reply to: Anonymous

"TRY THIS"

 

command: SDI

Enter new value for SDI <0>:1

 

 

STM

Message 12 of 17
Anonymous
in reply to: thavasi1982

Interesting. It works. But unforunately it's not an option to only be able to have one document open at the time... Isn't there any other way to get it to work?

Thanks thogh!
Message 13 of 17
thavasi1982
in reply to: Anonymous

Use (vla-open (vla-get-documents (vlax-get-acad-object)) pathfile 0) instead of (command "fileopen" pathfile)

 

Try this. It may work

 

STM

Message 14 of 17
Anonymous
in reply to: thavasi1982

Hmm... It sort of works. The problem now is that the "new" file does not close after it opens the old file again. So for each time I press the button another file is open... Any suggestions?
Message 15 of 17
Gary_J_Orr
in reply to: Anonymous

adding the the function to the startup suite works more along the lines of adding a load call to acad.lsp... and that is why it works in sdi mode and not in mdi mode.

you need it available in every document (or potentially may need it)... the same basic issue that you were having when writing the function...

Your choices are two (beyond changing SDI mode that is): add a call to load (or demand load) the function to your acaddoc.lsp or use HTH's suggestion to create a demand loader in the menu macro itself.(A method that I often employ for intermittent need functions)

-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 16 of 17
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
.... it's not an option to only be able to have one document open at the time... Isn't there any other way to get it to work?
....

It needs SDI=1 because otherwise, a Lisp routine can't "survive" moving into a different drawing, which is what SAVEAS does.  I would try this approach, which will not involve getting out of the drawing you're in, nor therefore getting back into it:

UNDO Mark;

Purges and Xref deletions;

Use the SAVE command [not to be confused with SAVEAS or QSAVE (the latter of which is what you get from ctrl-S and so-called "Save" menu items)] to the other location, which will make a new drawing file there, the same as the one you're in, without taking you into it, but will leave you in the drawing you're in;

UNDO Back to revert to before the Purges and Xref deletions.

Kent Cooper, AIA
Message 17 of 17
Anonymous
in reply to: Gary_J_Orr

Okey! Then it seems HTH's solution is the best. I'll just stick with that.

Thanks a lot everybody! Really appreciate all the help.

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

Post to forums  

Autodesk Design & Make Report

”Boost