-
Notifications
You must be signed in to change notification settings - Fork 0
/
Raw VBA.txt
34 lines (25 loc) · 1.18 KB
/
Raw VBA.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'If you would rather create from scratch, paste this code into a new spreadsheet. Your spreadsheet should have target Zlayers listed in Column A (starting on row 2) and have the same decimal precision as what is found in your gCode. Column B should have the corresponding extruder temp. The code runs through the gCode looking for instances of matching Z layers, and inserts a new line adding the target extruder temp.
Sub UpdateTempsinGcode()
Dim sBuf As String
Dim sTemp As String
Dim iFileNum As Integer
Dim sFileName As String
'Select gCode file
sFileName = Application.GetOpenFilename()
iFileNum = FreeFile
Open sFileName For Input As iFileNum
Do Until EOF(iFileNum)
Line Input #iFileNum, sBuf
sTemp = sTemp & sBuf & vbCrLf
Loop
Close iFileNum
'Update this part if your slicer handles temp changes differently
lastlayer = ActiveWorkbook.Worksheets("Sheet1").Range("A1").End(xlDown).Row
For I = 2 To lastlayer
sTemp = Replace(sTemp, "G1 Z" & Cells(I, 1).Value, "M104 S" & Cells(I, 2).Value & Chr(13) & Chr(10) & "G1 Z" & Cells(I, 1).Value)
Next I
iFileNum = FreeFile
Open sFileName For Output As iFileNum
Print #iFileNum, sTemp
Close iFileNum
End Sub