ScriptContext outside of the Execute() function

Apr 16, 2015 at 12:13 PM
Hi all,

This may be a stupid question but given that the ScriptContext object is only passed to the Execute() function of the script, how can I access it in another Script class member ? Is it viable to create a global (static) member of the Script class of type ScriptContext which is set as soon as Eclipse calls Execute() ?
On a related problem, I've been trying to pass the current StructureSet object to other objects in my project (in this case, to a Windows Form) but when I try to access the contents of 'StructureSet.Structures', I find myself with a 'null' pointer. Strangely enough, I can access StructureSet.Id. Is it possible StructureSet is not ENTIRELY passed, ie that the sub object Structures is left out ?

Thanks !
Apr 16, 2015 at 5:40 PM
Creating a static class member is viable, but it doesn't have to be static. It could be a non-static field or property that you set in Execute(). Something like:
public class Script
    public ScriptContext Context { get; private set; }

    public void Execute(ScriptContext context)
        Context = context;

        // Do stuff
Others methods in your class are free to use Context.

As for your other problem, I've passed StructureSet variables without a problem before. Can you verify that StructureSet.Structures is not null when you first get the ScriptContext? If it is, then perhaps the currently opened plan doesn't have structures or something else is wrong with the structure set.
Apr 17, 2015 at 9:25 AM
Ok thanks redcurry, that's more or less what I did (with the exception of the static keyword). I looked at the script examples and I see that StructureSet instances are tossed around quite liberally so clearly, my problem doesn't lie there. Is it possible that passing objects to a Windows Form is a special case by which only a "superficial" copy of the object is passed ? By superficial copy, I mean for example that the contents of a container within an instance of an object is not passed ?