Create a super block through a script

classic Classic list List threaded Threaded
8 messages Options
Yves Rambi Yves Rambi
Reply | Threaded
Open this post in threaded view
|

Create a super block through a script

Hello to all,
I am new in this forum and I use sometimes scicos.

Now I'd like to create a script which creates a custom block in Scicos. The structural information are read from an excel file. In the m-language there are two commands new_system(...) and add_block(...) in order to perform this task and there are also commands to create ports, links between the blocks etc.... Which are the corresponding commands for Scilab?

Here is my m-code:

***************************************
clc
clear;
[num, txt] = xlsread('TCS.xls');
dim = size(txt);
laenge = dim(1,1);
breite = dim (1,2);
System_Name = 'SYS2';
Subsys_Name ='';
PathFlag = '<<Path>>';
InPortFlag = '<<In>>';
OutPortFlag = '<<Out>>';

%POSITION
sys_blk_left = 10;
sys_blk_top = 10;
sys_blk_width = 100;
sys_blk_height = 100;
sys_blk_right = sys_blk_left +  sys_blk_width;
sys_blk_bottom = sys_blk_top +  sys_blk_height;

inp_blk_left = 100;
inp_blk_top = 10;
inp_blk_width = 20;
inp_blk_height = 10;
inp_blk_right = inp_blk_left +  inp_blk_width;
inp_blk_bottom = inp_blk_top +  inp_blk_height;

Dist_InPort_OutPort = 1000;
out_blk_left = inp_blk_left + Dist_InPort_OutPort;
out_blk_top = 10;
out_blk_width = 20;
out_blk_height = 10;
out_blk_right = out_blk_left +  out_blk_width;
out_blk_bottom = out_blk_top +  out_blk_height;



%CREATE AND OPEN SYSTEM
new_system(System_Name);
open_system(System_Name);

inter_row=0;
inter_block = 0;
i=1;
block_nr =0;

dim_port_name(1) = 5;
while i<laenge
    ColumnText = txt{i,1};
   
    if strcmp( ColumnText ,PathFlag) == 1
        block_nr = block_nr +1;
        Subsys_Name = txt{i,2};      
        dim = size(Subsys_Name);        
        dim = dim(1,2);
        Subsys_Name(dim)='';
        <b>add_block('built-in/SubSystem',Subsys_Name);
        sys_blk_top = sys_blk_bottom + 10;
        sys_blk_bottom = sys_blk_top +  sys_blk_height;
        sys_blk_right= sys_blk_left + 2*5* max(dim_port_name);
       
        %PLACE AND SIZE BLOCK
        if ~isempty(Subsys_Name)
            set_param(Subsys_Name,'Position',[sys_blk_left sys_blk_top sys_blk_right sys_blk_bottom]);
        end
        inp_blk_left = 10;
        inp_blk_top = 10;
        out_blk_left = 10;
        out_blk_top = 10;
    elseif strcmp( ColumnText ,InPortFlag) == 1
        inp_blk_left = 10;
        inp_blk_top = inp_blk_top + 50;
        inp_blk_right = inp_blk_left +  inp_blk_width;
        inp_blk_bottom = inp_blk_top +  inp_blk_height;
        Subsys_InPort = strcat(Subsys_Name,'/',txt{i,2});
        siz_port_name = size(txt{i,2});
        dim_port_name(i) = siz_port_name (1,2);
        add_block('built-in/Inport',Subsys_InPort);
        set_param(Subsys_InPort,'Position',[inp_blk_left inp_blk_top inp_blk_right inp_blk_bottom]);
        sys_blk_bottom = sys_blk_bottom + 5;
        old_dim_port_name = dim_port_name;
    elseif strcmp( ColumnText ,OutPortFlag) == 1
        out_blk_left = inp_blk_left + Dist_InPort_OutPort;
        out_blk_top = out_blk_top + 50;
        out_blk_right = out_blk_left +  out_blk_width;
        out_blk_bottom = out_blk_top +  out_blk_height;
        Subsys_OutPort = strcat(Subsys_Name,'/',txt{i,2});
        siz_port_name = size(txt{i,2});
        dim_port_name(i) = siz_port_name (1,2);
        add_block('built-in/Outport',Subsys_OutPort);
        set_param(Subsys_OutPort,'Position',[out_blk_left out_blk_top out_blk_right out_blk_bottom]);
        sys_blk_bottom = sys_blk_bottom + 5;
    end
    i=i+1;
   
end
****************************************

Thank you in advance.


Yves
Clément David-2 Clément David-2
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

Hello Yves and welcome,

Yep, it is possible to instantiate a diagram using the functions :

 * scicos_diagram()
 * scicos_block()
 * scicos_link()

to add a block simply append the block (here named `blkX`) to the list
of children of a diagram (here named `scs_m`):

```
scs_m = scicos_diagram();
blk1 = scicos_block();
// or instantiate a block
blk2 = BIGSOM_f("define");

scs_m.objs($+1) = blk1;
scs_m.objs($+1) = blk2;
```

Everything is documented on scilab help pages and to check do not
hesitate to use `xcos(scs_m)` to watch the resulting diagram. You can
also draw a template diagram on xcos and then export it to Scilab
(using the diagram browser).

Regards,

--
Clément

Le jeudi 17 septembre 2015 à 05:15 -0700, Yves Rambi a écrit :

> Hello to all,
> I am new in this forum and I use sometimes scicos.
>
> Now I'd like to create a script which creates a custom block in
> Scicos. The
> structural information are read from an excel file. In the m-language
> there
> are two commands new_system(...) and add_block(...) in order to
> perform this
> task and there are also commands to create ports, links between the
> blocks
> etc.... Which are the corresponding commands for Scilab?
>
> Here is my m-code:
>
> ***************************************
> clc
> clear;
> [num, txt] = xlsread('TCS.xls');
> dim = size(txt);
> laenge = dim(1,1);
> breite = dim (1,2);
> System_Name = 'SYS2';
> Subsys_Name ='';
> PathFlag = '<<Path>>';
> InPortFlag = '<<In>>';
> OutPortFlag = '<<Out>>';
>
> %POSITION
> sys_blk_left = 10;
> sys_blk_top = 10;
> sys_blk_width = 100;
> sys_blk_height = 100;
> sys_blk_right = sys_blk_left +  sys_blk_width;
> sys_blk_bottom = sys_blk_top +  sys_blk_height;
>
> inp_blk_left = 100;
> inp_blk_top = 10;
> inp_blk_width = 20;
> inp_blk_height = 10;
> inp_blk_right = inp_blk_left +  inp_blk_width;
> inp_blk_bottom = inp_blk_top +  inp_blk_height;
>
> Dist_InPort_OutPort = 1000;
> out_blk_left = inp_blk_left + Dist_InPort_OutPort;
> out_blk_top = 10;
> out_blk_width = 20;
> out_blk_height = 10;
> out_blk_right = out_blk_left +  out_blk_width;
> out_blk_bottom = out_blk_top +  out_blk_height;
>
>
>
> %CREATE AND OPEN SYSTEM
> *new_system*(System_Name);
> open_system(System_Name);
>
> inter_row=0;
> inter_block = 0;
> i=1;
> block_nr =0;
>
> dim_port_name(1) = 5;
> while i<laenge
>     ColumnText = txt{i,1};
>    
>     if strcmp( ColumnText ,PathFlag) == 1
>         block_nr = block_nr +1;
>         Subsys_Name = txt{i,2};      
>         dim = size(Subsys_Name);        
>         dim = dim(1,2);
>         Subsys_Name(dim)='';
>         &lt;b>add_block*('built-in/SubSystem',Subsys_Name);
>         sys_blk_top = sys_blk_bottom + 10;
>         sys_blk_bottom = sys_blk_top +  sys_blk_height;
>         sys_blk_right= sys_blk_left + 2*5* max(dim_port_name);
>        
>         %PLACE AND SIZE BLOCK
>         if ~isempty(Subsys_Name)
>             set_param(Subsys_Name,'Position',[sys_blk_left
> sys_blk_top
> sys_blk_right sys_blk_bottom]);
>         end
>         inp_blk_left = 10;
>         inp_blk_top = 10;
>         out_blk_left = 10;
>         out_blk_top = 10;
>     elseif strcmp( ColumnText ,InPortFlag) == 1
>         inp_blk_left = 10;
>         inp_blk_top = inp_blk_top + 50;
>         inp_blk_right = inp_blk_left +  inp_blk_width;
>         inp_blk_bottom = inp_blk_top +  inp_blk_height;
>         Subsys_InPort = strcat(Subsys_Name,'/',txt{i,2});
>         siz_port_name = size(txt{i,2});
>         dim_port_name(i) = siz_port_name (1,2);
>         add_block('built-in/Inport',Subsys_InPort);
>         set_param(Subsys_InPort,'Position',[inp_blk_left inp_blk_top
> inp_blk_right inp_blk_bottom]);
>         sys_blk_bottom = sys_blk_bottom + 5;
>         old_dim_port_name = dim_port_name;
>     elseif strcmp( ColumnText ,OutPortFlag) == 1
>         out_blk_left = inp_blk_left + Dist_InPort_OutPort;
>         out_blk_top = out_blk_top + 50;
>         out_blk_right = out_blk_left +  out_blk_width;
>         out_blk_bottom = out_blk_top +  out_blk_height;
>         Subsys_OutPort = strcat(Subsys_Name,'/',txt{i,2});
>         siz_port_name = size(txt{i,2});
>         dim_port_name(i) = siz_port_name (1,2);
>         add_block('built-in/Outport',Subsys_OutPort);
>         set_param(Subsys_OutPort,'Position',[out_blk_left out_blk_top
> out_blk_right out_blk_bottom]);
>         sys_blk_bottom = sys_blk_bottom + 5;
>     end
>     i=i+1;
>    
> end
> ****************************************
>
> Thank you in advance.
>
>
> Yves
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Create-a
> -super-block-through-a-script-tp4032849.html
> Sent from the Scilab users - Mailing Lists Archives mailing list
> archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Yves Rambi Yves Rambi
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

