Hello Guest it is March 29, 2024, 06:42:14 AM

Author Topic: Named Scripts and # expand Examples for mach 3.43.6+  (Read 3046 times)

0 Members and 1 Guest are viewing this topic.

Named Scripts and # expand Examples for mach 3.43.6+
« on: July 19, 2010, 01:59:17 AM »
Hi,
I'd actually written this and posted in the VB forum on July 4th.
I decided to bring a copy of it over here as the people playing with MSM are likely to be interested in this info.

===========

This topic came up in another thread and I thought I'd start a new thread to draw people's attention to new abilities added to the basic APIs with mach 3.43.6.

Named macros are supported on v3 as of 3.43.6 - I'm making a lot of use of them for the new screen set.
You no longer have to put scripts in M codes. A script can be a disk file and it can be called from another script via the use of the RunScript API.

A significant number of new APIs were added to 3.43.6 many of which utilize or support the use of named scripts.
To quickly find the new APIs, get the latest v3 programmer's manual and search for "3.43" - that will find all the new ones (New calls are marked in the manual to tell what level of mach first implemented the API).

Here is a summary of new calls that are available as of mach 3.43.6:

Finding key files
    GetActiveProfileDir
    GetActiveProfileName

    GetActiveScreenSetName

    GetLoadedGCodeDir
    GetLoadedGCodeFileName

Named script execution
    RunScript

Windows interface
    GetMyWindowsHandle

Macro Pumps
    StartPeriodicScript
    StopPeriodicScript
    IsPeriodicScriptRunning

Mach configuration info
    GetSetupUnits
    IncludeTLOinZFromG31
    ProgramSafetyLockout

Touch Screen data entry
    NumberPad

People will also want to look at the section of the manual that describes pre-processing and #expand
A typical use of this is to keep source code in on place ( in a disk file) and include it in multiple scripts.
Fix a bug in the master file and it is now fixed in all scripts that include the file.

For the MachStdMill implementation, essentially no script code lives inside the .set file - instead all buttons simply use #expand to reference an external named script disk file.

Just so folks can see what can be done with the new facilities, here is the content of the MSM history button:
    #expand <Scripts\All-History>

And this is the contents of All-History.m1s:

Option Explicit
'********DO NOT remove or change the expand line or the included file contents******************
'  MachStdMIll license terms REQUIRE that the copyright and License terms remain a part of this source file
#expand <Headers\CopyRightAndLicenseNotice>   
'**************************************************************************************

' code to open mach error history file
'
' we use the non-GCode editor for the history file.
' this leaves the user specified editor available for G-code editing
' we do this becuase many gcode editors reject plain text as invalid gcode syntax
'
#expand <Headers\MSMConstants>
#expand <Headers\MSMConfigFunctionNumbers>

Dim CmdString As String
Const FileName = "C:\Mach3\LastErrors.txt"

' set the menu bar state to the stored user preference
Call MSMRunScript("MSMCOnfig", MSMGetNGCEditorInfo)

' config info reloaded from file, FQFN in UserLabel
CmdString = """" & GetUserLabel(MSMNonGCodeEditorUserLabel) & """" & " " & """" & FileName & """"
'MsgBox "CS = " & cmdstring
Shell(CmdString) 
Exit sub   ' return from button Call

#Expand <Scripts\Common\MSMRunScript>
------------

MSMRunScript is a wrapper I use for RunScript that adds simple parameter passing on top of run script. Here is it's contents:

'********DO NOT remove or change the expand line or the included file contents******************
'  MachStdMIll license terms REQUIRE that the copyright and License terms remain a part of this source file
#expand <Headers\CopyRightAndLicenseNotice>   
'**************************************************************************************

Sub MSMRunScript(ByVal MSMScriptName As String, ByVal P1 As Double)
   
   ' This is a wrapper that will allow one to replace the functionality of "Call M*********x Px".
   ' In fact this it is a bit more capable as the param is implemented as an Global MSM userspace DRO,
   ' so the script could actually put a value back in the param DRO if needed.
   ' This could also be expanded to more params, but MSM only was used one param to M********* macros.
   ' param type choices  where double DRO or LEDs - used DROs as the more flexible approach,
   ' LED parameters will be encoded within MSM as 0/1 value in the DRO.
   '
   
   Dim QFN As String
   
   SetUserDRO(MSMRunScriptParam1, P1)   ' stash the param value in the allocated Global DRO
   QFN = "ScreenSetMacros\" & GetActiveScreenSetName() & "\Scripts\Common\" & MSMScriptName
   
   'MsgBox "Script to run: " & Chr(13) & "    " & QFN & Chr(13) & "Param value = " & P1
   
   RunScript(QFN)   
   
End Sub

And to keep things legal, here is the copyright/license header file included in every MSM script file:
' This Source file is part of the MachStdMill screen set package for Mach3
'
' Copyright © 2010 Calypso Ventures, Inc. All Rights Reserved.
' The author of the MachStdMill screen Set is Calypso Ventures, Inc.
'
' Redistribution And use In source And binary forms, With Or without modification, are permitted
' provided that the following conditions are met:'
'
' 1. Redistributions of the Screen Set And supporting Macro source code must retain the above copyright
' notice, this list of conditions And the following disclaimer.
'
' 2. Redistributions In binary form must reproduce the above copyright notice, this list of conditions And the
' following disclaimer In the documentation And/Or other materials provided With the distribution.
'
' 3. The Name of the author may Not be used To endorse Or promote products derived from this software
' without specific prior written permission.
'
' THIS SOFTWARE IS PROVIDED BY CALYPSO VENTURES, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
' PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
' INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
' NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
' BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
' STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'
'

Finally, the script editor in 3.43.6 was enhanced to support #expand etc - the E+ and E- buttons will expand / unexpand the #expand lines while you are in the editor.

And last, (but NOT least!) the editor also now has find and replace.

Anyhow, you can see that scripts can now get to looking rather different than prior to 3.43.6 <grin>
While the added tools are simple compared to most modern programming languages, they add a lot of functionality to mach's programing interfaces.

Dave
Author of the MachStdMill Extensions for Mach3
www.CalypsoVentures.com