Importing external modules

The search path for importing py modules can be extended in the script itself, for example:


Example:

#Import external module


import sys
sys.path.append(r'D:\MyPythonModule')

from mymodule import hello


Importing and using ScriptoMate Types

Example:

#ScriptoMate types

#VSApi is loaded and referenced by default, but still all required types need to be imported

#from VSApi import *
from VSApi import VSVariable, VSVariableDataType, VSVariableDefinitionType, VSSeverity


#Other types

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox,Form,MessageBoxButtons,DialogResult

Accessing Host objects 

Please refer to the Scripting Host Object Model

Most common uses

#Set property
Host.ScriptData.Variable["myDouble"].Value += 1.0

#Get property
myMsg = Host.ScriptData.Variable["myWelcomeMessage"].Value


#Call a sub routine

Host.ScriptData.Variables.Remove("test")


#Call a function

err = Host.IsRunTimeError()


#Create object

varName = "test"
var = VSVariable(varName, VSVariableDataType.String, varName + " (set by IronPython script)", varName + " (set by IronPython script)", False, VSVariableDefinitionType.VSDynamic)
Host.ScriptData.Variable[varName] = var


#Datatable.RepeatScript

#DR_TRX is the Datarow set by the repeater

dr = Host.ScriptData.Variable["DR_TRX"].Value
amount = dr["AMT_OR_QTY"]
dr["AMT_OR_QTY"] = amount  * 100


Misc.RunScript examples

Host Object

Example file

Host.ScriptData.Variables

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Python.Variables.xml

Host.ScriptData.MailServers

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Python.MailServers.xml

Host.ScriptData.FtpServers

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Python.FtpServers.xml

Host.Progress

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Python.Progress.xml

Host.DatasetManager

Planned

Host.AppManager

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Python.Application.xml

Datatable.RepeatScript examples

Host Object

Example file

Host.ScriptData.Variables

Xml\Tutorial\5001 Advanced topics\0401 Creating scripts\Datatable.RepeatScript.IronPython.xml