Way back in 2003, I posted an article called CoCreate Modeling alarm clock: Beep whenever a long-running command terminates. 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 forum discussion
the other day.
In the article, I showed how to subscribe to events in CoCreate Modeling (aka "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 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
But when you call this function during startup (i.e. from
, or in code loaded from there), you may find that other customization code or even CoCreate Modeling itself
changes the current directory after your code runs. This is because 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:
sd_customize (or, preferably, in code loaded from there), register an event handler for the
- 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:
(defun interactive-event-handler(&rest r)
(sd-unsubscribe-event *SD-INTERACTIVE-EVENT* 'interactive-event-handler))
(sd-subscribe-event *SD-INTERACTIVE-EVENT* 'interactive-event-handler)
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.