cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

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

QA_10868748
3-Visitor

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

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)

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

5 REPLIES 5

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

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

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

 

Top Tags