Welcome to Our Community

Some features disabled for guests. Register Today.

Can OB Control Software pop up a message if it detects specific code in the GCode file?

Discussion in 'Control Software' started by SeanD, Feb 14, 2023.

  1. SeanD

    SeanD Well-Known
    Builder

    Joined:
    Mar 23, 2019
    Messages:
    207
    Likes Received:
    65
    I use Passthrough in Fusion 360 to send commands to my CNC such as “X500 F5000” to move out of the way for me to screw things down.

    Is it possible to send a message string via Passthrough that pops up a message box with an OK button and the message string displayed?

    I only really need this functionality on the loading of the file, not during operation.

    I mentioned the Passthrough as that is the closest thing I know so far relating to sending information to the control software. I understand that Passthrough would probably not be useful dor what I am trying to achieve.
     
  2. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Its not standard functionality. But if you know javascript, you can add it.

    I wrote a tool change macro that lets you open multiple files. Part of that looks for tool information and displays what bit to load. I used Peter's early work for tool changes as a starting point since it gave me a clue as to how to parse the loaded file and pull out the info I need. Here's the discussion: Toolchanges · Issue #26 · OpenBuilds/OpenBuilds-CONTROL

    And the code: OpenBuilds-CONTROL/toolchange.js at master · OpenBuilds/OpenBuilds-CONTROL

    And more info on how to write javascript macros with dialogs and such: Getting started with Javascript Macros in CONTROL / Library of Macros created by the community
     
    SeanD likes this.
  3. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Ok. Here's a crude way of doing it. It may work for you.

    I couldnt find a built in way to listen for just the file open so it listens for a change on the gcode editor tab, which happens when you load a file. It then looks for the first line that contains the text "ALERT:" and displays that line in a dialog. In fusion, you would add a passthrough comment that starts with "ALERT:"


    Code:
    editor.session.on('change', function(delta) {
      let foundAlert = editor.find('ALERT:');
      if (foundAlert !== undefined) {
        let alertText = editor.session.getLine(foundAlert.start.row);
        var dialog = Metro.dialog.create({
          clsDialog: 'dark',
          title: "<i class='fas fa-exclamation-triangle'></i> ALERT",
          content: "<i class='fas fa-exclamation-triangle fg-darkRed'></i> " + alertText,
          actions: [{
            caption: "Close",
            cls: "js-dialog-close",
            onclick: function() {
              //
            }
          }]
        });   
      }
    });
    If you use Controls gcode editor to edit the code, this is a terrible solution since it will pop up the dialog with every editing keystroke. Like I said, its crude, but may work for you.

    Here's the first few lines of my test gcode:

    Code:
    (Made in : Autodesk CAM Post Processor)
    (G-Code optimized for Grbl 1.1 / BlackBox controller)
    (OpenBuilds CNC : GRBL/BlackBox)
    (Post-Processor : OpenbuildsFusion360PostGrbl.cps V1.0.30)
    (Units = inch)
    
    (Drawing name : Keyhole bracket v2)
    (Program Name : 1001)
    
    (1 Operation :)
    (1 : 2D Pocket1)
    (  Work Coordinate System : G54)
    (  Tool 3: Flat End Mill 3 Flutes, Diam = 0.25inch, Len = 0.75inch)
    (  Spindle : RPM = 5100)
    (  Machining time : 24 sec)
    
    G90 G94 G17
    G20
    
    (ALERT: Do this now)
    (ALERT: Do this also)
    upload_2023-2-15_7-13-21.png
     
    SeanD and Peter Van Der Walt like this.
  4. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Okay. I think I got it. This code will alert on file load but not on user edits.

    Code:
    function alertMacro() {
      editor.session.on('change', function(e) {
        if (editor.curOp && editor.curOp.command.name) {
          return null;
        }  
        let foundAlert = editor.find('ALERT:');
        if (foundAlert !== undefined) {
          let alertText = editor.session.getLine(foundAlert.start.row);
          console.log('what is pos ' + alertText)    
          var dialog = Metro.dialog.create({
            clsDialog: 'dark',
            title: "<i class='fas fa-exclamation-triangle'></i> ALERT",
            content: "<i class='fas fa-exclamation-triangle fg-darkRed'></i> " + alertText,
            actions: [{
              caption: "Close",
              cls: "js-dialog-close",
              onclick: function() {
                //
              }
            }]
          });
        }    
      });
    }
    
    $(document).ready(() => setTimeout(alertMacro, 1000));
    
    
    Oh, in case you dont know. Add this to a javascript macro and select "Run macro at startup". Restart Control and you should be set.
     
    #4 sharmstr, Feb 15, 2023
    Last edited: Feb 15, 2023
    SeanD and Peter Van Der Walt like this.
  5. SeanD

    SeanD Well-Known
    Builder

    Joined:
    Mar 23, 2019
    Messages:
    207
    Likes Received:
    65
    Family member was in hospital so I hope you accept my apology for not replying to this amazing post. This actually helps out with a lot of other sequencing too! You have gone above and beyond here.

    I appreciate how much time you spend helping others. I am so grateful.
     
    sharmstr and Peter Van Der Walt like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice