[Closed] dotnet scope
I’m having issues with scope. i have this script loading in startup scripts.
fn function_load_undefined_manager_ui obj =
(
flow = dotNetObject "flowLayoutPanel"
flow.size=dotNetObject"System.Drawing.Size" 400 300
flow.ForeColor = (dotnetclass "system.drawing.color").FromArgb 255 255 255
flow.BackColor = (dotnetclass "system.drawing.color").FromArgb 255 255 255
obj.controls.add flow
)
fn function_on_open_undefined_manager =
(
function_load_undefined_manager_ui (Global_Struct_undefined_manager.undefined_ui_form)
)
fn function_on_close_undefined_manager =
(
)
struct Struct_undefined_Manager_Tool
(
state_undefined_manager_tool=false,
undefined_ui_form=undefined,
fn function_load_undefined_manager_ui_framework =
(
if state_undefined_manager_tool == false then
(
undefined_ui_form = dotNetObject "maxCustomControls.maxForm"
undefined_ui_form.size=dotnetobject "System.Drawing.Size" 400 300
undefined_ui_form.location = dotNetObject"System.Drawing.Point" 10 10
undefined_ui_form.FormBorderStyle = undefined_ui_form.FormBorderStyle.FixedToolWindow
undefined_ui_form.ShowIcon = undefined_ui_form.ShowInTaskbar = undefined_ui_form.MaximizeBox = undefined_ui_form.MinimizeBox = off
undefined_ui_form.Text = ("Welcome " + sysinfo.username)
undefined_ui_form.AutoSize = false
maxHandlePointer=(Windows.GetMAXHWND())
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer
undefined_ui_form.show(maxHwnd)
/** -- Open & Close-- **/
dotNet.AddEventHandler undefined_ui_form "shown" function_on_open_undefined_manager
dotNet.AddEventHandler undefined_ui_form "closed" function_on_close_undefined_manager
state_undefined_manager_tool = true
)else(
undefined_ui_form.dispose()
state_undefined_manager_tool=false
)
)
)
Global_Struct_undefined_manager = Struct_undefined_Manager_Tool()
i have this in a marcro script to load above.
Global_Struct_undefined_manager.function_load_undefined_manager_ui_framework()
But i have to decalre the function (function_on_open_undefined_manager) again once max has loaded. The marcro script errors out in till i declare this function, then it works fine. I don't know why.
it’s because the system loads macroscripts before startup scripts. so at the moment of macro’s loading your global functions and structures from startup script are undefined.
i would put the “main” structure in stdscripts which are loading by the system before macros, but if you don’t want to change scripts places as a solution could be to use globalvars structure:
if globalvars.isglobal #Global_Struct_undefined_manager do
(
s = globavars.get #Global_Struct_undefined_manager
s.function_load_undefined_manager_ui_framework()
)
(code is not tested)
Its already been a month! times goes too quick. Thank Dennis! sorry its taken so long to get back to this. Finally have time to look in to this again.
So after testing this once again, Ive found its not the scope issue i first thought.
I’m having issues with the filein.
To make this work and print something that isn’t undefined, i need to run this function twice for it to work successfully.
fn function_test =
(
filein (@"C: est.ms")
print filein_test
)
function_test()
but if i run this
filein = @"C:\Program Files est1.ms"
fn function_test =
(
filein (@"C: est.ms")
print filein_test
)
function_test()
it works straight away. I don’t understand why.
Apologies if this seems trivial. But the way Ive written my script, its loaded on start-up and I’m having to run it again once max is open. Which defeats the point… its very annoying…