Mod Tool: Difference between revisions

2,068 bytes added ,  17 October 2012
m
scripting: turning a function with arguments into a command
mNo edit summary
m (scripting: turning a function with arguments into a command)
Line 58: Line 58:
** The user can install a newer version of the addon by repeating the installation with the new file: it's unnecessary to remove the old version.
** The user can install a newer version of the addon by repeating the installation with the new file: it's unnecessary to remove the old version.
* File > Add-On > Package... doesn't work with ModTool "Add-Ons cannot be created with Softimage Demo Version."
* File > Add-On > Package... doesn't work with ModTool "Add-Ons cannot be created with Softimage Demo Version."
* '''Putting scripts simply into folders doesn't work, they must be "plugins", the file extension can be the same e.g. "vbs"'''.
* Images and any other files can be put into any folder of the add-on.
** A script can run on another computer if its content is found under a command, and plugin register that new command(s).
** Let's say you have an addon called "my_stuff", a subfolder "images" and an image called "test.png". The image can be accessed via:
** E.g. use those commands in your toolbar's script buttons.
:: '''''XSIUtils.ResolvePath("$XSI_USERHOME/") & "Addons\'''my_stuff\images\test.png"''
* Images and any other files can be put into any folder of the add-on, get them with '''''XSIUtils.ResolvePath("$XSI_USERHOME/") & "Addons\'''Addon_name\other_subfolder\img.png"''
* The problem with embedded code: commands like ''CreatePrim'' can call an property page (PPG).
* The problem with embedded code: commands like ''CreatePrim'' can call an property page (PPG).
** Those popups can be disabled. Search for "disabling PPG popups" on this page.
** Those popups can be disabled. Search for "disabling PPG popups" on this page.
* '''Putting scripts simply into folders doesn't work, they must be "plugins", the file extension can be the same e.g. "vbs"'''.
** A script function can run on another computer if it is found as command, and plugin register new commands.
** E.g. you can use those commands in your toolbar's script buttons.
* Example of turning a function into a command:
'''function with arguments as it is'''
' this function can only be used inside the script where it was defined
function simple_math (a, b, mode)
if mode = "+" then
  simple_math = a + b
elseif mode = "-" then
simple_math = a - b
elseif mode = "/" then
simple_math = a / b
elseif mode = "x" then
simple_math = a * b
else
logmessage "This opperator is not allowed. Use one of those:" & vbCrlf & "+ - / x"
end if
end function
' example of usage
result = simple_math(5, 3, "+")
logmessage result
''' the same function as command'''
' the command simple_math can now be used in any script
function XSILoadPlugin( in_reg )
in_reg.Author = "your_name"
in_reg.Name = "simple_mathPlugin"
in_reg.Email = ""
in_reg.URL = ""
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterCommand "simple_math","simple_math"
'RegistrationInsertionPoint - do not remove this line
XSILoadPlugin = true
end function
function XSIUnloadPlugin( in_reg )
dim strPluginName
strPluginName = in_reg.Name
Application.LogMessage strPluginName & " has been unloaded.",siVerbose
XSIUnloadPlugin = true
end function
function simple_math_Init( in_ctxt )
dim oCmd
set oCmd = in_ctxt.Source
oCmd.Description = ""
oCmd.ReturnValue = true
dim oArgs
set oArgs = oCmd.Arguments
oArgs.Add "a",siArgumentInput,"0"
oArgs.Add "b",siArgumentInput,"0"
oArgs.Add "mode",siArgumentInput,"0"
simple_math_Init = true
end function
function simple_math_Execute( a, b, mode )
' convert to double
a = cdbl(a)
b = cdbl(b)
if mode = "+" then
simple_math_Execute = a + b
elseif mode = "-" then
simple_math_Execute = a - b
elseif mode = "/" then
simple_math_Execute = a / b
elseif mode = "x" then
simple_math_Execute = a * b
else
logmessage "This opperator is not allowed. Use one of those:" & vbCrlf & "+ - / x"
end if
end function




8,452

edits