Tapatalk

How to make collapsible code blocks for G-code?

How to make collapsible code blocks for G-code?

12
Basic UserBasic User
12

    Sep 12, 2022#1

    Hi,
    I'm trying to figure out how I can generate collapsible code blocks.
    I work a lot with G-code for 3D printing and it would be a big help if I were able to tell UE to generate collapsible blocks via specific words.
    Let´s say I have a G-code file that contains 300 layers for 3D printer to print. Every layer is marked in the code with layer:1, layer:2, layer:3...
    Is there a way to tell UE to make collapsible blocks going from layer:1 -> layer:2 and another from layer:2 -> layer:3 and so on?

    6,685587
    Grand MasterGrand Master
    6,685587

      Sep 12, 2022#2

      That should be no problem. There is needed first a syntax highlighting wordfile for G-code. The page User-submitted wordfiles for UltraEdit/UEStudio contains Mills G-Codes and and Lumonics Gcode. Which one is more suitable must be find out by yourself. I don't know it. Use the more suitable one by adding it to the wordfiles directory which is by default %APPDATA%\IDMComp\UltraEdit\wordfiles.

      The file extension definition in millg.uew looks very strange as I doubt that files with G-code have usually one of the file extensions C CPP CC H HPP AWK. The string and comment definitions it this wordfile also do not look right for me. It looks like this wordfile was created by a user using the standard wordfile for C/C++ without having really read the help page with title Syntax Highlighting explaining the keywords or using the template for syntax highlighting language wordfile (which I know I have to update for currently latest UltraEdit for Windows v2022.1.0.100).

      The other syntax highlighting wordfile lumonics.uew seems to be also not much better.

      The Wikipedia page about G-code lists much more keywords than defined in both wordfiles. I found also the forum topic G code highlighting.

      I have full knowledge about the keywords in the syntax highlighting wordfiles of UltraEdit/UEStudio, but absolutely no knowledge about G-code syntax. However, that was true also for other languages in the past and I could nevertheless help UE/UES users to create a good working wordfile for syntax highlighting with a useful function list, support for automatic indent and unindent, support for code folding, brace matching, etc. after getting the information where I could read about the syntax of the language to highlight and some examples files provided by the user and what should be listed in the function list view and how this list should look like.

      For your code folding requirement it would be perhaps enough to have in the wordfile used to syntax highlight files with G-code the lines:

      Code: Select all

      /Open Fold Strings = "layer"
      /Close Fold Strings = "layer"
      Please note that the last layer block will not be suggested for folding by UltraEdit as there is no close fold string. I requested years ago that end of file should be interpreted as end of a block to fold if open and close fold strings are identical. But it looks like I was the only UE/UES user who has ever requested that as such an enhancement is still not implemented in UltraEdit for Windows v2022.1.0.100.

      For the Function List view would be perhaps useful:

      Code: Select all

      /Regexp Type = Perl
      /TGBegin "Layers"
      /TGFindStr = "^[\t ]*(layer):(\d+)"
      /TGEnd
      Or there is used in the wordfile:

      Code: Select all

      /Regexp Type = Perl
      /TGBegin "Layers"
      /TGFindStr = "^[\t ]*(layer:\d+)"
      /TGEnd
      The layers are listed in the Function List view with a space character between the keyword layer and the number with first suggested block in the wordfile or as really written in the file with a colon with the suggested second block.
      Best regards from an UC/UE/UES for Windows user from Austria

      12
      Basic UserBasic User
      12

        Sep 13, 2022#3

        Thank you so much. I will work through it tomorrow and get back to you once I got it working or if I should have any further questions.

          Sep 15, 2022#4

          I cant seem to get it to work properly. I have looked into wordfiles and changed up the html one with the code snipped you provided to do the folding, but it doesnt do anything at all. 

          The gcode I am working with looks like this:

          Code: Select all

          [...]
          G0 X425.468 Y128.376
          G0 X426.122 Y127.23
          G0 X426.966 Y126.214
          G0 X428.043 Y125.309
          G0 X429.189 Y124.655
          G0 X430.413 Y124.215
          G0 X430 Y124.997
          ;TIME_ELAPSED:22984.662168
          ;LAYER:98
          ;TYPE:SUPPORT
          G1 F2400 E0.29212
          G1 F6000 X430 Y196.661 E6.86464
          G1 F2400 E-0.5
          G0 F7200 X435 Y197.08
          G1 F2400 E0.29212
          G1 F6000 X435 Y124.569 E6.94577
          G1 F2400 E-0.5
          G0 F7200 X440 Y124.569
          [...]
          G0 X427.02 Y195.49
          G0 X426.166 Y194.481
          G0 X425.469 Y193.276
          G0 X425.021 Y192.033
          G0 X424.795 Y190.73
          G0 X424.804 Y130.892
          G0 X425.566 Y130
          ;TIME_ELAPSED:23099.962084
          ;LAYER:99
          ;TYPE:SUPPORT
          G1 F2400 E0.29212
          G1 F6000 X497.706 Y130 E6.91023
          G1 F2400 E-0.5
          G0 F7200 X497.89 Y135
          G1 F2400 E0.29212
          G1 F6000 X425.379 Y135 E6.94577
          G1 F2400 E-0.5
          [...]
          It would make sense to make blocks from ";LAYER:" to ";TIME_ELAPSED:" as this would put every layer into a sweet little tidy 'container'. I have already changed the strings in your code to those and tried it, but still nothing.
          I dont really need a complete wordfile to markup the whole code as the folding is way more important right now. Furthermore, I have to work with several hundred million lines of gcode in every file and being able to organize them that way would be a huge time saver for me.

          6,685587
          Grand MasterGrand Master
          6,685587

            Sep 15, 2022#5

            HTML is very special for syntax highlighting. The wordfile html.uew should be not used as template to create a wordfile for any other language than HTML. So you better delete the wordfile created by making a copy of html.uew.

            Are lines starting with a semicolon comment lines G-code syntax or does the semicolon has a special meaning for the software processing G-code?

            That is important to know because of there can be used:

            Code: Select all

            /Open Fold Strings = "layer"
            /Close Fold Strings = "layer"
            as well as

            Code: Select all

            /Open Comment Fold Strings = "layer"
            /Close Comment Fold Strings = "layer"
            depending on first line in the wordfile does not contain Line Comment = ; or contains that line comment definition.
            Best regards from an UC/UE/UES for Windows user from Austria

            12
            Basic UserBasic User
            12

              Sep 16, 2022#6

              semicolon is a comment line in G-code, indeed.

                Sep 16, 2022#7

                I will be honest I am having a real hard time getting it to work. I have tried to write a very basic wordfile based on my needs. It is just not working.
                Shouldnt be something like this enough for what I am trying to achieve?

                Code: Select all

                /L22"GCode" Line Comment = ; File Extensions = gcode
                /Open Comment Fold Strings = "layer"
                /Close Comment Fold Strings = "layer"
                /C1"No Extrusion Moves"
                G0
                /C2"Extrusion Moves"
                G1
                /C3"GCode Macros"
                M104 M109 M82 T0 M107 M106
                /C4"Structure Type"
                ;TYPE:SUPPORT ;TYPE:FILL ;TYPE:INNER_WALL ;TYPE:OUTER_WALL 
                /C5"Layer"
                ;LAYER
                /C6"F"
                F
                /C7"X"
                X
                /C8"Y"
                Y
                /C9"Z"
                Z
                /C10"E"
                E
                The gcode in UE with this wordfile looks like this:

                I dont know why, but its giving me headache. I just cant get my head around it.

                6,685587
                Grand MasterGrand Master
                6,685587

                  Sep 17, 2022#8

                  I created four versions of a syntax highlighting wordfile for G-code based on what I read on Wikipedia page about G-code and tested them on a file with the G-code posted by you combined with the example G-code on Wikipedia page. Please extract the attached ZIP file and copy the four *.uew files into the directory %APPDATA%\IDMComp\UltraEdit\wordfiles. Next start UltraEdit and open the four Test.gcode? files which have identical contents. Then open in UltraEdit the Manage Themes dialog window, select tab Syntax and quickly configure for the four languages G-code v? all the color groups with making sure that each color group with a name has a unique color which no other color group has.

                  What is common for all four wordfiles?
                  1. All four wordfiles are case-sensitive which means g0 is not syntax highlighted, just G0. I don't know if G-code is case-sensitive or not and I don't know if you prefer all G-code files without small letters.
                    The advantage with a case-sensitive syntax highlighting language definition is that there can be entered the letters in lower case and UltraEdit corrects them to upper case if the configuration setting Auto-correct keywords is checked at Advanced - Settings or Configuration - Editor display - Miscellaneous if that character is being a syntax highlighted "word". The auto-correction is not done on strings syntax highlighted using a substring definition.It is possible to insert after "G-code v?" in the first line a space character and the language keyword Nocase to make the syntax highlighting definition case-insensitive.
                  2. The language keyword Noquote disables the default string highlighting as G-code definitely does not contain strings in single or double quotes.
                  3. A set of three Perl regular expression search strings is used to get displayed in the Function List view on being opened the program name, the layers and the times elapsed in a hierarchical or a flat list. The type of the list can be changed by right clicking into the Function List view and clicking on context menu item Flat list to toggle this option.
                  4. It is important for the first and fourth version that UltraEdit does not remove all comments before applying the syntax highlighting which is done by default since UltraEdit for Windows v24.20. The language term /Strip Comments = No is for that reason in all four wordfiles although really needed only in first and fourth wordfile.
                    That is the first reason why your fold string definition has not worked as expected.
                  5. The percent sign is interpreted as open/close fold string in all four wordfiles. That is very important on first and fourth wordfile as the open/close comment fold strings are ignored if there are no open/close fold strings defined, too. I described that important fact in the template for creation of a wordfile.
                    That is the second reason why your fold string definition has not worked as expected.
                  6. There can be used up to 20 color groups. So there is made use of nearly all of them.
                    It is of course possible to change the words/substrings assignments to the color groups to whatever is preferred.
                  7. All four wordfiles contain /Word Select Include = +-. to interpret a plus and minus sign (in real hyphen) and a dot as word character on selecting a word with a double click or using the command Select word. Please note that this definition is only for selecting a word, not for syntax highlighting a word. But I suppose that feature will be very helpful for you in the future on selecting a floating point value on a G-code file with a double click or using the command to select a word.
                  What is special on first wordfile?

                  The first wordfile defines a line comment. Everything from a semicolon to end of a line is syntax highlighted as a comment. Therefore it is not possible to get words or values syntax highlighted with a different color on a line after the semicolon. This is the reason why the first wordfile does not contain the color group 4 in comparison to the second and third wordfile.

                  If this version is preferred by you finally, it would be best to renumber the color groups 5 to 17 to 4 to 16 to avoid the gap in the color groups.

                  The list of /Delimiters = is very short for this wordfile. There are only space, horizontal tab, colon and semicolon interpreted as word delimiters for syntax highlighting (not for selecting a word). This makes it possible to use substring definitions to syntax highlight all strings starting with a specific character with the color and font style settings as defined for the color group containing the appropriate syntax highlighting definitions. That is used for the color groups 5 to 16.

                  The first three color groups lists all possible values for instructions (hope this is a good name for this color group), macros and parameters. There are not used substring definitions for these three color groups. The reason is that a good syntax highlighting definition should highlight only strings being really valid for the interpreter of the code. So if this version is finally the one used by you, I recommend to look into the manual of the machine and make sure that the first three color groups contain only the "words" really supported by the machine. That would be in future helpful for you as you would visually see what is wrong in G-code on using a string starting with G or M or P which is not syntax highlighted. The auto-completion feature is also only useful on getting only valid "words" suggested on making use of the auto-completion feature.

                  What is special on second wordfile?

                  The second wordfile does not define a semicolon as beginning of a line comment. That makes it possible to syntax highlight also strings in a line after a semicolon as done with color group 4 which I gave the name Keywords as I don't know enough about G-code to find a better name for the words in this color group. I added also ; and : as "words" to this color group. Please note that semicolon and colon are word delimiters for syntax highlighting and are therefore always interpreted as single character words by the syntax highlighting of UltraEdit. It is of course possible to use a separate color group for semicolon and colon if that is preferred by you on using this version of the G-code syntax highlighting.

                  Important here is that the color group with LAYER has a lower number as the color group with the substring definition to highlight all words starting with L to get this word really highlighted separately from all other words starting with L. That rule is important also for the words SUPPORT, TIME_ELAPSED and TYPE which I added also to color group 4.

                  Everything else to know about the second version for G-code syntax highlighting is identical to first version.

                  What is special on third wordfile?

                  The third wordfile has a different set of word delimiters in comparison to second wordfile. Every digit, plus sign, minus sign and dot is interpreted as word delimiter for syntax highlighting by this language definition. That changes the syntax highlighting completely. Now the numbers are always syntax highlighted with the predefined color group Numbers and just the letter left to the number is syntax highlighted according to the color group.

                  The last color group with name Signs, dot can have the same color and font style settings as the predefined color group Numbers or can have different settings. That is up to you on using this wordfile.

                  The first three color groups contain now only the characters G, M and P as word because of each digit is itself a single character word for syntax highlighting. So the syntax highlighting with third version gives the user no information about valid or invalid instruction, macro or parameter as it is not possible to define a "word" in a color group which consists of multiple "words" according to the word delimiters definition. That is of course a disadvantage of this wordfile, but you might like that syntax highlighting more than the two others.

                  What is special on four wordfile?

                  That wordfile is a combination of the first wordfile with a line comment definition and the third wordfile with the special word delimiters definition to syntax highlight all floating point numbers as numbers.

                  Some more notes:

                  The list of instructions, macros and parameters should be reduced finally to what the machine really supports according to its manual on using the first or the second version suggested by me.

                  The finally used wordfile should have no gap in numbering of the color groups  as the first and the fourth version currently have.

                  The color groups can be redefined by you, for example by splitting up the first color group for the instructions into multiple color groups according to meaning of the instructions to have a visual indication what the appropriate G-code is for. But please note that more than 20 color groups are not possible.

                  Please let me know if you would like to see more in the Function List view  or if you need help to further enhance one of the four wordfiles after having decided which one is liked most by you.

                  The version information should be removed from the file name of the finally used G-code wordfile as well as from language name at beginning of the first line.

                  The file extension of finally used syntax highlighting wordfile should be changed to the file extension really used for G-code files at end of the first line.

                  The three not further used wordfiles should be removed from the wordfiles directory.

                  The color and font style settings of the the longer used wordfiles should be finally removed from the theme file which is in %APPDATA%\IDMComp\UltraEdit\themes or its subdirectory overrides depending on using a custom theme or override (extend) a standard theme with the color and font style settings for G-code syntax highlighting.
                  g-code_file_set_1.zip (5.24 KiB)   4
                  This ZIP file contains for versions of a wordfile for syntax highlighting G-code with four test files with identical contents.
                  Best regards from an UC/UE/UES for Windows user from Austria

                  12
                  Basic UserBasic User
                  12

                    Sep 19, 2022#9

                    This must be the best support I have ever gotten for anything. I have chosen to use the first wordfile and try to tweak it a little by myself to hopefully get a better understanding on how it works. 
                    There are different kinds of 'Flavour' of gcode depending on the system your machine is running on. A little tweaking is necessary as commands can be different.

                    There is one more thing:

                    Is there a way to tell UE to fold those blocks by default? I have a few hundred layers in most of my files and I really want them all to be folded so that I just have to open the ones I need to tweak. 
                    Having to fold them all first is kinda tedious.

                    You have been incredibly helpful so far and if I should stumble again, I will get back to you.

                    6,685587
                    Grand MasterGrand Master
                    6,685587

                      Sep 19, 2022#10

                      Yes, it should be possible to fold (collapse) everything already on opening a G-code file by using a macro executed on each file load, but that is not working anymore since UltraEdit for Windows v25.10 as I could find out with testing the solution described below.

                      There must be created a macro with a name of your choice and with the properties Show cancel dialog for this macro and Continue if search string not found and Disable screen refresh during macro playback unchecked in Macro Definition dialog window. The following macro commands should be used for that macro:

                      Code: Select all

                      IfExtIs "gcode"
                      HideShowCollapseAll
                      ExitMacro
                      EndIf
                      This macro simple collapse (fold) all blocks of active file on having the file extension gcode. The file extension must be specified without the dot.

                      This small macro is saved into a macro file with a file name of your choice and a storage location of your choice. I recommend to create a subdirectory macros in directory %APPDATA%\IDMComp\UltraEdit and save the macro file with the small macro in this directory. Next this macro file and the macro must be configured to be run automatically on each file open using the command Set macro for file open/save which opens the dialog window Set Macro to Run on File Load/Save. Browse to just saved macro file and enter the name of the macro in edit field below Macro to run on load and change # of times from 0 to 1. Then click on button Set.

                      Whenever a file is opened/loaded now, UltraEdit runs the macro which folds all layer blocks if the file has the file extension gcode. There is nothing done on opening other files.

                      That works up to UltraEdit for Windows v25.00.0.82, but does not work anymore with v25.10.0.10 and any newer version up to currently latest v2022.1.0.100. I think, this issue is caused by the changes made by the UltraEdit developers to startup UltraEdit faster and load files faster. The macro is definitely executed as I could see with adding additionally the command Bottom after command HideShowCollapseAll, but it looks like the syntax highlighting definition is not already loaded and applied to the opened file when the macro is executed on file open. I read in the file changes.txt in program files folder of UltraEdit about improvements for faster loading dozens of files as some users have opened on exit/startup of UltraEdit so that UltraEdit becomes faster responsive for the user after startup. The disadvantage seems to be that a macro making use of definitions in the syntax highlighting wordfile is now run to early on file open. There was introduced also code folding improvements with UE v25.10 which could be also the cause why code folding on file open via a macro does not work anymore since v25.10. I will report this issue to UltraEdit support by email.

                      So you have to press the hotkey Ctrl+Add which is assigned by default to the command Collapse all in the key mapping configuration dialog to collapse all in G-code file after opening it depending on used version of UltraEdit. (Add is the key + on the numeric keypad.)

                      I could code for you also a macro which collapses the blocks manually for G-code files independent on syntax highlighting wordfile if you would like that as workaround for folding all layer blocks on opening a G-code file. Please let me know if you would like the macro code for code folding. It would be no problem for me to code this little macro too.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      12
                      Basic UserBasic User
                      12

                        Sep 21, 2022#11

                        Thank you, but the shortcut Ctrl+Add is more than enough. That lets me take a quick look at it before I fold it all.

                        6,685587
                        Grand MasterGrand Master
                        6,685587

                          Sep 21, 2022#12

                          The issue with the macro command HideShowCollapseAll not working as expected in macro executed on file load could be reproduced by UltraEdit support on doing the steps and using the files of my report and is added to the issue database for investigation by an UltraEdit developer. That is not anymore important for you, but might be a useful information for other readers of this forum topic.
                          Best regards from an UC/UE/UES for Windows user from Austria