Difference between revisions of "Execute a script"

From Proview Wiki
Jump to: navigation, search
Line 6: Line 6:
 
Using pwrc (wb_cmd) command : wb_cmd -v MyRootVolumeName @config_from_excel<br /><br />
 
Using pwrc (wb_cmd) command : wb_cmd -v MyRootVolumeName @config_from_excel<br /><br />
  
Example:  
+
'''Example csv file: (config_from_excel.csv) '''
 +
<nowiki>
 +
 
 +
! Start with "wb_cmd -v volvfssx3 @config_from_excel"
 +
!
 +
! The .csv file should look like this
 +
!
 +
! Signalname              Class  Signal description       
 +
! =====================  ====== =====================
 +
! VFS-SX3-LM-AS13-KlippTK; Di    ;TK SAX 3 KLIPP +AS13  BL.21
 +
!
 +
! Hint, set a comment on "save" on the bottom row the first time to check that
 +
! everything works.
 +
!
 +
 
 +
!
 +
! Create an object and it's ancestors if they doesn't exist
 +
!
 +
function int  create_object( string name, string class)
 +
  int i;
 +
  int j;
 +
  string parent;
 +
  string object;
 +
  int sts;
 +
 
 +
  i = strrchr( name, "-");
 +
  if ( i)
 +
    i++;
 +
    j = i - 2;
 +
    parent = extract( 1, j, name);
 +
    object = extract( i, 80, name);
 +
  else
 +
    object = name;
 +
    parent = "";
 +
  endif
 +
  if ( !ObjectExist( name))
 +
    if ( parent != "")
 +
      create_object( parent, class);
 +
    endif
 +
    create object/dest="'parent'"/class='class'/name="'object'"
 +
  endif
 +
endfunction
 +
 
 +
 
 +
main()
 +
!
 +
!              Name of the file to read
 +
  string filename = "test.csv";
 +
!
 +
  int file;
 +
  string        str;
 +
  string name_str;
 +
  string class_str;
 +
  string descr_str;
 +
 
 +
  !verify(1);
 +
  file = fopen( filename, "r");
 +
  if ( !file)
 +
    printf( "Unable to open %s\n", filename);
 +
    exit();
 +
  endif
 +
 
 +
  while ( fgets( str, file))
 +
    if ( extract( 1, 1, str) == "!")
 +
      continue;
 +
    endif
 +
    name_str = felement( 1, ";");
 +
    if ( strlen( name_str) == 0)
 +
      continue;
 +
    endif
 +
    name_str = edit( name_str);
 +
    class_str = felement( 2, ";");
 +
    class_str = edit( class_str);
 +
    descr_str = felement( 3, ";");
 +
    printf( "Processing signal: %s\n", name_str);
 +
 
 +
    create_object( name_str, class_str);
 +
    set attr/noco/name='name_str'/attr=Description/value="'descr_str'"
 +
  endwhile
 +
  fclose( file);
 +
!  save
 +
endmain
 +
</nowiki>
 +
 
 +
<br \>
 +
<br \>
 +
 
  
 
You can read about scripts in the Script chapter in Designer's Guide.
 
You can read about scripts in the Script chapter in Designer's Guide.

Revision as of 04:37, 24 August 2013

In Proview you can use scripts to read csv files and create both the signal, card, channel objects and to connect them.
This can be handy to create the signals in the database so it is not necessary to create them one bye one with the editor.

A script-file can be executed from the command-line with the command:

wtt> @'filename'
Or
Using pwrc (wb_cmd) command : wb_cmd -v MyRootVolumeName @config_from_excel

Example csv file: (config_from_excel.csv)


! Start with "wb_cmd -v volvfssx3 @config_from_excel"
!
! The .csv file should look like this
!
! Signalname              Class   Signal description         
! =====================   ====== =====================
! VFS-SX3-LM-AS13-KlippTK; Di    ;TK SAX 3 KLIPP +AS13  BL.21
!
! Hint, set a comment on "save" on the bottom row the first time to check that
! everything works.
! 

!
! Create an object and it's ancestors if they doesn't exist
!
function int  create_object( string name, string class)
  int	 i;
  int	 j;
  string parent;
  string object;
  int	 sts;

  i = strrchr( name, "-");
  if ( i)
    i++;
    j = i - 2;
    parent = extract( 1, j, name);
    object = extract( i, 80, name);
  else
    object = name;
    parent = "";
  endif
  if ( !ObjectExist( name))
    if ( parent != "")
      create_object( parent, class);
    endif
    create object/dest="'parent'"/class='class'/name="'object'"
  endif
endfunction


main()
!
!               Name of the file to read
  string	filename = "test.csv";
!
  int 		file;
  string        str;
  string 	name_str;
  string 	class_str;
  string 	descr_str;

  !verify(1);
  file = fopen( filename, "r");
  if ( !file)
    printf( "Unable to open %s\n", filename);
    exit();
  endif

  while ( fgets( str, file))
    if ( extract( 1, 1, str) == "!")
      continue;
    endif
    name_str = felement( 1, ";");
    if ( strlen( name_str) == 0)
      continue;
    endif
    name_str = edit( name_str);
    class_str = felement( 2, ";");
    class_str = edit( class_str);
    descr_str = felement( 3, ";");
    printf( "Processing signal: %s\n", name_str);

    create_object( name_str, class_str);
    set attr/noco/name='name_str'/attr=Description/value="'descr_str'"
  endwhile
  fclose( file);
!  save 
endmain




You can read about scripts in the Script chapter in Designer's Guide.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox