Jump to content

Mod Tool/Scripting: Difference between revisions

Suppress custom events in batch processing
(finally getting a simple value displayed in the viewport via ICE)
(Suppress custom events in batch processing)
Line 128: Line 128:


[...]
[...]
===Suppress events in batch processing===
Events that get triggered by code inside functions don't delay the function for processing the event.
The events are precessed after the function finished.
This can pose a serious problem with batch processing where you might create and select each object several times.
====Negative-example====
function XSILoadPlugin( in_reg )
in_reg.Author = ""
in_reg.Name = "Sel Plug-in"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterEvent "Selection",siOnSelectionChange
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 Selection_OnEvent( in_ctxt )
' get select event, ignore unselect events (0)
if cstr(in_ctxt.GetAttribute("ChangeType")) = 1 then
exit function
end if
if XSIUtils.Environment("IgnoreMe") = "true" then
exit function
else
logmessage "hi !"
end if
Selection_OnEvent = true
end function
Code to be called from somewhere else.
XSIUtils.Environment.Setitem "IgnoreMe", "true"
SelectObj "cylinder", , True
XSIUtils.Environment.Setitem "IgnoreMe", "false"
The selection event outputs "hi !" despite "IgnoreMe" is set to "true" at the beginning.
That's because the event becomes processed after the function finished after "IgnoreMe" was set to "false".
====Positive-example====
function XSILoadPlugin( in_reg )
in_reg.Author = ""
in_reg.Name = "Sel2 Plug-in"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterEvent "Selection2",siOnSelectionChange
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 Selection2_OnEvent( in_ctxt )
if cstr(in_ctxt.GetAttribute("ChangeType")) = 1 then
exit function
end if
IgnoreCount = GetGlobal ("IgnoreThis")
if IgnoreCount > 0 then
SetGlobal "IgnoreThis", (IgnoreCount - 1)
else
logmessage "Hi 2 !"
end if
Selection2_OnEvent = true
end function
Code to be called from somewhere else.
Be aware of what can trigger the unwanted event and use a '''''global ignore variable'''''.
for i=1 to 5
SetGlobal "IgnoreThis", GetGlobal ("IgnoreThis") + 1
SelectObj "cylinder", , True
next
' Don't use that variable where you want to trigger the event intentionally.
SelectObj "cylinder", , True


===Directories===
===Directories===
Line 371: Line 460:
  logmessage "onisplit finished."
  logmessage "onisplit finished."
  ' now you can work with the extracted xml file
  ' now you can work with the extracted xml file


==Read file==
==Read file==
8,323

edits