Welcome to Our Community

Some features disabled for guests. Register Today.

Tech support for Javascript Macros in CONTROL

Discussion in 'Control Software' started by sharmstr, Jan 4, 2021.

  1. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    Thank you Peter, very useful. I have to look for a NO probe.
     
    Peter Van Der Walt likes this.
  2. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    Thank you too for turning ON my lantern :)
    Your script is a great job well done :thumbsup:
     
    Misterg likes this.
  3. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    Misterg and Peter Van Der Walt like this.
  4. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    @Peter Van Der Walt @Misterg
    The 3D probe is operational, it works in parallel with the XYZ+ probe with the macro. Thank you very much for your details!
     
    Misterg and Peter Van Der Walt like this.
  5. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    Hello !
    Sorry to ask a silly question, but how to get this file (Alternative UI ), because Center Finder V2.zip gives me default UI, I did not find the link :(
    Thanks for all
     
  6. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    14,868
    Likes Received:
    4,283
    Set simpleUI = "false" inside the macro's code (JavaScript tab)

    As per the instructions in thread
     
    Alain JBT likes this.
  7. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    Hi Super Team!
    I changed the variable and it works very well.

    @Misterg I have another good ... or bad question:
    Could you tell me how to display the external measurement result of the probe as it displays in the Peter script
     
  8. Misterg

    Misterg Veteran
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    350
    Likes Received:
    273
    I’m away at the moment - I’ll have a look when I get home in a day or so.
     
  9. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    53
    Likes Received:
    31
    Thank you @Misterg , this is not an emergency:)
     
  10. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Small display issue in dark mode. Its hard to see with the fg-black you have on the button icon. There's no need to call out the color. By default its black in light mode and white in dark mode.

    upload_2024-4-22_12-15-2.png

    With fg-black removed


    upload_2024-4-22_12-15-38.png
     
    Misterg and Peter Van Der Walt like this.
  11. JP Cassar

    JP Cassar New
    Builder

    Joined:
    May 3, 2024
    Messages:
    2
    Likes Received:
    3
    Sharing my updates:
    - Round to 3 digits after comma
    - Added fractional measurement for inches
    - Split output into 2 lines
    Code:
    Math.gcd= function(a, b){
        if(b) return Math.gcd(b, a%b);
        return Math.abs(a);
    }
    
    Math.roundFraction= function(n, prec, up){
        var s= String(n), 
        p= s.indexOf('.');
        if(p== -1) return s;
    
        var i= Math.floor(n) || '', 
        dec= s.substring(p), 
        m= prec || Math.pow(10, dec.length-1), 
        num= up=== 1? Math.ceil(dec*m): Math.round(dec*m), 
        den= m, 
        g= Math.gcd(num, den);
    
        if(den/g==1) return String(i+(num/g));
    
        if(i) i= i+'"-';
        return i+ String(num/g)+'/'+String(den/g);
    }
    
    const round = (n, dp) => {
      const h = +('1'.padEnd(dp + 1, '0')) // 10 or 100 or 1000 or etc
      return Math.round(n * h) / h
    }
    
    if (typeof object !== 'undefined') {
       var precision = 32
       var string = ""
       if (object.userData.inch) {
           string += "Width (X): " + round((object.userData.bbbox2.max.x - object.userData.bbbox2.min.x), 3) + "inch (" + Math.roundFraction(object.userData.bbbox2.max.x - object.userData.bbbox2.min.x, precision) + ") <br/> " + "Height (Y): " + round((object.userData.bbbox2.max.y - object.userData.bbbox2.min.y), 3) + "inch (" + Math.roundFraction(object.userData.bbbox2.max.y - object.userData.bbbox2.min.y, precision) + ")";
       } else {
           string += "Width (X): " + round((object.userData.bbbox2.max.x - object.userData.bbbox2.min.x), 3) + "mm" + " / " + "Height (Y): " + round((object.userData.bbbox2.max.y - object.userData.bbbox2.min.y), 3) + "mm";
       }
       console.log(string)
       Metro.dialog.create({
           title: "Stock Size needed",
           clsDialog: "dark",
           content: `
              To run this job, you need a piece of stock:<hr>
              ` + string + `
          `,
           actions: [{
               caption: "Cancel",
               cls: "js-dialog-close alert",
           }]
       });
    }
    
     
  12. Hykr3n

    Hykr3n New
    Builder

    Joined:
    Sep 27, 2023
    Messages:
    26
    Likes Received:
    6
    Is there a way to probe and find center of 2 point like a slot ou a groove?

    i never messed with macro and dint want to break something so im asking here 1st

    thanks
     
  13. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    14,868
    Likes Received:
    4,283
  14. BASt_NL

    BASt_NL New
    Builder

    Joined:
    Sep 9, 2022
    Messages:
    24
    Likes Received:
    3
    Since a lot is possible to adapt the UI with the javascript macro's, like adding/removing interface buttons... would it also be possible in this route to have the serial and Macro tab show side by side (50%/50%) instead of on separate tabs?
     
  15. kaoscreations

    Builder

    Joined:
    Aug 9, 2022
    Messages:
    13
    Likes Received:
    2
    uhao super!! but it's possible add also the information about toolpath that I've insert in my Gcode for postprocessor?
     
  16. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    I havent fully tested this, but should work. Put the following code into a javascript macro and set it to run at startup.

    Code:
    $('#macros').insertAfter('#console')
    $('#consoletab').html('<i class="fas fa-fw fa-terminal fg-darkGreen"></i> Console / Macros')
    $('#tab-four').remove()
    $('#macrostab').remove()
    $("#macros").css({"height": "calc(100vh - 535px)", "overflow-y": "auto"})
    



    upload_2024-5-21_8-28-42.png
     
  17. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Can you be more specific? What exactly do you want?
     
    JP Cassar likes this.
  18. kaoscreations

    Builder

    Joined:
    Aug 9, 2022
    Messages:
    13
    Likes Received:
    2
    Yes, thanks!
    I was wondering if in this screen the information on the size of the piece would come out, also including the depth of the Z, and the information on the cutter to use (if they exist in the original Gcode).
    For example
    To do this job you need a piece of this size
    x ----
    y----
    z---
    and these tools
    (tool size),(tool name)

    Are you saying it can be done?
     
  19. JP Cassar

    JP Cassar New
    Builder

    Joined:
    May 3, 2024
    Messages:
    2
    Likes Received:
    3
    Yes for Z. Locate this line:
    Code:
    if (object.userData.inch) {
    
    and replace by:
    Code:
    if (object.userData.inch) {
           string += "Width (X): " + round((object.userData.bbbox2.max.x - object.userData.bbbox2.min.x), 3) + "inch (" + Math.roundFraction(object.userData.bbbox2.max.x - object.userData.bbbox2.min.x, precision) + ") <br/> " + "Height (Y): " + round((object.userData.bbbox2.max.y - object.userData.bbbox2.min.y), 3) + "inch (" + Math.roundFraction(object.userData.bbbox2.max.y - object.userData.bbbox2.min.y, precision) + ")<br/>" + "Depth (Z): " + round((object.userData.bbbox2.max.z - object.userData.bbbox2.min.z), 3) + "inch (" + Math.roundFraction(object.userData.bbbox2.max.z - object.userData.bbbox2.min.z, precision) + ")";
       } else {
           string += "Width (X): " + round((object.userData.bbbox2.max.x - object.userData.bbbox2.min.x), 2) + "mm" + "<br/>" + "Height (Y): " + round((object.userData.bbbox2.max.y - object.userData.bbbox2.min.y), 2) + "mm<br/>" + "Depth (Z): " + round((object.userData.bbbox2.max.z - object.userData.bbbox2.min.z), 2) + "mm";
       }
    
     
    sharmstr likes this.
  20. BASt_NL

    BASt_NL New
    Builder

    Joined:
    Sep 9, 2022
    Messages:
    24
    Likes Received:
    3
    Works flawless, thx!
    I'm struggling on how to adapt it to start with that panel active; discovered it is already named tab-one, while it boots up with the 3Dview which is tab-three??
     
  21. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Tab numbers have little to do with it. They are just names.

    Control does "start" with the console tab active. So Im assuming you mean after loading a file?
     
  22. BASt_NL

    BASt_NL New
    Builder

    Joined:
    Sep 9, 2022
    Messages:
    24
    Likes Received:
    3
    I'll have to check tomorrow when it is connected to the controller, but when not connected the application 'starts' with the 3D view tab for me.
     
  23. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    14,868
    Likes Received:
    4,283
    It does, then when you connect we switch to the log tab to show you the connection. When you load a file we switch to 3D view. Load a file but 3D view is broken or disabled > we switch to Gcode editor tab for you. Always relevant context
     
    sharmstr and BASt_NL like this.
  24. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    Add this to the bottom of the macro I gave you

    Code:
    $('#consoletab').click()
     
  25. BASt_NL

    BASt_NL New
    Builder

    Joined:
    Sep 9, 2022
    Messages:
    24
    Likes Received:
    3
    Perfect, thankyou!
     
  26. kaoscreations

    Builder

    Joined:
    Aug 9, 2022
    Messages:
    13
    Likes Received:
    2
    This is Fantastic thanks!! I've tested this, if it were possible you could insert the fact that the close button closes (now I have to make several clicks) and that the alarm goes off after 3 seconds (or if I can set it, can you tell me how to do it? I tried to change the timeout but I'm doing something wrong ). It's seems like that are opened 15 screen of the same alert :(
    Furthermore, if possible, could it be made to work once the file has been loaded or even with a push button? so if I forget the parameters I can recall them :)

    Thank you very much and congratulations, super work!!
     
    #206 kaoscreations, May 27, 2024
    Last edited: May 27, 2024
  27. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,448
    My guess is that you've clicked the macro button several times and its loaded the function several times. Its meant to be run once at startup, so edit the macro and select "Run Macro on startup". Save and restart Control.

    upload_2024-5-27_6-43-12.png

    If you need to recall the info, click on the GCODE Editor tab. Its all the start of the file

    upload_2024-5-27_6-44-1.png
     
  28. kaoscreations

    Builder

    Joined:
    Aug 9, 2022
    Messages:
    13
    Likes Received:
    2
    hi!! this is perfect, works very well, thanks!!!!
     
  29. Misterg

    Misterg Veteran
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    350
    Likes Received:
    273
    Peter Van Der Walt likes this.
  30. Misterg

    Misterg Veteran
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    350
    Likes Received:
    273
    Alain JBT 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