Hello Guest it is May 10, 2021, 09:01:24 PM

Author Topic: Can mcScriptExecute be called from a macro?  (Read 785 times)

0 Members and 1 Guest are viewing this topic.

Can mcScriptExecute be called from a macro?
« 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

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: Can mcScriptExecute be called from a macro?
« Reply #1 on: February 10, 2018, 04:57:49 PM »
Everything should work but I would use mcScriptExecutePrivate to be safe.

Place an mcs file in a directory

Code: [Select]
-- test.mcs
wx.wxMessageBox("Hello")

Code: [Select]
-- Macro
function m111()

local mInst = mc.mcGetInstance()
mc.mcScriptExecutePrivate(mInst, "test.mcs", false);
end

if (mc.mcInEditor() == 1) then
 m111()
end


DazTheGas
« Last Edit: February 10, 2018, 05:01:37 PM by DazTheGas »
Theres always time for a choccy biccy
Re: Can mcScriptExecute be called from a macro?
« Reply #2 on: February 10, 2018, 05:42:19 PM »
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

Code: [Select]
---------------------------------
--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

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: Can mcScriptExecute be called from a macro?
« Reply #3 on: February 10, 2018, 06:08:12 PM »
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
Theres always time for a choccy biccy