Many thanks Clément. I will have try right now.
Yves Rambi Yves Rambi
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

In reply to this post by Clément David-2
Hello Clément,
I have tried it. But it is really not obvious to me how to use e.g "scicos_block" (graphics, model, etc...). Even the help didn't give me further information. Even by looking at the .sci file I couldn't get it.

Is there some example code how to create a custom block with inputs, outputs, connections?


Thank you

Yves
Yves Rambi Yves Rambi
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

In reply to this post by Clément David-2
Hello Clément,
it works. I don't know why but yesterday I didn't see the small square (the system) that has been created in the Scicos model.

Thank you
Yves Rambi Yves Rambi
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

In reply to this post by Clément David-2
Hello Clément,
it's really not so easy to begin with writing sce scripts.

So I could finally after hours of research and trials partly understand how this scripting works.

Here is my code:

**********************
scs_m = scicos_diagram();
scs_m.props.title = "Test_Superblock";

//SUM-Block
//scs_m.objs(1) = SUMMATION("define");
//scs_m.objs(1).graphics.sz = [30 50];


//super block
scs_m.objs(1) = SUPER_f("define");
scs_m.objs(1).graphics.sz = [200 200];

//create one additional input
scs_m.objs(1).model.rpar.objs(3)= IN_f("define")

//define input-structure
scs_m.objs(1).model.in = [2;-1]
scs_m.objs(1).model.in2 = [1;-2]
scs_m.objs(1).model.intyp = [2;-1]



xcos(scs_m)

**********************

I have some questions:
- what are the vectors in[2; -1] and in2[1; -2] ? I write it just "instinctively" by looking at the diagram browser.
- is there not another simplier way to create inputs in a kind of one command like "create_input"?
- is my code correct or did I forget something?

By the way I don't know how to export a model to the "diagram browser". When I open it I see a tree structure. From there I deduced how to create sub-model-elements. But I don't know if my code is complete or if there are some additional things necessary.

If I could get some example code from somewhere it would help me a lot.


Thank you



Yves
Clément David-2 Clément David-2
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

Hello Yves, hello all,

Yep in fact this is not trivial and we try to improve that for Scilab6
(such as automatic definitions of port properties).

> I have some questions:> - what are the vectors in[2; -1] and in2[1;
-2] ? I write it just> "instinctively" by looking at the diagram
browser.> - is there not another simplier way to create inputs in a
kind of one> command like "create_input"?> - is my code correct or did
I forget something?>

Your code seems correct. The model.in and model.in2 let the user
specify the size of the inputs.

> By the way I don't know how to export a model to the "diagram
> browser". When> I open it I see a tree structure. From there I
deduced how to create> sub-model-elements. But I don't know if my code
is complete or if
> there are> some additional things necessary.

Opening the diagram browser push an 'scs_m' variable into Scilab and
you can then access its fields.

Regards,

--
Clément
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Yves Rambi Yves Rambi
Reply | Threaded
Open this post in threaded view
|

Re: Create a super block through a script

In reply to this post by Yves Rambi
Dear all,
after a Long break I tried to go on with this Topic.

So my Intention was to create a superblock with 3 Inputs and one Input. But
each time I try to run the script nothing appears. By the second run of the
script the console hangs and I have to kill the Task WScilex.

So no superblock appears for Scicos. Here is the code:

----------------
scs_m = scicos_diagram();
scs_m.props.title = "Test_Superblock";

//super block
scs_m.objs(1) = SUPER_f("define");
scs_m.objs(1).graphics.sz = [200 200];

//create one additional input
scs_m.objs(1).model.rpar.objs(4)= IN_f("define")

//define input-structure
//scs_m.objs(1).model.in = [2;-1;-1]
//scs_m.objs(1).model.in2 = [1;-2;-2]
//scs_m.objs(1).model.intyp = [2;-1;-1]

scs_m.objs(1).model.in = [1;1;1]
scs_m.objs(1).model.in2 = [2;2;2]
scs_m.objs(1).model.intyp = [1;1;1]

scs_m.objs(1).model.out =1
scs_m.objs(1).model.out2 =1
scs_m.objs(1).model.outtyp =1

xcos(scs_m)

-------------------------

What is wrong with my script?


Best Regards

Yves



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users