Home
Categories
Dictionary
Download
Project Details
Changes Log
Who We Are
FAQ
License

PrintScript Plugin



PrintScript
Type Editor Scripting printing
Jar File PrintScript.jar
Applies to editor
The PrintScript Plugin is used with the EditorScript Plugin to save content in a text file, XML file, or Excel file[1]
Without the presence of the PrintScript Plugin, the EditorScript Plugin won't be able to save content
.

Printing in a File

It is possible to create a GroupWriter in the ScriptHelper. For example:
      GroupWriter writer = null;
      public void start() {
      writer = helper.createFileWriter("File");
      if (writer == null) {
      context.abort("Aborting");
      }
      }
The framework will ask for a File in which subsequent GroupWriter.print(Object... elements) methods will create new lines in the File. Two File formats are provided for writing: a simple text format, and a XLSX format. Note that it is not necessary to flush and close the content of the File at the end of the Script. This will be performed automatically by the framework at the end of the Script. It is also possible to create more than one ScriptWriter.
Example:
      GroupWriter writer = null;

      public void start() {
      // this first instruction will pop a Dialog which will ask the user for a txt or xlsx file path
      writer = helper.createFileWriter("File");
      if (writer == null) {
      // the writer will be null if the user click on the "Cancel" Button
      context.abort("Aborting");
      }
      }

      public void process(ServerWidget widget) {
      writer.print(widget.getName(), widget.getID());
      }

Creating groups

It is possible to create a GroupWriter from an existing ScriptFileWriter. The result of creating a group depends on the file format:
  • For a text file, it will only create several separation lines
  • For a xlsx file, it will create a new sheet in the workbook
It is possible to print in a group as it is possible in the initial ScriptFileWriter. Note that by default the printing will be performed in the last defined GroupWriter when performed in the ScriptFileWriter.

Printing properties

The GroupWriter.setProperty(String, Object...) method allows to set properties for the GroupWriter or ScriptFileWriter. The available properties depend on the format (properties which are not supported for a format will no perform anything, but will not throw any exception).

  • For text format: the "separator" property allows to set the separator between the elements in the current line. For example:
                setProperty("separator", ";");
    
  • For xlsx format: the "columnWidth" property allows to set the column width for a column. For example:
                setProperty("columnWidth", 1, 10);
    
    or with autoSize:
                setProperty("columnWidth", 1, "autoSize");
    
  • For xlsx format: the "cellStyle" property allows to set the style for a cell. Styles are separated with "+" and are not case-sensitive. For example:
                setProperty("cellStyle", 1, 1, "verticalcenter+center+wrap");
    

Printing in a XML File

It is possible to create an XMLFileWriter in the ScriptHelper. For example the following script will ask for an XML file to the user:
      XMLFileWriter writer = null;

      public void start() {
      // this first instruction will pop a Dialog which will ask the user for the XML file path
      writer = helper.createXMLFileWriter("File");
      if (writer == null) {
      // the writer will be null if the user click on the "Cancel" Button
      context.abort("Aborting");
      }
      }
This writer allows to create an XML hierarchy. As for the other ScriptFileWriters, it is not necessary to flush and close the XML file at the end of the script. It will be performed automatically by the Scripting framework.
The following code creates an XML file with one XML element for each Layer, and one child XML element for each widget in the layer. The XML Layer element will have one attribute for the LayerID. The XML Widget element will have one attribute for the Widget ID.
      XMLFileWriter writer = null;
      XMLNode rootNode = null;
      XMLNode layerNode = null;

      public void start() {
      // this first instruction will pop a Dialog which will ask the user for the XML file path
      writer = helper.createXMLFileWriter("File");
      if (writer == null) {
      context.abort("Aborting");
      }
      // this instruction will create the root node for the XML File
      rootNode = writer.getRootNode("root");
      }

      public void process(ServerLayer layer) {
      layerNode = new XMLNode(layer.getName());
      layerNode.addAttribute("id", layer.getLayerID());
      rootNode.addChild(layerNode);
      }

      public void process(ServerWidget widget) {
      XMLNode widgetNode = new XMLNode(widget.getName());
      widgetNode.addAttribute("id", widget.getID());
      layerNode.addChild(widgetNode);
      }

Writing any File

It is possible to access or create any File, and write anything in its content. For example, the following Script writes a text File with the path of the file:
      import java.io.*;

      BufferedWriter writer = null;
      public void start() {
      File file = helper.getNewFile("Set Text file", "txt");
      BufferedWriter writer = new BufferedWriter(new FileWriter(file));
      writer.write(file.getPath());
      writer.newLine();
      }

      public void end() {
      writer.flush();
      writer.close();
      }

Notes

  1. ^ Without the presence of the PrintScript Plugin, the EditorScript Plugin won't be able to save content

Categories: editor | plugins | user

Copyright 2016-2017 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v2 licence