Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
I change the code example because I need get value from a matrix.
I already got "MatrixResult" from MathCAD but only columns and rows count.
how could I get value from matrix result with JS?
thx in advance!
var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var mathcad = new ActiveXObject("MathcadPrime.Application");
mathcad.Visible = true;
mathcad.Activate();
var worksheet = mathcad.Open(fileSystemObject.BuildPath(dirScript,"xxx.mcdx"));
worksheet.SetTitle("Title from JS Script");
outputs = worksheet.Outputs;
countOutputs = outputs.Count;
firstOutput = outputs.GetAliasByIndex(0);
var val = worksheet.OutputGetMatrixValue(firstOutput);
msg("error code " + val.ErrorCode + val.MatrixResult.Columns);
// here need to be changed!
var element = new ActiveXObject("MathcadPrime.IMathcadPrimeOutputResult");
element = val.MatrixResult.GetMatrixElement(0, 1, element);
msg("value" + element.RealResult)
Solved! Go to Solution.
OK lets go from the beginning.
Mathcad needs an output with an alias. It will also have a count.
matrix is called "here" and it is the second count( 1 as zero based counting).
b is set as an integer with value 1 being the zero based count of outputs.
"hereResult" is defined and set to the output alias "here" the matrix.
The matrix is output
Cheers
Terry
Try this:
// here need to be changed!
let element = 3.14;
element = val.MatrixResult.GetMatrixElement(0, 1, element);
msg("value" + element);
If the above does not work try this:
// here need to be changed!
let double_element = 3.14;
element = val.MatrixResult.GetMatrixElement(0, 1, double_element);
msg("value" + double_element);
actually, not worked.
let double_element = 3.14;
element = val.MatrixResult.GetMatrixElement(0, 1, double_element);
msg("value" + double_element); // The value here has not been changed
OK lets go from the beginning.
Mathcad needs an output with an alias. It will also have a count.
matrix is called "here" and it is the second count( 1 as zero based counting).
b is set as an integer with value 1 being the zero based count of outputs.
"hereResult" is defined and set to the output alias "here" the matrix.
The matrix is output
Cheers
Terry
thanks for your patient.
I understand how to use VB to get the value of a matrix, because there are similar examples in the tutorial.
The problem I actually have is that there is no corresponding statement to run in JavaScript, below.
b = hereResult.MatrixResult.GetMatrixElement(0, 1, bdlhere)
But fortunately, I finally solved the problem of using python. In python, I can clearly understand the type of return value and all the properties and methods it has. I didn't try, but I think JS should have a similar solution.
post my code if someone needed.
import win32com.client
MC = win32com.client.Dispatch("MathcadPrime.Application")
MC.Visible = True
WS = MC.Open("xxxx.mcdx")
p0 = WS.Outputs
b = p0.Count
hereResult = WS.OutputGetMatrixValueAs("out", "")
RowCount = hereResult.MatrixResult.Rows
b = hereResult.MatrixResult.GetMatrixElement(0, 1)
print(b) # <-- here get a tuple with (0, 1) | 0: error code, 1: value