PowerMill Custom UI

Hey guys, I just wanted to start a thread here about a custom UI I’ve been developing over the past few years.

Unfortunately I haven’t been able to quite figure out how to make plugins correctly, so I’ve resorted to rebuilding the PowerMill interface to suit what I need.

The concept is quite simple.

Step 1: Generate an HTML page that is compatible with PowerMill’s native web browser (HTML 3 i believe)

This can be done using FILE commands to generate a fresh page whenever you need.

Personally I call this using a Master Switchboard script (a script in which I house my CALL methods using patterns as my identifiers) but you can call this however you want.

Example Script:

RESET LOCALVARS

        // Create HomePage Website

        STRING fileName = "Main Page.html"

        STRING directory = "C:\PowerMill\Automation\Pages"

        STRING browserCall = $directory + "\" + $fileName

        IF dir_exists($directory) {
            CD $directory
        } else {
            MKDIR $directory
            CD $directory
        }

        if file_exists($fileName) {

            DELETE FILE $fileName

        }

        FILE OPEN $fileName FOR WRITE AS output

        STRING line = '<!DOCTYPE html>'
        FILE WRITE $line TO output
        $line = '<html>'
        FILE WRITE $line TO output
        $line = '<head>'
        FILE WRITE $line TO output
        $line = '<title>Your PowerMill Homepage</title>'
        FILE WRITE $line TO output
        $line = '<style>'
        FILE WRITE $line TO output
        $line = 'body {'
        FILE WRITE $line TO output
        $line = 'background-color: #108bce;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.container {'
        FILE WRITE $line TO output
        $line = 'display: flex;'
        FILE WRITE $line TO output
        $line = 'flex-direction: column;'
        FILE WRITE $line TO output
        $line = 'align-content: center;'
        FILE WRITE $line TO output
        $line = 'align-items: center;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.button-row {'
        FILE WRITE $line TO output
        $line = 'display: flex;'
        FILE WRITE $line TO output
        $line = 'flex-direction: row;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.button-column {'
        FILE WRITE $line TO output
        $line = 'display: flex;'
        FILE WRITE $line TO output
        $line = 'flex-direction: column;'
        FILE WRITE $line TO output
        $line = 'margin-right: 30px;'
        FILE WRITE $line TO output
        $line = 'margin-left: 30px;'
        FILE WRITE $line TO output
        $line = 'align-items: center;'
        FILE WRITE $line TO output
        $line = 'justify-content: center;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.mainpara {'
        FILE WRITE $line TO output
        $line = 'text-align: center;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.button {'
        FILE WRITE $line TO output
        $line = 'display: flex;'
        FILE WRITE $line TO output
        $line = 'align-items: center;'
        FILE WRITE $line TO output
        $line = 'justify-content: center;'
        FILE WRITE $line TO output
        $line = 'background-color: #EDF2F4;'
        FILE WRITE $line TO output
        $line = 'color: #0C1141;'
        FILE WRITE $line TO output
        $line = 'font-size: 20px;'
        FILE WRITE $line TO output
        $line = 'font-weight: bold;'
        FILE WRITE $line TO output
        $line = 'text-align: center;'
        FILE WRITE $line TO output
        $line = 'width: 300px;'
        FILE WRITE $line TO output
        $line = 'height: 50px;'
        FILE WRITE $line TO output
        $line = 'border-radius: 25px;'
        FILE WRITE $line TO output
        $line = 'margin-bottom: 10px;'
        FILE WRITE $line TO output
        $line = 'cursor: pointer;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.hubstart {'
        FILE WRITE $line TO output
        $line = 'width: 145px;'
        FILE WRITE $line TO output
        $line = 'margin-right: 5px;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.hubcall {'
        FILE WRITE $line TO output
        $line = 'width: 145px;'
        FILE WRITE $line TO output
        $line = 'margin-left: 5px;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.footer {'
        FILE WRITE $line TO output
        $line = 'position: fixed;'
        FILE WRITE $line TO output
        $line = 'text-align: center;'
        FILE WRITE $line TO output
        $line = 'bottom: 0px;'
        FILE WRITE $line TO output
        $line = 'width: 100%;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '.logo {'
        FILE WRITE $line TO output
        $line = 'width: 300px;'
        FILE WRITE $line TO output
        $line = 'height: 100px;'
        FILE WRITE $line TO output
        $line = '}'
        FILE WRITE $line TO output
        $line = '</style>'
        FILE WRITE $line TO output
        $line = '<script>'
        FILE WRITE $line TO output
        $line = '</script>'
        FILE WRITE $line TO output
        $line = '</head>'
        FILE WRITE $line TO output
        $line = '<body>'
        FILE WRITE $line TO output
        $line = '<div class="container">'
        FILE WRITE $line TO output
        $line = '<img src="Custom Logo URL Here" class="logo">'
        FILE WRITE $line TO output
        $line = '<h1>Powermill Homepage</h1>'
        FILE WRITE $line TO output
        $line = '<BR><BR><BR><BR>'
        FILE WRITE $line TO output
        $line = '</div>'
        FILE WRITE $line TO output
        $line = '<div class="container">'
        FILE WRITE $line TO output
        $line = '<div class="button-column">'
        FILE WRITE $line TO output
        $line = '<div class="button-column">'
        FILE WRITE $line TO output
        $line = '<button class="button" onclick="">Start Up</button>'
        FILE WRITE $line TO output
        $line = '<button class="button" onclick="">Open Existing</button>'
        FILE WRITE $line TO output
        $line = '<button class="button" onclick="">Automation Processes</button>'
        FILE WRITE $line TO output
        $line = '<button class="button" onclick="">Help and Training</button>'
        FILE WRITE $line TO output
        $line = '</div>'	
        FILE WRITE $line TO output
        $line = '</div>'
        FILE WRITE $line TO output
        $line = '</div>'
        FILE WRITE $line TO output
        $line = '</body>'
        FILE WRITE $line TO output
        $line = '</html>'
        FILE WRITE $line TO output

        FILE CLOSE output

        VIEW BROWSER_WIDTH "500"

        BROWSER GO $browserCall

Step 2: Once generated you can use the inside the HTML to execute PowerMill commands via the window.external.Execute() function from javascript.

This will allow custom methods or macros to be ran from within the HTML.

Myself, I have the functions inside the javascript generate patterns and then call the Master Switchboard script which then does a CALL method to my Master Function script (the main macro that houses all my macros and automation routines)

Honestly, I find this method pretty sleek and relatively easier to use for those who aren’t super savvy with coding. It’s an easy method to teach as well.

While I have been successful in create one off plugins, I haven’t been able to generate a Master Plugin that houses all my automation, where as this method can still run everything I’ve created over the years, and is quite easy to modify when adding additional modules and components to the existing macros and routines.

Hopefully this helps out a bit, or at least inspires someone to get a little more creative with the PowerMill UI.

Thanks

  • Jarryd

this is brilliant! can you give a code example of what happens when i click start up button? i would use this, i think

Thank you =)

