1 страниц (14 вхождений)
Return constant from plugin - Return a constant value from inside a plugin - Сообщения
#1 Опубликовано: 20.09.2021 13:35:14
Hello all,
I'm new to SMath Studio, and I'm developing a plugin in VB.NET. I need to define a constant given from my code (for example, I want to type in "const=" and get an hardcoded value).
I saw that TermType can be Operand, Operator, Function or Bracket. I defined my constant as a function, and in this way I always have to type const(1) to get the value (i.e. I must use a dummy argument, which is not needed).
Do you have any hint on that? Can I defined a constant in a plugin?
thanks in advance
I'm new to SMath Studio, and I'm developing a plugin in VB.NET. I need to define a constant given from my code (for example, I want to type in "const=" and get an hardcoded value).
I saw that TermType can be Operand, Operator, Function or Bracket. I defined my constant as a function, and in this way I always have to type const(1) to get the value (i.e. I must use a dummy argument, which is not needed).
Do you have any hint on that? Can I defined a constant in a plugin?
thanks in advance
#2 Опубликовано: 20.09.2021 13:40:30
As I know it is not possible. All plugin stuff (if they are not regions) registered as functions. But I've never tried registering an operand instead of a function.
I tried. You can register the operand, but an error occurs when you try to calculate it numerically.
I tried. You can register the operand, but an error occurs when you try to calculate it numerically.
Russia ☭ forever, Viacheslav N. Mezentsev
#3 Опубликовано: 20.09.2021 14:03:28
Thans for replying
It seems I cannot also use system paths as a function arguments; I suspect there's something about encoding: I have myfunc("C:\test.txt") and inside plugin code I get "C\003A\\test\002E\txt"
002E is "." in UTF8, but there's also escape chars.
It seems I cannot also use system paths as a function arguments; I suspect there's something about encoding: I have myfunc("C:\test.txt") and inside plugin code I get "C\003A\\test\002E\txt"
002E is "." in UTF8, but there's also escape chars.
#4 Опубликовано: 20.09.2021 14:06:49
You must use TermsConverter.DecodeText() and TermsConverter.EncodeText() for this. Examples can be found in the repository.
Russia ☭ forever, Viacheslav N. Mezentsev
#5 Опубликовано: 20.09.2021 15:50:43
Thanks a lot. Final question: can a function return a boolean?
#6 Опубликовано: 20.09.2021 16:33:08
The program supports operations with numbers presented in various forms (natural, integer, rational, complex). There is no such type as boolean numbers. There are boolean operations defined on the above types. Therefore, there are numbers and operations on them, strings and operations on them, matrices and operations on them. The type of a variable is determined by its value. In symbolic form, you can return any expression allowed by the program syntax.
Therefore, if you need to return a boolean value from a plugin, then it needs to be converted to a value supported in API (see TNumber constructors). Usually, true - 1, false - 0.
Therefore, if you need to return a boolean value from a plugin, then it needs to be converted to a value supported in API (see TNumber constructors). Usually, true - 1, false - 0.
Russia ☭ forever, Viacheslav N. Mezentsev
#7 Опубликовано: 21.09.2021 11:25:19
Thanks, hence it would be easier to put result in an expression with a boolean operator and then return result.
I'm just wondering how to return vectors, I cannot understand from Core Documentation how to return a vector as a result. I suppose one can use some thing like: result = New Entry(New Numeric.TMatrix(... ? ))
and using 1 column only.
can you help on this?
thanks in advance
EDIT:
I did it like this - now the question is: is there a shorter way?
I'm just wondering how to return vectors, I cannot understand from Core Documentation how to return a vector as a result. I suppose one can use some thing like: result = New Entry(New Numeric.TMatrix(... ? ))
and using 1 column only.
can you help on this?
thanks in advance
EDIT:
I did it like this - now the question is: is there a shorter way?
Dim val() As Double = {1,2,3,4,5,6}
Dim m(5, 0) As Numeric.TNumber
For i = 0 To 5
m(i, 0) = New Numeric.TNumber(val(i))
Next
Dim mout As New Numeric.TMatrix(m)
result = Entry.Create(mout.ToTerms)
#8 Опубликовано: 21.09.2021 15:06:30
You can find examples in repository. Try to search in *.cs files using keyword TMatrix. And then convert to the equivalent on vb.net.
Russia ☭ forever, Viacheslav N. Mezentsev
#9 Опубликовано: 21.09.2021 15:49:52
I already saw that page, thanks. Don't know if it's for vb instead of c#, but I cannot have "result = solution" since this conversion is not permitted.
Now I'm looking how to associate units (eg. N, m or MPa, etc.) for result - I didn't find any code sample for this (I thought this https://smath.info:8443/!/#public/view/head/plugins/CustomFunctions/SMathFunctions/Units/UoM.cs was ok, but I cannot understand how units are associated to result). In my case, units are not inherited from function arguments.
Now I'm looking how to associate units (eg. N, m or MPa, etc.) for result - I didn't find any code sample for this (I thought this https://smath.info:8443/!/#public/view/head/plugins/CustomFunctions/SMathFunctions/Units/UoM.cs was ok, but I cannot understand how units are associated to result). In my case, units are not inherited from function arguments.
#10 Опубликовано: 21.09.2021 17:30:37
WroteI cannot understand how units are associated to result
Associate unit compatible to functional operand
as exemplified ... integration is m² km² ...
Page12 Unit_Bolean.sm (13 КиБ) скачан 35 раз(а).
#11 Опубликовано: 21.09.2021 17:37:52
WroteAssociate unit compatible to functional operand
as exemplified ... integration is m² km² ...
Page12 Unit_Bolean.sm (13 КиБ) скачан 35 раз(а).
The questions are about source code of a plugin.
Not about how to write boolean expressions in SMath.
This post is not related with topic.
If you don't get what is asked, don't answer it.
#12 Опубликовано: 21.09.2021 18:08:23
For example you can add units using TDouble. To determine the unit, you need to add an apostrophe in front of the text. For TryEvaluateExpression() you can use other methods (classes).
Public Class Plugin
Implements IPluginMathNumericEvaluation
Private _terms As TermInfo()
Private _description As Dictionary(Of String, String) = New Dictionary(Of String, String) From {
{"ENG", "test function."},
{"RUS", "функция тестирования."}
}
Public Function GetTermsHandled(sessionProfile As SessionProfile) As TermInfo() Implements IPluginHandleEvaluation.GetTermsHandled
Return _terms
End Function
Public Sub Initialize() Implements IPlugin.Initialize
_terms = {New TermInfo("test", TermType.[Function], _description("ENG"
, FunctionSections.Unknown, True) }
End Sub
Public Function NumericEvaluation(value As Term, args As TNumber(), ByRef result As TNumber) As Boolean Implements IPluginMathNumericEvaluation.NumericEvaluation
result = args(0) * ( new TDouble("'sec"
)
Return True
End Function
Public Sub Dispose() Implements IDisposable.Dispose
End Sub
End Class
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
johnnyontheweb 22.09.2021 03:57:00
#13 Опубликовано: 12.10.2021 04:38:19
Hello,
I looked in the code by I cannot find something similar to what I'm trying to do with my plugin.
A power of a length unit has to be returned as measure, but this is not working:
New TNumber(area * New TDouble("'m^2" ) )
What am I missing? It seems that "^" operand is considered in a different way when typed in SMath Studio and when coming from a plugin.
I looked in the code by I cannot find something similar to what I'm trying to do with my plugin.
A power of a length unit has to be returned as measure, but this is not working:
New TNumber(area * New TDouble("'m^2" ) )
What am I missing? It seems that "^" operand is considered in a different way when typed in SMath Studio and when coming from a plugin.
#14 Опубликовано: 13.10.2021 07:26:17
I found an alternative, please tell if there's something shorter than this:
New TNumber(area * DirectCast(New TDouble("'m" ).Pow(New TDouble(2) ), TDouble))
New TNumber(area * DirectCast(New TDouble("'m" ).Pow(New TDouble(2) ), TDouble))
1 страниц (14 вхождений)
-
Новые сообщения
-
Нет новых сообщений