I have a text file below that I use to parameterize numerical simulations. I’d like to be able to change the values in the red box below from the data I put in an Excel file.
However, I’m encountering two problems :
1st problem: Transforming “V_xmin” into the value “0” is fairly straightforward using the “String Replace” module, but it requires the template to be used each time a value is changed. The line starts each time with xmin. Do you know if it’s possible to delete the entire line content and replace it with “xmin 0”?
2nd problem: Once I’ve modified the values, when I want to rewrite the file, I use the CSV Writer module, but for lines 27+, a certain organization of the lines is required (with precise tabulations), which is not respected. In reality, only lines 17-25 need to be modified. Is it possible to rewrite only these lines?
This could probably be something for which you can use the new Handlebars templating node in plain “Text” mode. Put the template and add tags for the variable parts, generate the string, and write it out to a file:
You can even do this for multiple rows, respectively files, in one go.
Hi, thank you for your proposition, unfortunatly I met some difficulties with these two new nodes as there are no exemples associated. Here is my workflow :
With the handlebars, I end up with a result column with all the same values and when I save this as files with the StringCell To File node, I end up with multiple files with the name of the row as file name :
thanks for giving it a try and for providing your current workflow. You’ll find my working modifications below. I realize that there’s a good example workflow missing at the moment - this is on me.
To the explanation:
You’ll need to put the template with the placeholders in the the node’s configuration “Template” field.
Variables to be used in the template can be passed via Flow Variable and / or via JSON column.
To access a variable value called e.g. xmin from the JSON data in the template, use e.g. {{ data.xmin }} (in case it is supplied via flow variable, use {{ variables.flowVariableName }}
(advanced) You can use Handlebars syntax, such as loops, conditions, string helpers, etc.
The updated workflow is available on my public NodePit Space: