Skip to content

Commit b9efbe7

Browse files
committed
Initial Commit
1 parent de2eba5 commit b9efbe7

2 files changed

Lines changed: 163 additions & 2 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Jam-Es.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,142 @@
1-
# GCode-Razor-PostProcessor
2-
Adds loops and recursion features to early versions of GCode (using C# Razor Syntax). Complete with editor and examples.
1+
# G-Code Razor
2+
3+
[G-Code](https://en.wikipedia.org/wiki/G-code) the most common language used for programming CNC machines.
4+
5+
Modern features have gradually been added to G-Code over the past few decades. Early versions of G-Code did not have support for features such as iterative loops and trigonometric functions.
6+
7+
This Windows 10 App is intended for engineers working with older machines that do not support modern G-Code or CAD/CAM software. It gives you modern G-Code features through a postprocessor. This means you write your G-Code slightly differently (using [Razor syntax](https://en.wikipedia.org/wiki/ASP.NET_Razor)), and press a button to generate the raw G-Code which can then be run on the machine.
8+
9+
![alt text](ttps://cdn.jam-es.com/img/gcoderazor/screenshot1.PNG "G-Code Razor Screenshot")
10+
11+
## Download and Run
12+
13+
Requires Windows 10, 64-bit.
14+
15+
1. Go to the [Github Releases Page](https://github.com/James231/GCode-Razor-PostProcessor/releases).
16+
17+
2. Under the 'Assets' section, download the `.zip` file.
18+
19+
3. Unzip the file and save the contents somewhere. Double click on `GCodeRazor.exe` to run it.
20+
21+
**Note:** In the unlikely event that this repo gets some interest, I will package the app into an installer to make the installation process smoother and reduce the chance of it being blocked by anti-virus software.
22+
23+
24+
## Examples
25+
26+
G-Code Razor includes a page full of examples. But here are a couple to demonstrate its purpose:
27+
28+
Firstly you can use basic trigonometric functions like this:
29+
```gcode
30+
N10 G00 X0.2 Y@(sin(45))
31+
```
32+
When you press 'Generate' in G-Code razor this produces:
33+
```gcode
34+
N10 G00 X0.2 Y0.707106781186547
35+
```
36+
Or you can add rounding with:
37+
```gcode
38+
N10 G00 X0.2 Y@(round(sin(45)), 4)
39+
```
40+
Which gives:
41+
```gcode
42+
N10 G00 X0.2 Y0.7071
43+
```
44+
45+
The biggest time saver comes when using loops. For example, the following code requires lots of copy and pasting and editing:
46+
47+
```gcode
48+
N10 G00 X0.2
49+
N10 G00 Y0.1
50+
N10 G00 X0.3
51+
N10 G00 Y0.1
52+
N10 G00 X0.4
53+
N10 G00 Y0.1
54+
N10 G00 X0.5
55+
N10 G00 Y0.1
56+
N10 G00 X0.6
57+
```
58+
**Note:** The line numbers are not set correctly, but this rarely causes problems, and can be set corrected your primary G-Code editor.
59+
60+
But, instead of typing the code above you can enter the following into G-Code Razor:
61+
62+
```
63+
@for(int i = 0; i < 5; i++) {
64+
@:N10 G00 X@(0.2+(i*0.1))
65+
@:N10 G00 Y0.1
66+
}
67+
```
68+
While this may look complex, the examples page in the App explains this in detail and lets you copy snippets to change yourself. It is simpler than it looks!
69+
70+
## Settings
71+
72+
G-Code Razor has a few customizable settings. You can change them by editing the `settings.json` file. These are the settings in the version on the Releases page:
73+
74+
```json
75+
{
76+
"open_file_when_generated": false,
77+
"trim_output": true,
78+
"files_to_concat": [
79+
"cshtml/trig.cshtml"
80+
],
81+
"font_size": 20,
82+
"line_numbers": true,
83+
"word_wrap": false,
84+
"ask_before_closing": true
85+
}
86+
```
87+
88+
The file should consist of valid [Json](https://www.w3schools.com/js/js_json_syntax.asp).
89+
90+
## C# and Razor
91+
92+
The tool effectively gives you access to the whole of the C# programming language and .NET Framework libraries.
93+
94+
The full Razor documentation can be found [here](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-3.1). This basically tells you how to use the `@` signs.
95+
96+
Functions like `sin`, `cos` and `round` are C# functions I have written. They can be edited and you can add your own. For example, `sin` is defined by:
97+
```cs
98+
double sin(double angle) {
99+
return System.Math.Sin(ToRadians(angle));
100+
}
101+
```
102+
These functions are defined in the `cshtml/trig.cshtml` file. You can edit the file or add more `cshtml` files providing you list the file paths in the `files_to_concat` setting in `settings.json`.
103+
104+
The contents of these `cshtml` files is added to the start of the code you type into G-Code Razor (just string concatenation) before generating using [RazorLight](https://github.com/toddams/RazorLight).
105+
106+
Not all .NET Framework libraries are included by default (there are a lot of them) so if something you need is missing, you need to build from source after adding a reference to the solution.
107+
108+
## Building From Source
109+
110+
Use Visual Studio 2019 or later, with desktop development workloads installed. Open the solution (`.sln` file) and build.
111+
112+
**Note:** If you build this way the `settings.json` will be different, as the `cshtml/trig.cshtml` file will not be present. This means functions like `sin`, `cos`, `round`, etc, will be missing. The files can be copied from the version on the Releases page to fix this.
113+
114+
## Dependencies
115+
116+
[RazorLight](https://github.com/toddams/RazorLight) - Provides API around Razor engine to make it possible to use in any kind of .NET app.
117+
118+
[Material Design In Xaml](http://materialdesigninxaml.net/) - The WPF styles used in this app.
119+
120+
[AvalonEdit](http://avalonedit.net/) - The code editor WPF control used for the code fields in the app.
121+
122+
[AvalonEditHighlightingThemes](https://github.com/Dirkster99/AvalonEditHighlightingThemes) - Implementation of Themes in AvalonEdit.
123+
124+
[SharpDevelop](https://github.com/icsharpcode/SharpDevelop) - An IDE which uses AvalonEdit. I used some of their syntax highlighting definitions. Although I heavily edited them and wrote my own G-Code highlighting.
125+
126+
[Custom Window Title Bar](https://github.com/James231/WPF_CustomWindow_TitleBar) - My own repo letting you customize Windows 10 title bars in WPF, based on a fork of [this](https://github.com/GiGong/WPF_CustomWindow_TitleBar).
127+
128+
[Json.NET](https://www.newtonsoft.com/json) - JSON serializer.
129+
130+
[JsonSubTypes](https://www.newtonsoft.com/json) - JSON SubType implementation for Json.NET.
131+
132+
Obviously credit goes to Microsoft for C#, Razor, WPF, .NET and lots of other stuff.
133+
134+
## License
135+
136+
This code is released under MIT license. Modify, distribute, sell, fork, and use this as much as you like. Both for personal and commercial use. I hold no responsibility if anything goes wrong.
137+
138+
If you use this, you don't need to refer to this repo, or give me any kind of credit but it would be appreciated. At least a :star: would be nice.
139+
140+
## Contributing
141+
142+
Pull Requests are welcome. But, note that by creating a pull request you are giving me permission to merge your code and release it under the MIT license mentioned above. At no point will you be able to withdraw merged code from the repository, or change the license under which it has been made available.

0 commit comments

Comments
 (0)