Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hi all,
I'm still learning how to use API for Mathcad and I have a few questions about this function, SetRealValue.
1) why doesn't the code below work? I mean there are obviously no error, but it doesn't do what I want. In the selected worksheet has x:=2, I was trying to get this x:=2 to be x:=3m. This code below doesn't change anything in this sheet.
Sub test01()
Dim WS As Ptc_MathcadPrime_Automation.Worksheet
Dim App As Ptc_MathcadPrime_Automation.Application
Dim FileName
Set App = New Ptc_MathcadPrime_Automation.Application
FileName = Application.GetOpenFilename(MultiSelect:=False)
Set WS = App.Open(FileName)
Call WS.SetRealValue(x, 3, "m")
End Sub
2), why are there so many functions with the same name reappear in a few different classes? are they doing the same thing? If not, what are the differences? For examples, this SetRealValue occurs in three differences classes: IMathcadPrimeWorksheet, IMathcadPrimeWorksheet2, and Worksheet.
3) The input format for this function is variable name as string, value as double, and unit as string. What if I want to assign string as the value, can I still use this function as just assign string? or there are other functions for that?
Add 4). What happens if I have a variable defined multiple times throughout the sheet? Let say I have x:=.... in page 1 and x:=... in page2 and x:=... in page10. Which one of these will be changed? Is there a way to specify which of these x:= I want to change?
For example:
Page1
x:= 1
y:= x+1 = 2
Page2
x:= 2
y:= x+1 = 3
Page10
x:= 5
y:= x+1 = 6
which of these xs will be affected by this SetRealValue?
Thank you very much!
Solved! Go to Solution.
Hi,
Happy to see 1) and 3) solved.
If you have more than one input defined for "x" the alias that you can use to differentiate between them will automatically be different.
I
If you want to do matrices enclosed is an example.
Cheers
Terry.
Hi,
Can you please include the worksheet and the code.
Cheers
Terry
I think I have the code block included in the main post, may I ask what is it you're seeing between 1) and 2)?
For 1), the worksheet literally have nothing other than x:=2. I was just trying to mess around see if there are any changes.
For 4), I don't have a worksheet for this just yet, but for example:
Page1
x:= 1
y:= x+1 = 2
Page2
x:= 2
y:= x+1 = 3
Page10
x:= 5
y:= x+1 = 6
Please let me know if you want me to clarify any other points.
Thank you!
Hi,
Asked to see the worksheet to see if input or output had been assigned.
To change the value of an item and its units in VBA/Prime value needs to be set as an Input parameter in the worksheet.
Highlight x:=2
Assign Input will no longer be greyed out.
Press it and a small blue box with "in" title will be visible every time you highlight x=2.
Use Show as list button to show the defined inputs and outputs.
In Prime
Cheers
Terry
So, I highlighted, hit "Assign Inputs". Ran the script above again and nothing change, still.
I can't access the attached file though, only have up to Prime7.0 Sorry
Hi,
Will do something up in Prime 7 give me some time.
What language are you using to program in?
Cheers
Terry
Thank you very much!
Currently using VBA(preferably), but I can also read Python and Matlab.
Hi,
Happy to see 1) and 3) solved.
If you have more than one input defined for "x" the alias that you can use to differentiate between them will automatically be different.
I
If you want to do matrices enclosed is an example.
Cheers
Terry.
Hi terryhendicott,
Thank you very much. At the moment, I was able to get 1) and 3) solved. However, I'm sstill looking for a solution for 4). I tried repeating the SetRealValue twice to make change to the 2nd value but still couldn't get that solve.
wow. thank you very much! I really appreciate this!!!!