Look at what indentation this code snippet from typescript gives. Typescript:
// only for testing
builder.ifCondition("myVar")
builder.localVariable("resultVar", "1")
builder.elseIfCondition("yourVar")
builder.localVariable("resultVar", "2")
builder.end()
When i view the resulting code in the script view of my robot(simulation) it appears like this:
if (myVar):
local resultVar = 1
elif (yourVar):
local resultVar = 2
end
Why is the indentation off? I expected the ‘elif’ line to be at the same indentation level as the ‘if’ line.
The same thing happens on else statements:
if (bolltecDCTrackTimer < 10 ):
set_standard_digital_out(5, False)
else:
set_standard_digital_out(5, True)
end
Also everything uses double space indentation. I prefer tabs, which is irrelevant i suppose, but more importantly it is inconsistent with the default code in the script file:
def ur_get_joint_speeds_before_offset(previous_q, time):
local current_q = get_joint_positions()
local delta_q = current_q - previous_q
return delta_q / time
end
I just use writer.appendLine() for every single command I have the CAP write. I can have a different editor format it or whatever and then I just slap the syntax on at the beginning.
That is actually a great idea, and probably what I should have done from the start. You would even have proper linting and stuff if you could move your whole URscript program into a separate file. You would just need a way to read the file and, as you say, slap the syntax on at the beginning.
Pretty sure I lifted this code straight from one of the sample UR CAPs. It reads the script from the file and injects it as writer.append calls. Just run it from the generate script method. Pretty nice because VSCode has a URScript option, so you still get syntax highlighting and such. Use “#” to comment out any lines you don’t want added to the script.