Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - <nop>CoCreate Modeling: Changing the current directory during startup (02 Nov 2015) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="02"></a> ---+++ [[DefinePrivatePublic20151102ChangeDirectoryDuringStartup][<nop>CoCreate Modeling: Changing the current directory during startup]] (02 Nov 2015) <summary> Way back in 2003, I posted an article called <a href="http://www.clausbrod.de/CoCreateModeling/MacroAlarmClock">CoCreate Modeling alarm clock: Beep whenever a long-running command terminates</a>. Besides reminding me of my age (sigh), the article served a useful purpose this week, as it illustrates a technique required to solve a problem which came up in a <a href="http://forum.cad.de/foren/ubb/Forum92/HTML/000789.shtml">forum discussion</a> the other day. </summary> In the article, I showed how to subscribe to events in <nop>CoCreate Modeling (aka [[https://de.wikipedia.org/wiki/Creo_Elements/Direct_Modeling]["PTC Creo Elements/Direct Modeling"]]) for fun and profit. It turns out that this technique can also be applied to solve the following problem: In customization code which is loaded into <nop>CoCreate Modeling during startup, you want to set the user's default working directory to some default value specific to your environment or team. You'd think that this should be trivial, as the current directory can be set using the IKIT's =sd-set-current-working-directory= API. But when you call this function during startup (i.e. from code in =sd_customize=, or in code loaded from there), you may find that other customization code or even <nop>CoCreate Modeling itself changes the current directory after your code runs. This is because <nop>CoCreate Modeling remembers the directory which was current before the user closed the last session. When you restart the application, it will try to "wake up" in precisely that working directory. To override this behavior, here's a simple trick: * In =sd_customize= (or, preferably, in code loaded from there), register an event handler for the =SD-INTERACTIVE-EVENT=. * This event will be fired when startup has completed and the application becomes interactive. * In the event handler: * Set the current working directory as you see fit * Unregister from the event (we want one-shot behavior here) And here is what event handler code like this would look like: <style type="text/css"> <!-- pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #FFEECC; } body { font-family: monospace; color: #000000; background-color: #ffffff; } * { font-size: 1em; } .Constant { color: #ff00ff; } .Statement { color: #804040; font-weight: bold; } .Type { color: #2e8b57; font-weight: bold; } .Special { color: #6a5acd; } .Identifier { color: #008080; } --> </style> <pre> <span class="Special">(</span><span class="Statement">in-package</span> :de.clausbrod<span class="Special">)</span> <span class="Special">(</span><span class="Statement">use-package</span> :oli<span class="Special">)</span> <span class="Special">(</span><span class="Statement">defun</span> interactive-event-handler<span class="Special">(</span><span class="Type">&rest</span> r<span class="Special">)</span> <span class="Special">(</span>sd-set-current-working-directory <span class="Special">(</span>user-homedir-pathname<span class="Special">))</span> <span class="Special">(</span>sd-unsubscribe-event <span class="Type">*SD-INTERACTIVE-EVENT*</span> <span class="Special">'</span><span class="Identifier">interactive-event-handler</span><span class="Special">))</span> <span class="Special">(</span>sd-subscribe-event <span class="Type">*SD-INTERACTIVE-EVENT*</span> <span class="Special">'</span><span class="Identifier">interactive-event-handler</span><span class="Special">)</span> </pre> This particular event handler sets the current working directory to the user's home directory, but this is of course just an example for a reasonable default. --- %STOPINCLUDE% %COMMENT{type="below" nonotify="on"}% ---
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.6 |
>
|
r1.5
|
>
|
r1.4
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20151102ChangeDirectoryDuringStartup
r1.6 - 09 Nov 2015 - 21:51 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback