Script Region - Extends SMath Studio with a Script Region (c#, vb.net, python) - Сообщения
#1 Опубликовано: 11 лет назад
Script Region

C# and VB.Net:
Do not use directive "using". You just need to fill function body.
List of specified namespaces (c#, vn.net):
System
System.IO
System.Diagnostics
System.Xml
System.Linq
System.Text
System.Reflection
System.Collections.Generic
System.Globalization
System.Drawing
System.Drawing.Drawing2D
System.Drawing.Imaging
SMath.Manager
SMath.Controls
SMath.Math
SMath.Math.Numeric
List of specified namespaces (python (import * used)):
System
SMath.Manager
SMath.Controls
SMath.Math
SMath.Math.Numeric
Predefined variables available in script (c#, vn.net, python): Store store.
Links:
1. Fast Colored TextBox for Syntax Highlighting (Pavel Torgashov).
2. Runtime-генерирование .Net-кода для тех, кому некогда (Андрей Мартынов).
3. Scripting .NET Applications with IronPython (Jerome Terry).
4. SMath Studio Core documentation (CHM)
Examples:
Script. CurrentDirectory.sm (5 КиБ) скачан 356 раз(а).
Script. CurrentDirectory.pdf (51 КиБ) скачан 424 раз(а).
Script. Show time.sm (4 КиБ) скачан 298 раз(а).
Script. Show time.pdf (42 КиБ) скачан 352 раз(а).
Script. InOut.sm (8 КиБ) скачан 417 раз(а).
Script. InOut.pdf (30 КиБ) скачан 493 раз(а).





C# and VB.Net:
Do not use directive "using". You just need to fill function body.
List of specified namespaces (c#, vn.net):
System
System.IO
System.Diagnostics
System.Xml
System.Linq
System.Text
System.Reflection
System.Collections.Generic
System.Globalization
System.Drawing
System.Drawing.Drawing2D
System.Drawing.Imaging
SMath.Manager
SMath.Controls
SMath.Math
SMath.Math.Numeric
List of specified namespaces (python (import * used)):
System
SMath.Manager
SMath.Controls
SMath.Math
SMath.Math.Numeric
Predefined variables available in script (c#, vn.net, python): Store store.
Links:
1. Fast Colored TextBox for Syntax Highlighting (Pavel Torgashov).
2. Runtime-генерирование .Net-кода для тех, кому некогда (Андрей Мартынов).
3. Scripting .NET Applications with IronPython (Jerome Terry).
4. SMath Studio Core documentation (CHM)
Examples:
Script. CurrentDirectory.sm (5 КиБ) скачан 356 раз(а).
Script. CurrentDirectory.pdf (51 КиБ) скачан 424 раз(а).
Script. Show time.sm (4 КиБ) скачан 298 раз(а).
Script. Show time.pdf (42 КиБ) скачан 352 раз(а).
Script. InOut.sm (8 КиБ) скачан 417 раз(а).
Script. InOut.pdf (30 КиБ) скачан 493 раз(а).
Russia ☭ forever, Viacheslav N. Mezentsev
2 пользователям понравился этот пост
#2 Опубликовано: 11 лет назад
#3 Опубликовано: 11 лет назад
#4 Опубликовано: 11 лет назад
Updated. Small improvements.
EDIT:
Test (c#).

Script:
EDIT:
Test (c#).

Script:
var log = ( Action<string> ) ( ( text ) => store.TraceData(
String.Format( "{0} {1} [INFO ] {2}",
DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(),text ) ) );
var defs = Enumerable.Range( 0, store.Count ).Select( n => store[n] ).ToList();
defs.ForEach( d => log( d.ToString() ) );
Russia ☭ forever, Viacheslav N. Mezentsev
#5 Опубликовано: 9 лет назад
The source code has been restored, updated and uploaded to svn. Something does not work yet (last example). The plugin is not available, because Release Manager can't build it (too complex I think).
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Davide Carpi 9 лет назад
#6 Опубликовано: 9 лет назад
Updated (svn). Now last example works and we are waiting when Andrey fix the Release Manager.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Davide Carpi 9 лет назад
#7 Опубликовано: 9 лет назад
Updated. Now available.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Davide Carpi 9 лет назад
#8 Опубликовано: 9 лет назад
Hi Uni. Admirable work, thanks a lot for this plugin. Just few questions:
- From where plugin's take c#, vb.net and python ¿(i.e. came when plugin is downloaded)?
- ¿Can call nympi or Sci python?
- ¿Can you show how to modify some SMtah's vector or matrix variable? In other words, ¿there are an output, avoiding handling files, to smath worksheet or only can view results in the trace window?
- Not related with your plugin, but ... easy asking you: SMath don't have maple's traperror or mathcad onerror functions?
Have a nice day.
Alvaro.
- From where plugin's take c#, vb.net and python ¿(i.e. came when plugin is downloaded)?
- ¿Can call nympi or Sci python?
- ¿Can you show how to modify some SMtah's vector or matrix variable? In other words, ¿there are an output, avoiding handling files, to smath worksheet or only can view results in the trace window?
- Not related with your plugin, but ... easy asking you: SMath don't have maple's traperror or mathcad onerror functions?
Have a nice day.
Alvaro.
#9 Опубликовано: 9 лет назад
Wrote- From where plugin's take c#, vb.net and python ¿(i.e. came when plugin is downloaded)?
- ¿Can call nympi or Sci python?
- ¿Can you show how to modify some SMtah's vector or matrix variable? In other words, ¿there are an output, avoiding handling files, to smath worksheet or only can view results in the trace window?
c#, vn.net from the .Net Framework which is already installed on your PC.
As for the python I used IronPython which is a part of the plugin.
Not shure about numpi and Sci. I think it is impossible use them now.
You can modify and add definitions to the worksheet dynamically (inside the script). It not so simple to show how you can use this, I need a time to make an example.
Russia ☭ forever, Viacheslav N. Mezentsev
#10 Опубликовано: 9 лет назад
Wrote
c#, vn.net from the .Net Framework which is already installed on your PC.
As for the python I used IronPython which is a part of the plugin.
Not shure about numpi and Sci. I think it is impossible use them now.
You can modify and add definitions to the worksheet dynamically (inside the script). It not so simple to show how you can use this, I need a time to make an example.
Examples (specially regarding Python) would be greatly appreciated!

Tinu
1 пользователям понравился этот пост
Davide Carpi 9 лет назад
#11 Опубликовано: 9 лет назад
Dear all,
I donwloaded @uni's #3 smath file. Tried to understand but it seems more explanation is needed for low level users like me
It would be really perfect having Python scripts running within Smath.
Is there any ongoing effort?
++Ahmet
I donwloaded @uni's #3 smath file. Tried to understand but it seems more explanation is needed for low level users like me

It would be really perfect having Python scripts running within Smath.
Is there any ongoing effort?
++Ahmet
1 пользователям понравился этот пост
frapuano 8 лет назад
#12 Опубликовано: 8 лет назад
Updated. Variable terms added. Some namespaces declared implicit.

Script:

Script:
try
{
string varname = terms[0].Text;
List<Definition> list = new List<Definition>();
for ( int n = 0; n < store.Count; n++ ) list.Add( store[ n ] );
// Функция условия для поиска определения.
Predicate< Definition > cond = delegate( Definition x )
{
// Если имя определения (переменной) равно varname.
return x.Name.Equals( varname );
};
// Метод Find ищет первый элемент, который удовлетворяет условию.
Definition def = list.Find( cond );
// Если элемент найден, то что-нибудь делаем.
store.TraceData( varname + ( def != null ? " " : " not " ) + "found" );
if ( def != null )
{
TMatrix m = new TMatrix( new TNumber[ 2, 3 ] );
m.unit.SetValue( ( TNumber ) new TDouble( "\"name\"" ), new long[] { 0, 0 } );
m.unit.SetValue( ( TNumber ) new TDouble( "\"descr\"" ), new long[] { 0, 1 } );
m.unit.SetValue( ( TNumber ) new TDouble( "\"value\"" ), new long[] { 0, 2 } );
m.unit.SetValue( ( TNumber ) new TDouble( "\"" + def.Name + "\"" ), new long[] { 1, 0 } );
m.unit.SetValue( ( TNumber ) new TDouble( "\"" + def.Description + "\"" ), new long[] { 1, 1 } );
TNumber val = SMath.Math.Numeric.Expression.Calculate( def.Result, store );
m.unit.SetValue( val, new long[] { 1, 2 } );
Definition res = new Definition( "out", m.ToTerms(), new Term[0] );
store.AddDefinition( res );
}
}
catch ( Exception ex )
{
store.TraceData( ex.Message );
}
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
frapuano 8 лет назад
#13 Опубликовано: 8 лет назад
Updated. Fixed some issues related to vb compiler.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
frapuano 8 лет назад
#14 Опубликовано: 8 лет назад
Updated. Examples added.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
frapuano 8 лет назад
#15 Опубликовано: 8 лет назад
Updated. Now more magic available.
![2017-03-04 20-42-28 SMath Studio - [Script. Lambda. Linq.sm].png](/ru-RU/files/Download/RLcvLY/2017-03-04-20-42-28-SMath-Studio---[Script.-Lambda.-Linq.sm].png)
Script:
![2017-03-04 20-42-28 SMath Studio - [Script. Lambda. Linq.sm].png](/ru-RU/files/Download/RLcvLY/2017-03-04-20-42-28-SMath-Studio---[Script.-Lambda.-Linq.sm].png)
Script:
var args = Entry.Create( terms );
var entries = args.Items.ToList().Take(3).Select( x => Decision.Preprocessing( x, store ) ).ToList();
var nums = entries.Select( x => SMath.Math.Numeric.Expression.Calculate( x, store ).obj.ToDouble() ).ToList();
nums.ForEach( n => store.TraceData( n.ToString() ) );
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
frapuano 8 лет назад
#16 Опубликовано: 8 лет назад
Updated. Another attempt to fix the problem related with the portable version. Martin, please try again. Now the tmp directory appears in the plugins directory and you need to remove it content manually periodically. Fix this later.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Martin Kraska 8 лет назад
#17 Опубликовано: 8 лет назад
Now working with the portable version, thanks. With maxima, we had quite some issues with temp dirs (interference between multiple smath instances or documents...
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#18 Опубликовано: 8 лет назад
Add definitions from list of strings. To get a textual representation we use [Ctrl+C], [Ctrl+V].
![2017-03-08 12-08-37 SMath Studio - [Script. Load definitions.sm ].png](/ru-RU/files/Download/eEV8ed/2017-03-08-12-08-37-SMath-Studio---[Script.-Load-definitions.sm-].png)
Script:
![2017-03-08 12-08-37 SMath Studio - [Script. Load definitions.sm ].png](/ru-RU/files/Download/eEV8ed/2017-03-08-12-08-37-SMath-Studio---[Script.-Load-definitions.sm-].png)
Script:
var defs = new List<string>( new[] { "E:m*c^2", "a:1", "b:2" } );
defs.ForEach( d =>
{
var tmp = SMath.Math.Symbolic.Converter.ToMItem(d).ToTerms();
Decision.SymbolicCalculation( Entry.Create( tmp ), store );
} );
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Davide Carpi 8 лет назад
#19 Опубликовано: 8 лет назад
String to matrix (c#).
![2017-03-08 21-31-34 SMath Studio - [Script. String to matrix.sm].png](/ru-RU/files/Download/4eQA65/2017-03-08-21-31-34-SMath-Studio---[Script.-String-to-matrix.sm].png)
Script:
![2017-03-08 21-31-34 SMath Studio - [Script. String to matrix.sm].png](/ru-RU/files/Download/4eQA65/2017-03-08-21-31-34-SMath-Studio---[Script.-String-to-matrix.sm].png)
Script:
// rows - 2, cols - 3.
var text =
@"
1, 1.2, 0.3,
2, 9.5, -12,
2, 3
";
var provider = new NumberFormatInfo() { NumberDecimalSeparator = "." };
var vals = text
.Split( ',' ).Select( s => s.Trim() )
.Select( x => new TDouble( double.Parse( x, provider ) ).ToTerms() )
.Select( x => Entry.Create(x) ).ToList();
var mat = new Entry( "mat", TermType.Function, vals.ToArray() );
store.AddDefinition( "out", new Term[0], mat );
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
frapuano 8 лет назад
#20 Опубликовано: 8 лет назад
-
Новые сообщения
-
Нет новых сообщений