Skip to main content
3-Newcomer
November 23, 2023
Solved

How could I get a value from a matrix with js?

  • November 23, 2023
  • 1 reply
  • 2040 views

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)

 

 

 

 

 

 

Best answer by terryhendicott

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).

Capture.JPG

b is set as an integer with value 1 being the zero based count of outputs.

Capture2.JPG

"hereResult" is defined and set to the output alias "here" the matrix.

Capture3.JPG

The matrix is output

Capture4.jpg

Cheers

Terry

1 reply

21-Topaz II
November 25, 2023

Try this:

 

// here need to be changed!
let element = 3.14;
element = val.MatrixResult.GetMatrixElement(0, 1, element);
msg("value" + element);

 

21-Topaz II
November 26, 2023

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);

 

 

3-Newcomer
November 27, 2023

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