Jump to content
  • Using IronPython to call a script in Spotfire®


    Introduction

    Often it is useful to be able to call one IronPython script from another. For example, you may define some useful utility scripts that are used in multiple places in other scripts. 

    Code Sample

    The script below uses the ScriptManager to look up a script by name. The parameters are then defined and the script is executed.

    # Copyright © 2017. TIBCO Software Inc.
    # Licensed under TIBCO BSD-style license.
    # Author: Andrew Berridge
    
    #Example on how to call a script
    
    from System.Collections.Generic import Dictionary
    from Spotfire.Dxp.Application.Scripting import ScriptDefinition
    import clr
    
    # Get a reference to the script
    # Note: this is an interesting example of how
    # to use an OUT parameter in IronPython
    # - the out parameter is the scriptDef
    # - an "empty" variable is created by using 
    # the clr (Common Language Runtime) to generate
    # a reference to a ScriptDefinition object
    
    scriptDef = clr.Reference[ScriptDefinition]()
    Document.ScriptManager.TryGetScript("Name of Script", scriptDef)
    
    # Defines the values of the parameters
    
    paramDict = {"MyParam":"Value1", 
    	"Parameter2":"Value2"} 
    
    params = Dictionary[str, object](paramDict)
    
    # At this point, scriptDef will be an instance of StrongBox[ScriptDefinition]
    # There is an ExecuteScript method that expects an instance of ScriptDefinition.
    # StrongBox is confusing, but easily sorted by
    # getting scriptDef.Value - this is the instance of ScriptDefinition that 
    # the StrongBox references
    Document.ScriptManager.ExecuteScript(scriptDef.Value, params)
     

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...