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

S::Startup

10 REPLIES 10
Reply
Message 1 of 11
kevinmulvaney
474 Views, 10 Replies

S::Startup

I am new to lisp and just need to add a little lisp that will run at startup. It closes the first drawing without saving. I have gotten it to work and it seems that I need to add it to the S::Startup area. I don't really know where that is.





(Defun C:cc () (command "close" "y") (princ) )
That's the lisp i want to run it's called close1st.lsp

Thanks for any help



Kevin
Kevin Mulvaney, CAD/Revit Manager
PKA ARCHITECTS
Portland Oregon
10 REPLIES 10
Message 2 of 11
arcticad
in reply to: kevinmulvaney

(DEFUN S::startup ()
' do something
)

The file isn't really anyplace. You need to add this to the lisp file and then load the lisp file on startup.

use appload and add your lisp file to the startup contents.

it will load and execute whatever is inside of startup.
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 11
scot-65
in reply to: kevinmulvaney

There are many ways to load LISP.

The S::STARTUP area is for things to happen at the very last when the editor is starting up.
Also inside one can place commands as no other place will allow commands to run during the startup process.
Follow as other replies show, or you can also create an ACAD.lsp file.
This file, when found in the support path, will automatically load
(I do not know where you placed S::STARTUP, but keep on building!!).

Inside the ACAD.lsp file you may have something like this:
(defun c:CC () (load "CC") (c:CC) (princ) ) ;closes first drawing
-OR-
(defun c:CC () (load "close1st") (c:CC) (princ) ) ;closes first drawing

It is suggested that you name the file the same as the command name.
As you get more involved with LISP you will need to better organize yourself.

Next, create this file and place in a (declare a) support path.
Name the folder "My LISPS" (see attachment)

Now, inside S::STARTUP, simply make a call to this LISP: (c:CC)

If the command is not a keyboard command, you can simply load it: (load "CC").
Just cancel out the first and last lines of your program and it will behave like a script.

Another place to declare the routine is in MyMenu.MNL.
If there is not one, then create it and place in same folder as MyMenu.CUI.
Again, this file, once found in the support path, will automatically load.

The down and dirty way to load a routine is via startup suite.

Good Luck!

(I'm having trouble loading the attachment)

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 4 of 11
Anonymous
in reply to: kevinmulvaney

Kevin:

AutoCAD executes a function named (S::STARTUP) (if one is defined) after
the editor is initialized. You just need to add code to your acad.lsp file
to define or modify (S::STARTUP) so that it executes the code you want to
run. If you don't already have an acad.lsp file, create one with Notepad.
In acad.lsp, add the following code:

{code:lisp}
;; Fancy function to add new function to existing S::STARTUP
;; no matter how it was defined by preceding startup code
(defun AddToStartup (func)
(if
(and
(listp func)
(member (type (eval (car func))) '(LIST USUBR SUBR EXSUBR EXRXSUBR)))
(cond
( (and S::STARTUP (listp S::STARTUP))
(setq S::STARTUP (append S::STARTUP (list func '(princ)))))
( (member (type S::STARTUP) '(USUBR SUBR EXSUBR EXRXSUBR))
(setq S::STARTUP (list nil (list S::STARTUP) func '(princ))))
( (setq S::STARTUP (list nil func '(princ))))))
)

;; Better version that only closes the untitled drawing and uses
;; underscore prefixed commands so it works correctly in all languages
(defun C:CC () (if (zerop (getvar "DWGTITLED")) (command "_CLOSE" "_Y"))
(princ))
(AddToStartup '(C:CC))
{code}

It's important for your code to play nice and not overwrite an existing
S::STARTUP function. The purpose of the (AddToStartup) function above is to
add your function to the end of any existing S::STARTUP code without wiping
out the previous code.

Acad.lsp only loads when AutoCAD starts (unless you've changed the
ACADLSPASDOC system variable to 1), so this code should execute only for the
initial drawing. I added a test for DWGTITLED so that your code only close
untitled drawings (otherwise it would also close a drawing opened by
double-clicking on a .dwg file to start AutoCAD, for example). 🙂
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>


"kevinmulvaney" wrote in message news:6051526@discussion.autodesk.com...
I am new to lisp and just need to add a little lisp that will run at
startup. It closes the first drawing without saving. I have gotten it to
work and it seems that I need to add it to the S::Startup area. I don't
really know where that is.


(Defun C:cc () (command "close" "y") (princ) )
That's the lisp i want to run it's called close1st.lsp
Thanks for any help

Kevin
Message 5 of 11
krispy
in reply to: kevinmulvaney

sorry, wrong post
Message 6 of 11
Anonymous
in reply to: kevinmulvaney

Of course, if the OP was to use acad-push-dbmod and acad-pop-dbmod
or remove the code that is causing AutoCAD to prompt for saving changes
on Drawing1.dwg there is no need to close the file since it will close all
by
itself upon opening a drawing.

"Owen Wengerd" wrote in message
news:6051611@discussion.autodesk.com...

;; Better version that only closes the untitled drawing
Message 7 of 11

Thanks to all for the help. Through a load of trial and error I found a solution that will work. I was trying to do too much, so i just added my lisp routine to the acad.lsp file so it only runs on the inital startup. I kep running into the problem of it running each time I opened a drawing. I guess I should start off a bit smaller with the lisps, and work my way up. Again thanks to everyone for the help.

Kevin
Kevin Mulvaney, CAD/Revit Manager
PKA ARCHITECTS
Portland Oregon
Message 8 of 11
Anonymous
in reply to: kevinmulvaney


If you name that file acaddoc.lsp instead of just
acad.lsp, and have it on one of your Support Paths (OPTIONS->Files Tab,
Support Paths) it will load with every drawing instead of just at startup
od acad.

 

(alternatively, in OPTIONS, there's a checkbox to
load acad.lsp with every dwg if you prefer)


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Thanks
to all for the help. Through a load of trial and error I found a solution that
will work. I was trying to do too much, so i just added my lisp routine to the
acad.lsp file so it only runs on the inital startup. I kep running into the
problem of it running each time I opened a drawing. I guess I should start off
a bit smaller with the lisps, and work my way up. Again thanks to everyone for
the help.

Kevin
Message 9 of 11

I only need it to run on initial startup. Otherwise it will close any drawing that I open.

Thank you,
Kevin
Kevin Mulvaney, CAD/Revit Manager
PKA ARCHITECTS
Portland Oregon
Message 10 of 11
scot-65
in reply to: kevinmulvaney

ACADLSPASDOC = 1
Loads ACAD.lsp every time (overtakes LISPINIT).


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 11 of 11
Anonymous
in reply to: kevinmulvaney


Ahhhh


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
only need it to run on initial startup. Otherwise it will close any drawing
that I open.

Thank you,
Kevin

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

Post to forums  

Autodesk Design & Make Report

”Boost