Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: rhtuttle on February 10, 2018, 04:34:50 PM
-
Can mcScriptExecute be called from a macro?
I have deleted some file and path checking to verify that the full path and filename are correct and found. The 'TestScript.mcs' simply contains a mc.mcCntlSetLastError message. When run in the editor you can step through the code, it hangs for a few seconds on the script execute then moves to the next line. After completing the debug the editor declares itself closing due to an error.
function m9001()
mc.mcScriptExecute(0,'c:\\mach4Hobby\\profiles\\MyTurn4\\macros\\'..'TestScript.mcs',false)
end
if mc.mcInEditor()==1 then
m9001()
end
Is using mcScriptExecute in a macro not allowed?
TIA
RT
-
Everything should work but I would use mcScriptExecutePrivate to be safe.
Place an mcs file in a directory
-- test.mcs
wx.wxMessageBox("Hello")
-- Macro
function m111()
local mInst = mc.mcGetInstance()
mc.mcScriptExecutePrivate(mInst, "test.mcs", false);
end
if (mc.mcInEditor() == 1) then
m111()
end
DazTheGas
-
Thanks DAZ ;D
Could you point me to, or expound on, the difference between mcScriptExecute and mcScriptExecutePrivate?
It does work but I'm not sure if it will work when I start doing things I shouldn't
---------------------------------
--Macro to execute a script from call to m9001 with script name commented:
--N0100 m9001 (TestScript.mcs)
---------------------------------
function m9001()
local inst=mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
local pn=path.."\\Profiles\\"..profile..'\\macros\\'
local ln=mc.mcCntlGetGcodeLineNbr(0)
local s=tostring(mc.mcCntlGetGcodeLine(0,ln))
local n=string.find(s,'(',1,true)
s=string.sub(s,n+1)
n=string.find(s,')',1,true)
s=string.sub(s,1,n-1)
local fn=wx.wxFileName.FileExists(pn..s)
if fn==true then
mc.mcScriptExecutePrivate(0,pn..s,false)
end
return
end
if mc.mcInEditor()==1 then
m9001()
end
It would be nice if it did, I hate having to keep updating the list of what each m... does. Just naming the script for what it does and calling it with the same macro with the name commented would suit my way of thinking, which is always a bit twisted ::)
RT
-
mcScriptExecute just basically executes a script and is global - it can change things globally and have its variables changed etc, using the private version just like it says makes it private and more protected, remember we all have our own prefs how we use things and i like my privacy lol
DazTheGas