Author Topic: Proper use of S::STARTUP  (Read 11265 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Proper use of S::STARTUP
« on: December 02, 2009, 08:17:20 PM »
Was just a bit perplexed over the correct use of this function, I've seen it used in many different ways, in the VLIDE help files and also on the forums - especially in the loading of dll's and VBA.

But I wondered if some of you experts here could properly explain to me how exactly it should be used, and for what purpose?

This question stems from a question posed over at CADTutor, and it got me thinking (and doubting)...

Many thanks in advance for your time,

Lee

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Proper use of S::STARTUP
« Reply #1 on: December 02, 2009, 08:39:48 PM »
S::STARTUP is probably a legacy throwback to pre-A2k. Although I still use it for loading some applications at startup and setting variables required for our working environment, there really isn't much else it is needed for. Of course the opinions will vary widely.

Lets just think about it for a minute ... S::STARTUP is executed whenever the first drawing is opened, unless you load it in each drawing. It then executes whatever functions you have programmed it to do.

So what might you want to do? Well, you might want to set things like limits, create layers, load linetypes, set variables etc ...
Ok, cool ... except most of that can be done within your template ...

Well, there is the possibility of having it autoload other lisp, vba and arx files ... except that can be done very easily in the startup suite (except, don't forget the startup suite is different for each profile)

Ok, maybe you want to autoexecute some of your lisps at startup ... ok, but that can be done within the lisp file itself ... i.e. (C:MYLISP)

Well .. then really there isn't anything that S::STARTUP can do for you that you cannot do in other ways ... however, I find it is still much simpler to utilize, especially considering the workspaces, profiles, templates etc. that can be changed and used by the person behind the keyboard. By using S::STARTUP you will be reasonably sure that no matter what profile is being used, no matter what menu, workspace or template is loaded, this function will be executed at least the first time a drawing is opened.

At one of my previous jobs, we used it exclusively to track drawing usage utilizing acadlspasdoc and acad.lsp to load it into each drawing.

So the "proper" use could be debated and you will likely find many people who use it as who don't ... kinda like in vba

sub startup()
'do stuff
end sub

it runs when loaded, but many people don't use it.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Proper use of S::STARTUP
« Reply #2 on: December 02, 2009, 08:59:06 PM »
Mark, you make me LoL.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #3 on: December 02, 2009, 09:11:36 PM »
So the way I understand it, suppose (as in the current case on cadtutor) we want to use the NETLOAD command.
The options are:
  • We can either create a lisp with the command in it and add it to the startup suite
  • Or add it to S::STARTUP in say acaddoc.lsp
  • We can't directly add the command to ACADDOC because it loads before the drawing loads.
And adding it to the startup suite means it will only be there for that person. So if you were on a network the best (only) method is with S:STARTUP... :?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #4 on: December 02, 2009, 09:21:47 PM »

For a .NET dll I'd consider 2 options

Partial menu  .MNL file

Demand loading settings in the registry. (preferred)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #5 on: December 02, 2009, 09:36:39 PM »
For a .NET dll I'd consider 2 options
Partial menu  .MNL file
Demand loading settings in the registry. (preferred)
Thanks. I'd have to read up on implementation with an .mnl file. And registry, well I've always been scared to touch the registry (Microsoft warnings have got to me  :police:), and besides, it always seems like it'd be a big effort if you want to remove it again (compared to just removing it from the startup suite)?

So why would you recommend the registry way?
« Last Edit: December 02, 2009, 09:53:03 PM by steve.k »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #6 on: December 02, 2009, 10:04:49 PM »
This works for me ..... a simple autoload defined in the partial menu MNL
only loads the .NET dll when needed, so startup time in minimised ( similar to demand loading)
Code: [Select]
(defun c:CMD1 ()
  ;;// Codehimbelonga kwb@theSwamp 20070509
  ;;(findfile  "F:\\_VS2008Projects\\Projects\\ACAD-Managed\\CsMgdAcad-ColorLab\\bin\\Release\\CsMgdAcad-ColorLab.dll")

  (command
    "_NETLOAD"
    "F:\\_VS2008Projects\\Projects\\ACAD-Managed\\CsMgdAcad-ColorLab\\bin\\Release\\CsMgdAcad-ColorLab.dll"
  )
  (command "CMD1")
)

Command: cmd1

Concept Code For AC2008, MSVS2005 :: kwb@theSwamp 20070509 ->> ...
<dll netloads and program runs first instance>

Command: CMD1
<program runs subsequent instances>


Regards
Kerry
« Last Edit: December 02, 2009, 10:15:10 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #7 on: December 02, 2009, 10:41:22 PM »
Just to correct myself I just added (command "_CIRCLE" "0,0" "10") into my acaddoc.lsp file and ran autocad and it drew it. So a reason for S::STARTUP is not to run commands. Then what is the difference, I might as well add commands straight to acaddoc.lsp?   :|

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #8 on: December 02, 2009, 10:49:16 PM »
And Kerry (B) I'm lost with regards the partial menu MNL. First time I've really heard about it and autocad help file seems to talk about something else (about menu's  :-)), is there a tut around for what you are suggesting?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #9 on: December 02, 2009, 10:52:22 PM »
From Help
Quote
Also, if you use the command function in an acad.lsp or .mnl file, it should be called only from within a defun statement. Use the S::STARTUP function to define commands that need to be issued immediately when you begin a drawing session.

Quote
You can define an S::STARTUP function to perform any needed setup operations after the drawing is initialized.

The startup LISP files (acad.lsp, acaddoc.lsp, and MNL) are all loaded into memory before the drawing is completely initialized. Typically, this does not pose a problem, unless you want to use the command function, which is not guaranteed to work until after a drawing is initialized.

If the user-defined function S::STARTUP is included in an acad.lsp, acaddoc.lsp, or MNL file, it is called when you enter a new drawing or open an existing drawing. Thus, you can include a definition of S::STARTUP in the LISP startup file to perform any setup operations.




kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

cadabyss

  • Guest
Re: Proper use of S::STARTUP
« Reply #10 on: December 02, 2009, 10:53:05 PM »
One benefit of using a s::startup function vs. acad.lsp or acaddoc.lsp is that s::startup runs after the drawing is loaded.  So s::startup could be used to setup the drawing to company standards for example.  

A second benefit, is it provides one standard function which different third party developers can plug-into to initialize their routines.   Say you have a third party app called "QuickDraw" for example, and another third party app called "SymbolLib", they each could append to the s::startup function to load their initializing code.  Note that to append to any function during runtime, the function needs to be created with defun-q and not defun.



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #11 on: December 02, 2009, 10:56:13 PM »
And Kerry (B) I'm lost with regards the partial menu MNL. First time I've really heard about it and autocad help file seems to talk about something else (about menu's  :-)), is there a tut around for what you are suggesting?

A partial menu is simply a secondary menu ... nothing special ... I use them so that I don't need to edit the ACAD.MNL.

The function I posted could be defined in ANY file that autoCAD loads into menory at startup/initialisation.

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%202010%20User%20Documentation/index.html?url=WS73099cc142f4875513fb5cd10c4aa30d6b-7f62.htm,topicNumber=d0e399760
« Last Edit: December 02, 2009, 10:59:25 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #12 on: December 02, 2009, 11:05:58 PM »
A partial menu is simply a secondary menu ... nothing special ... I use them so that I don't need to edit the ACAD.MNL.
The function I posted could be defined in ANY file that autoCAD loads into menory at startup/initialisation.
Aside: Ah!  8-) I was thinkin it had some special feature for starting up dll's!  :roll:


Re: S::STARTUP. That's shedding more light on it, thanks Steve, Kerry, Keith.
I can get away with drawing circles before the drawing has fully loaded, but say for big lisps with dialog boxes it would be better (likely essential) to have the drawing already loaded before proceeding with a program.
« Last Edit: December 02, 2009, 11:20:07 PM by steve.k »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #13 on: December 02, 2009, 11:58:19 PM »

I don't understand the circle reference and 'getting away' with stuff.

Your stated objective was to netload a dll. Have you tried the 'autoload/selfdefining' method I posted ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #14 on: December 03, 2009, 12:38:01 AM »
Your code works. Sorry I didn't say that very well, I was just saying it as a statement to try sum it all up. I.E. As I understand it if someone wanted to do something simple (eg draw circles) at startup they could just plug it straight into acaddoc, but for big lisps the S::STARTUP method is preferred and sometimes necessary as the drawing will be already loaded. (basically just repeating what Steve Doman said)
« Last Edit: December 03, 2009, 12:42:05 AM by steve.k »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #15 on: December 03, 2009, 12:55:18 AM »
< .... > but for big lisps the S::STARTUP method is preferred and sometimes necessary as the drawing will be already loaded.

No, that is not correct.
By loading routines (at startup) before they are needed (irregardless of IF they will be needed) is a waste of time and resources.

Have a look at the AutoLoad function in the AutoLISP reference guide for your lispy stuff.


And attempt to understand the logic behind the function I posted.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Proper use of S::STARTUP
« Reply #16 on: December 03, 2009, 05:27:00 AM »
Many thanks guys for all the replies - I have learnt a ton from this thread - especially from your detailed explanation Keith, thanks for your time.

So, to be clear, my understanding is that S::STARTUP can be used to execute functions that operate directly on the drawing in question (as S::STARTUP) is loaded after the ACADDOC.lsp file.

I do have one further question:

I have seen two ways to implement the S::STARTUP function:

Code: [Select]
(defun-q test ( )
  (command "_.CIRCLE" '(0 0 0) 10.0)
  (princ))

(setq S::STARTUP (append S::STARTUP test))

Code: [Select]
(defun S::STARTUP ( )
  (command "_.CIRCLE" '(0 0 0) 10.0)
  (princ))

Now, I always thought that the best way to implement this, is the first method shown, but a few examples in the VLIDE are showing the second - and I have also seen a few examples on here with the second.

So which is correct - or does it vary if the S::STARTUP has not been utilised?

Thanks once again guys, you've been a great help.

Lee


PS>  Now I've posted my Lee7 post rank is gone  :-(

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Proper use of S::STARTUP
« Reply #17 on: December 03, 2009, 05:47:37 AM »
< .. >

So which is correct - or does it vary if the S::STARTUP has not been utilised?

Thanks once again guys, you've been a great help.

Lee


Lee , See the link in post reply#11
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Proper use of S::STARTUP
« Reply #18 on: December 03, 2009, 06:40:47 AM »
Hi,

I think there's some confusion with the defun vs defun-q using.

defun-q defines a function as a list defun creates a (U)SUBR type object.

You can, but you don't need to define 'test' with defun-q, but you have to do it for the S::STARTUP function to be able to use append.

The interest is that you can have many acaddoc.lsp or *.mnl files.
Only one acaddoc file should be openened on opening a drawing: the first AutoCAD find, and the first path AutoCAD looks for an acaddoc.lsp file is the drawing directory, so it can be useful to link an acaddoc.lsp file to one or more drawings using this behavior.
On the other hand you can have as many *.mnl files as partial CUI files more the main CUI and according the profile they can be loaded or not.

So it can be usefull to define more than one S::STARTUP function in some acaddoc.lsp and*.mnl file.
This is possible using the defun-q function to define the S::STARTUP function this way in a file:

Code: [Select]
(defun circle1 ()
  (command "_.circle" '(0. 0. 0.) 10.)
  (princ)
)

(if S::STARTUP
  (setq S::STARTUP (append S::STARTUP '((circle1))))
  (defun-q S::STARTUP () (circle1))
)

and this way in another file

Code: [Select]
(defun circle2 ()
  (command "_.circle" '(0. 0. 0.) 12.)
  (princ)
)

(if S::STARTUP
  (setq S::STARTUP (append S::STARTUP '((circle2))))
  (defun-q S::STARTUP () (circle2))
)

If any or both files are loaded, one or two circles will be drawn whatever the order the files were loaded.

Hope it's clear enough...
Speaking English as a French Frog

cadabyss

  • Guest
Re: Proper use of S::STARTUP
« Reply #19 on: December 03, 2009, 07:49:04 AM »
Part of the confusion of the use of s::startup is that in the old days, we had only one menu, the Acad menu. So you couldn't load a separte partial menu as you can today.  Another confusing issue is that when we defun a function today, they are not created as a list type.  Thus we cannot use list handling techniques to manipulate a function after it's be defun'd unless you use initially created it using defun-q.

If you want to use s::startup, proper etiquette to avoid overwriting a third party s::starup code, is to check if s::startup exist.  If it does exist, then append to it, otherwise defun-q a new s::startup.

Having said all that, I think the MNL method is popular way to load your code now a days.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Proper use of S::STARTUP
« Reply #20 on: December 03, 2009, 08:35:52 AM »
I too have seen the (command) function execute without error, when simply dropped into "acaddoc.lsp", but I think the key here is that it "may not".

Quote from: AutoCAD HELP
...unless you want to use the command function, which is not guaranteed to work until after a drawing is initialized.

Taken from this page: http://tinyurl.com/yf6h7jr

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Proper use of S::STARTUP
« Reply #21 on: December 03, 2009, 10:26:48 AM »
< .. >

So which is correct - or does it vary if the S::STARTUP has not been utilised?

Thanks once again guys, you've been a great help.

Lee


Lee , See the link in post reply#11

Thanks Kerry - I should've looked at that before posting - it explains things.


Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Proper use of S::STARTUP
« Reply #22 on: December 03, 2009, 10:29:47 AM »

Code: [Select]
(defun circle1 ()
  (command "_.circle" '(0. 0. 0.) 10.)
  (princ)
)

(if S::STARTUP
  (setq S::STARTUP (append S::STARTUP '((circle1))))
  (defun-q S::STARTUP () (circle1))
)

and this way in another file

Code: [Select]
(defun circle2 ()
  (command "_.circle" '(0. 0. 0.) 12.)
  (princ)
)

(if S::STARTUP
  (setq S::STARTUP (append S::STARTUP '((circle2))))
  (defun-q S::STARTUP () (circle2))
)


Gile,

With your above examples, are you saying that although you are appending the functions "circle1" and "circle2" to the S::STARTUP function, they do not need to be defined using defun-q, and that it is only S::STARTUP (should it not exist) that needs to be defined using defun-q?

So, after reading the documentation - am I right in saying that S::STARTUP should never be defined with "defun", but rather appended to, (if it exists) or else defined using "defun-q"?

Its almost sinking in...

Lee

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Proper use of S::STARTUP
« Reply #23 on: December 03, 2009, 11:25:25 AM »
Any code that needs to be appended should be defined with (defun-q), otherwise, it *can't* be appended.

You should get this error if you try.

Code: [Select]
; error: Invalid attempt to access a compiled function definition.  You may
want to define it using defun-q:

SteveK

  • Guest
Re: Proper use of S::STARTUP
« Reply #24 on: December 03, 2009, 04:14:13 PM »
Sweet  :-D I (finally) understand! For my part, thanks guys for all your posts...one more concept in the bag   :-)

ps. & thanks for telling me about autoload Kerry.
« Last Edit: December 03, 2009, 04:22:38 PM by steve.k »