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

PrintScript Plugin


    1  Printing in a File
       1.1  Creating groups
       1.2  Printing properties
    2  Printing in a XML File
    3  Writing any File
    4  Notes

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] .

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: 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).

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

Category: editor Category: plugins Category: user

Copyright 2016 Dassault Aviation. All Rights Reserved. Documentation and source under the GPL v2 licence

Project Web Hosted by SourceForge.net Copyright 1999-2010 - Geeknet, Inc., All Rights Reserved About - Legal - Help