That’s a loaded question lol. The startup sequence I have written is 2700+ lines long.

Essentially, I have the startup open another webpage called Job import. The programmer then enters the settings and the startup sequence initiates.

I’ve included the entire Startup Script for reference. Wouldn’t let me upload as a .mac so I have to convert it over to .txt

PowerMill Startup.txt (92.7 KB)

so when a user clicks a button, you have that linked to an external script that calls a macro command?

Essentially yes. The button creates a unique pattern in the PowerMill session, then calls a macro. The macro looks for that pattern, if it exists, it deletes the pattern than calls a macro from a Master List.

It’s essentially a switchboard that houses every call I require. This way I can keep all my macros in one script and just call which ever Function I require at that point.

I find it to be cleaner than having a million macro files. This way I have 6 scripts that house every macro and automation sequence.

that’s pretty creative! i need to dig into that more when i have time. we have some old guys here that would use that. i dont think they’d like my plugin (and it’s not really geared for molds) but they would love this UI, especially if it’s customized for mold programming

Yeah the old guys like it since the buttons are nice and large.

I’ve also optimized it so that the younger guys are able to run it through their phones while near the machines. Saves them from running back and forth between the floor and the office. Used mainly for quick fixes and sizing adjustments.

I’ll have to show it to them and have them drive what they want. that’s awesome, i’d never have thought of this

I’m not familiar with the ins and out of the PowerMill macro language, but you may want to have a look at the SWITCH statement. When you have miles and miles of IF-THEN statements, a SWITCH statement can make things a little more clear and concise:

SWITCH $someVariable
CASE ‘First possible value’
//do stuff for first value
BREAK
CASE ‘Second possible value’
//do stuff for second value
BREAK
DEFAULT
//do stuff when no matching CASE found

2 Likes

great observation!

Yeah when I originally wrote the startup, I wasn’t as fluent with the language as I am now. To be honest, it’s never stopped working so I’ve just let it sit haha.

I should probably go and clean it all up and re-factor it all at some point.

nah. whenever i share my old macros with a couple guys here, i always tell them “that’s before i learned about functions” or some such, & they say the same thing about theirs. if it isnt broken…

One day I’ll rewrite them like a proper programmer. Today is not that day though.

1 Like