Proektsoftbg / Calcpad

Free and open source software for mathematical and engineering calculations.
https://calcpad.eu
MIT License
321 stars 39 forks source link

Passing variables into cli #189

Closed Grefron closed 8 months ago

Grefron commented 9 months ago

Hi,

Is there a way to pass in variables when calling cli.exe to export to a pdf or word file, when the input cpd file contains a question mark 'placeholder'?

Something like defining the values in a json or yaml file (of which the name is than passed into cli.exe through a command line argument) would be very helpful in automating the generation process.

Example pdn: a=? {10} m

example json to go along: {'a':4}

Thanks!

Proektsoftbg commented 9 months ago

Currently not in this way. But you can easily replace a=? {x} with a=? {y} in the file by using regex.

Grefron commented 9 months ago

This was my workaround at the moment. Just not very good with regexes (who is?) so always a little afraid the endresult may be corrupted. Therefore I thought a more directly supported way of doing this would be beneficial.

Grefron commented 8 months ago

For anyone interested, I opted to generate the input files using Python, with the jinja2 template engine, which works nicely for me.

Still struggling a bit with getting the results from my calculations back. Some way of exporting key-value pairs of variables would be awesome.

Proektsoftbg commented 8 months ago

Check out this idea about calling Calcpad from Python as a library: https://github.com/Proektsoftbg/Calcpad/issues/188#issuecomment-1719265127

We can create a simple wrapper around Calcpad that can pass input, set variables, get output, read variables, etc. I do not think that using a console app in command line mode is the most appropriate way to do these things.

Proektsoftbg commented 8 months ago

We made significant improcement to Cli in command mode:

  1. It now supports includes and macros.
  2. Also, support for old style cpd files (see explanations bellow).
  3. Option for silent mode by adding -s at the end. With this, it will not open the output file automatically when finished.

In the older versions, all input values are added subsequently and the end of the file, after a vertical tab ASCII Code 11. Almost all examples are still in this format: https://github.com/Proektsoftbg/Calcpad/blob/main/Examples/Mathematics/Cubic%20Equation.cpd

It works even if there are inline input values, like x = ? {2}. So, this could be an easier way to pass different values to Cli in command mode, without searching throughout the whole file. Just search for a vertical tab '\v', take the entire text before it and add the input vaues after it. If there is no vertical tab, just add it with the values after it.

https://github.com/Proektsoftbg/Calcpad/blob/main/Setup/calcpad-setup-en-x64.exe