Insert ; or \n in text?

#1

In the following code, I need a ; after the “M83”. But when I put a ; there, it gets transformed into a newline and the code is messed up.

How do I do this?

Also, how do I paste code here and keep the indentation?

"
import math
def BuildLines(Layers, zLift, extrusionWidth):
	gcode=[]
	for i in range(len(Layers)):
		gcode.append('layer')
		gcode.append('G1 Z%f' % (Layers[i][0][0].Z))
 		for j in range(len(Layers[i])):
 			gcode.append('spline')
 			gcode.append('M83 relative extrusion')
            ......some irrelevant code removed.......

	return gcode

OUT=BuildLines(IN[0], IN[1], IN[2]);
";
0 Likes

#2

Like this :slight_smile:

0 Likes

#4

You have to put an escape in the code or use a string node to force the code to know you want a string. Post a screenshot of your dyn and/or the graph or a paired down version of it and we can help more.

0 Likes

#5

I got it to work with a string node.

What would be the syntax of an escape? ‘\n’ inserts a newline in the code itself, not as a string.

0 Likes

#6

Are you in Python or a code block?

0 Likes

#7

Well…

A code block that I input to a “Python Script From String” node. Maybe there’s a smarter way?

0 Likes

#8

0 Likes

#9

Ah! I see where the confusion lies.

For this type of exercise you are likely better off using a string node instead of a code block, as the special characters are likely going to cause you significant grief otherwise.

You can use a single \ character to escape them, and actually using a return in the quotes will usually serve as a new line as long as the quotes are placed right, though the formatting goes out the window in a very frustrating way when you do this.

See this post for more info on the escape character usage:

http://dynamobim.org/forums/topic/escape-characters/

Other alternatives are to use a Python node directly, or stick to using designscript directly in the code block and sidestep the Python. I believe that the functions (square root and arctangwnt) from the module you are importing (math) both can be called via designscript in Dynamo. Use node to code function if you get stuck.

0 Likes

#10

I tried with a string node, but with a fixed width of 20ish characters, that’s horrible :slight_smile:
I made it work with a true Python Script node, and everything is much easier :smile: :

Thank you for the help.

0 Likes

#11

Glad to hear you’re on track again! :smiley:

0 Likes

#12

FUI, I am generating the gcode to 3D print a house :grin:

Gcode is the language that the 3D printer reads.


3 Likes

#13

That is awesome! Jaw dropping cool tech there, and a great example of putting Dynamo to use outside of the normal parameter setting and form generation stuff we see every day here on the forums.

Is the design/layout/whatnot done in Revit, Sketchup, Rhino, CAD, straight Python & Dynamo, or is input/design source somewhat irrelevant? I’m really interested in the data flow across the design process.

Hope you will be able to share more as you go along so that others can be inspired to push the tech to that level as well.

0 Likes

#14

The design was done in Rhino by our Architect, Ana Goidea. The data flow is interesting, because we were unable to communicate the shape of the foundation to foundation people, so we ended up having to 3D print the foundation too. We talked about laser cutting a template from tarpaulin as a reference, but it was unsure if we could be sure that it would match the 3d print. (the walls will be printed directly on top of the foundation).
Also, to show the electricians exactly where the wires were supposed to come out of the floor, we used the printer to mark the spots.
Now it will be interesting to see if we were right, or if the wires and water etc. is conflicting with one of the walls.

We plan to finish the print in 10 days.

1 Like

#15

Code block nodes don’t work well with non DesignScript syntax. As you’re already aware, It’s a bit easier with Python syntax , because we can use to define a string literal and that way we don’t have to escape our encapsulating quotes every single time. For semicolons, you’ll just need to reference them once and then you could insert them into your strings using one of python’s many string combination methods:

Unfortunately, we don’t have the same luxury with other languages and will need to escape the inner quotes all the time. As an added headache, the colors of the resulting CBN add further to the user’s confusion:

2 Likes