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

0 Members and 1 Guest are viewing this topic.

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 »