Skip to main content
1-Visitor
January 10, 2012
Question

Method to use the IMathCADWorksheet::SetValue

  • January 10, 2012
  • 1 reply
  • 4077 views

Is there any workaround of using the IMathCADWorksheet::SetValue instead of accessing directly the XML file?

1 reply

1-Visitor
January 10, 2012

Karthik,

The SetValue method does not access the Mathcad XML file. SetValue talks to an executing Mathcad process with a worksheet loaded, whether it is visible or not is developers choice. If you want the SetValue changes saved to the XML file you will need to execute the SaveAs method as well before existing.

John

1-Visitor
January 10, 2012

Thank you John.

But the SetValue method of the Worksheet doesnt change anything in the active worksheet when I tried to execute the method from my C++ application. Is there any other method to the change the value in the mathcad worksheet? If there is any sample application it will be helpful for me.

Karthik

1-Visitor
January 10, 2012

Hi Karthik,

If you are willing to try Richard's method here are some tips. I believe this is the best method, but definitely more work programatically.

As he mentioned you pre-process your worksheet by RMB on the math region of interest and then tag it.

a tag is just a text string you will use to filter regions programatically. Can be as simple as "input1", "input2" etc.

In your code , after you get the interface to the worksheet get the collection of regions of the worksheet interface.

Now loop for all recgions (either stop on NULL region or use regions.count) and search for your region of interest' tag. Some VB.NET code to review.

SW2MC is the tag I am looking for on regions. Value comes from other code snippets , pretend it is the value you are trying to set .. 3.14159.

WS = MC.Worksheets.Open(openFileDialog1.FileName)

MyRegions = WS.Regions

For Each myregion In

If(String.Compare(myregion.Tag, "SW2MC") = 0) Then

If (newstr.Compare(newstr, leftstr) = 0) And ((substring_test) Or (pos = 0))Then
If pos > 0 Then
tmpstr = "<ml:define xmlns:ml=""http://schemas.mathsoft.com/math30""> <ml:id xml:space=""preserve"" subscript="""
tmpstr = tmpstr & rightstr & """" & ">"
tmpstr = tmpstr & newstr
Else
tmpstr = "<ml:define xmlns:ml=""http://schemas.mathsoft.com/math30""> <ml:id xml:space=""preserve"">"
tmpstr = tmpstr & newstr
End If


tmpstr = tmpstr & "</ml:id><ml:real>"
tmpstr = tmpstr & value
tmpstr = tmpstr & "</ml:real></ml:define>"


myregion.MathInterface.XML = tmpstr

End If

End If ' found the right region

Next

Dont get too hung up on the VB.NET string manipulation, bottom line I am formatting a proper XML string according to Mathcad schema. To learn the format open a plane worksheet, type in the region you would like to see as a result. Save the worksheet and open it in Notepad. Now you see what your region's syntax needs to look like.

John