MattWoodhead / MathcadPy

A Python wrapper for the Mathcad Prime automation API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Input a matrix

andcoder321 opened this issue · comments

@MattWoodhead How do I input a matrix from Mathcad to Python. I can't get it to work.

Hi @andcoder321.

I will add a matrix example to documentation/Examples, however whilst testing this I noted that there is a mistake in the function to fetch the value of a matrix input that currently raises an exception.
The functions to get matrix results from outputs are unaffected so should still work on the current MathcadPy version.

I will let you know when the example is available and I update MathcadPy for the above bug.

@MattWoodhead thank you, I appreciate it. I use Mathcad about everyday, but it just isn't good at processing large amounts of data (so slow!). I am looking to initialize projects and document calls in MC, then process in python, and then bring it all back. Something like that anyway.
Actually, I stumbled onto Mathcadpy while looking for a way to connect MC to Grasshopper. I've already got that to work which is awesome!

Here is what I am running into when trying to input MC matrices into python. It reads it as NaN which is odd and then when I try to call the value, still NaN. Tried 'get_matrix_input' too but that just errors out. An example would help. I can read Excel filed into python just fine as databases etc.

image
image

Hi @andcoder321.

I have released version 0.4, that should fix the above bug in the get_matrix_input function. Please update and give it a try. I have also added Examples/matrix_example.py and its corresponding Mathcad files (created in version 5.0.0).

Let me know if these work for you.

Thanks for the update @MattWoodhead ! I have updated to 0.4 and get_matrix_input works :).

Now, on to the next question, haha. Is there a 'get_string_input'? Similar to above, I am trying to read a string from MCP into python. Additionally, if there is a method to read a string in, what about a matrix of strings? What about a matrix composed of a mix of strings and numbers with units? I am looking to do all of these operations with a current MCP sheet. Thanks again for your help!

Hi @andcoder321.

For the get_string_input functionality I need to rework some of the wrapper class methods, but you can use the code below to get what you need done in the meantime:

input_result_obj = mathcad_worksheet.ws_object.InputGetValue("input_alias")
if input_result_obj.ResultType == 2:
    input_string = input_result_obj.StringResult
    error_code = input_result_obj.ErrorCode
    assert error_code == 0
    print(input_string)

Unfortuantely, the matrix with a mix of strings an numbers with units does not seam to be compatible with the Mathcad API - See exerpt below from the PTC Prime API help document:

  • All values in the matrix must be of the same dimension. For example, one matrix can contain values in meters and feet – different units of length, but cannot contain meters and kilograms – units of length and weight. If the values do not have units of same dimension, such as, inches and seconds, the function returns an error.
  • You can use values without units. In this case, all values in the matrix must be unitless.
  • Strings are not supported.

Ok, thank you for the update @MattWoodhead.
That is too bad that MCP does not support a matrix of strings or mixed units in their API. I'll have to work around that somehow.
Thanks again!