1 страниц (5 вхождений)
Function with optional parameters - Сообщения
#1 Опубликовано: 16.07.2010 10:17:16
How to create a plugin function that accepts multiple parameters. For example:
Es:=29000000 psi
x:=myfunc(a,b,28000000psi,...) ' Here I'm overriding the default with 28000000psi
or
x:=myfunc(a,b,...)
where the default third parameter is Es from SMath sheet and there are other optional parameters following the Es position and "..." means any number of following parameters.
So to the user it could be:
x:=myfunc(a,b )
x:=myfunc(a,b,c,d,e,f,g,h,i,j,k) and so on
You do it with augment(...)
ArgumentsCount puts empty parameter symbols.
By the way. The way I get Es is as follows. Let me know if there is an easier way.
Es:=29000000 psi
x:=myfunc(a,b,28000000psi,...) ' Here I'm overriding the default with 28000000psi
or
x:=myfunc(a,b,...)
where the default third parameter is Es from SMath sheet and there are other optional parameters following the Es position and "..." means any number of following parameters.
So to the user it could be:
x:=myfunc(a,b )
x:=myfunc(a,b,c,d,e,f,g,h,i,j,k) and so on
You do it with augment(...)
ArgumentsCount puts empty parameter symbols.
By the way. The way I get Es is as follows. Let me know if there is an easier way.
Dim e As New Term("Es", TermType.Operand, 0)
arge.Add(e)
arg1 = Decision.Preprocessing(arge.ToArray, store)
Ed
#2 Опубликовано: 16.07.2010 17:36:22
WroteYou do it with augment(...)
I did it also with concat(..) function. Please, check its code to see the logic:
else if (root.Text == "concat"
{
string res = "";
for (int i = 0; i < root.ChildCount; i++)
{
args[i] = Decision.SymbolicCalculation(args[i], ref store);
if (!IsTextTerm(args[i]))
throw new Exception(GlobalParams.StringsErrors[(int)Error.ArgumentMustBeString]);
res += args[i][0].Text.Substring(1, args[i][0].Text.Length - 2);
}
result = new Term[] { new Term("\"" + res + "\"", TermType.Operand, 0) };
}
else if (root.Text == "findstr" && root.ChildCount == 2)
{
WroteThe way I get Es is as follows. Let me know if there is an easier way.
I advise you to discover store object - it is context of current evaluation operation. Check its Shared field to see all information about worksheet definitions.
Regards.
#3 Опубликовано: 16.07.2010 17:45:42
Andrey,
This is good. I hope that we can see more discussion like this on plugin development. I am looking forward to learning from you and others who know alot more than myself.
Sometime in the future, I would suggest that you might want to consider a forum section that would be reserved for discussions about developing plugins. Those threads that have been started already (such as this one) could be moved to that section.
Just a suggestion.
Will
This is good. I hope that we can see more discussion like this on plugin development. I am looking forward to learning from you and others who know alot more than myself.
Sometime in the future, I would suggest that you might want to consider a forum section that would be reserved for discussions about developing plugins. Those threads that have been started already (such as this one) could be moved to that section.
Just a suggestion.
Will
Will Massie
Mechanical Engineer
Oregon, USA
#4 Опубликовано: 16.07.2010 17:52:09
Hello Will. You're absolutely right, it will be good if separate forum section will be created for plugin development related discussions when we will have enough topics about it.
Regards, Andrey Ivashov.
Regards, Andrey Ivashov.
#5 Опубликовано: 16.07.2010 19:54:51
I was concerned about the ArgumentsCount of TermInfo but needlessly.
Public Function ExpressionEvaluation(ByVal root As SMath.Manager.Term, ByVal args()() As SMath.Manager.Term,
ByRef store As SMath.Manager.Store, ByRef result() As SMath.Manager.Term)
As Boolean Implements SMath.Manager.IPluginLowLevelEvaluation.ExpressionEvaluation
Dim i as Integer
If root.Type = TermType.Function And root.Text = "test" Then
For i = args.GetLowerBound(0) To args.GetUpperBound(0)
' Do something with args(i)
Next
' If you run out of input parameters the rest are defaults
Return (True)
End If
Return False
End Function
Ed
1 страниц (5 вхождений)
-
Новые сообщения
-
Нет новых сообщений