Automation Studio API and Scripting Language Guide
Automation Studio API and Scripting Language Guide
User’s Guide
Famic Technologies Inc.
REPRODUCTION
ii
Table of Contents
5.5.3 Primary Object ......................................................................................... 5-9
5.5.4 Register Scripts to be launched ................................................................ 5-9
5.5.5 Example ................................................................................................. 5-11
5.5.6 Remove Event Registration ................................................................... 5-12
5.5.7 Function Calls from a Script .................................................................. 5-12
6 .NET Environment ........................................................................................................ 6-1
6.1 Introduction ........................................................................................................... 6-1
6.2 General Setup ........................................................................................................ 6-1
6.3 Launch a .NET Method ......................................................................................... 6-1
6.3.1 Method Syntax ......................................................................................... 6-1
6.3.2 Loading Client Functionality ................................................................... 6-3
6.3.3 Command Line to Call a User’s Method ................................................. 6-4
6.3.4 Startup call to User Extendibility............................................................. 6-4
6.3.5 User Variable HYPERLINK ................................................................... 6-4
6.3.6 Hyperlink User Method Launch .............................................................. 6-4
6.3.7 Hooks ....................................................................................................... 6-5
6.3.8 Events ...................................................................................................... 6-5
6.4 User’s Runtime Environment ................................................................................ 6-5
6.4.1 Object Identification ................................................................................ 6-5
6.4.2 Accessing Automation Studio™ Interface Objects ................................. 6-6
6.4.3 Register Scripts or Methods to be Launched ......................................... 6-10
6.4.4 Sequence of Events ................................................................................ 6-12
6.4.5 Remove Event Registration ................................................................... 6-13
6.4.6 Automation Studio™ User ............................................................... 6-13
6.4.7 User Automation Studio™ ............................................................... 6-14
6.5 User’s Runtime Environment .............................................................................. 6-15
6.5.1 Dynamically Load User’s .NET DLL .................................................... 6-15
6.5.2 ApplicationClientApi ............................................................................. 6-15
6.5.3 Additional Event Responding Objects ................................................... 6-15
6.5.4 Accessing Automation Studio™ Interface Objects ............................... 6-16
6.5.5 Application Object ................................................................................. 6-16
7 API Reference Manual .................................................................................................. 7-1
7.1 Available Interfaces ............................................................................................... 7-1
7.1.1 Objects Affected ...................................................................................... 7-1
7.1.2 Unique Identifiers .................................................................................... 7-2
7.1.3 Definitions ............................................................................................... 7-3
7.1.4 General Methods (Base) .......................................................................... 7-6
7.2 Node .................................................................................................................... 7-36
7.2.1 The Node Object.................................................................................... 7-36
iv
1 Introduction
Automation Studio™ provides a methodology that allows a third party developer to hook
scripts into Automation Studio™’s normal process flow with access to Automation
Studio™’s object model. This allows users to implement their own functionality from
within Automation Studio™ that can automate different tasks routinely applied by
overriding or creating new functionality, hence changing the way Automation Studio™
normally functions. To do this, Automation Studio™ comes with the following:
API: Application Programming Interface that provides an interface to AS’s runtime and
data module.
This document describes how Automation Studio™ Extensibility can be used to add
functionality to Automation Studio™. The technologies used in both implementations
(Scripting and .NET) are not controlled by Famic Technologies therefore Famic
Technologies cannot assume responsibility for them.
Chapter 3 Getting Started Writing Scripts: Provides a number of examples that allows a
developer to quickly start using scripts without having to concern themselves with
Automation Studio™’s data model.
Chapter 4 Static and Runtime Model Overview: Overview of Automation Studio™ data and
runtime model.
Chapter 7 API Reference Manual: Reference manual of all the available functionality
provided.
Appendix B: IronRuby Syntax: A simple version of the available syntax provided by the
programming scripting language IronRuby.
1-2
2 Overview of Automation Studio™ Extensibility
2.1 Purpose
Automation Studio™ allows users to run their own programmatic control that affects the
runtime behavior and data of Automation Studio™. This is called Automation Studio™
extensibility. This is an extremely powerful way of supporting user’s every expanding
need to interface with additional systems or change the behavior of Automation Studio™.
The Automation Studio™ extensibility system opens up its environment and allows every
expanding functionality.
If an important need is identified that fits the API provided, it can be addressed directly
by the user and implemented using the extensibility system. Functionality that a user
wants to keep protected would never have to leave his environment. When new releases
of Automation Studio™ are provided these processes would work as before, like any data
kept by a user but this data would have functionality.
This interface is a great way for a third party to add functionality that would only be
applied by him, even things like manipulating current contents of projects as a data
preparation process. It generally opens up the general model on how things can behave.
The extensibility system allows a third party to manipulate Automation Studio™ runtime
data model and process flow using the following two methods:
A scripting language
.NET Interface
A basic knowledge of .NET is required to use this environment. This document will not be
covering this, for this is well documented by Microsoft.
For the scripting environment, Automation Studio™ loads an IronRuby interpreter that is
used to translate and run the scripts written. IronRuby is one of the easiest languages to
use. The examples supplied within this document should be sufficient to get one started
writing IronRuby scripts. IronRuby is also well documented by third party content
providers. These third party content providers should be referenced in order to access
support or solve IronRuby problems.
The Automation Studio™ Scripting environment is the simple version of applying third
party functionality to Automation Studio™. This scripting language only requires a text
editor to create and deploy scripts that access Automation Studio™’s runtime data and
processing model. This environment provides most of expected methodologies required
to do this type of work.
With such a language, a client can access Automation Studio™’s runtime and data model
and implement normal scripting methods like looping, assignments and conditional
expressions. An example would allow him to write a script that could redirect the file
open operation to access files from a specific version control system.
2.2.1 Advantages
The script writer will only be required to know the scripting language that interfaces with
Automation Studio™ and the API command language described within this document. The
language provided is a very intuitive language that does not require any difficult
programming concepts.
The language provided supports access to the .NET environment from within the scripts.
2.2.2 Disadvantages
The script is interpreted every time the event occurs, affecting performance. For most
2-2
Overview of Automation Studio™ Extensibility
object events, this will not be an issue since they do not occur often, but if this type of
extensibility is used on objects like primitives that occur hundreds of times within a
display, it may affect the performance of the display.
This interface will offer .NET programmers a rich complex development environment that
can access Automation Studio™ ’s runtime and processing model.
Here the code does get compiled so significant performance improvements can be
expected over the Automation Studio™ scripting language method of client extensibility.
With a .NET based language, a client could build an entire interface on top of Automation
Studio™.
Advantages
This will be significantly faster than the pure Automation Studio™ scripting
method;
The users will be able to extend the Automation Studio™’s existing interface;
Disadvantages
The API is the interface that is available to a user from within his .NET methods or the AS
scripting environment. This API provides the user access to the runtime and data model
of Automation Studio™.
This API consists of methods that can be applied to many objects within Automation
Studio™. These objects can be of type, general application, to individual projects,
documents, views, components, and catalogues to name a few. Methods are also
supplied within this API that allow a user to navigate between different objects within
Automation Studio™’s object model.
2-4
3 Getting Started Writing Scripts
This chapter will demonstrate a number of simple scripts using the Automation Studio™’s
scripting environment that can be easy installed and used. These scripts should provide a
simple overview of writing scripts without having to know very much about the
Automation Studio™’s Model.
Through this section, the scripts will be expected in the directory Scripts found in the
user’s application data folder. This will be referenced as the scripts quick start directory:
Windows XP:
C:\Documents and Settings\<User>\Application Data\Famic
Technologies\Automation Studio\Scripts
Automation Studio™ is hardcoded to search this folder for scripts (see section 5.2.2 Search
Path for Scripts). If you were to place your scripts in a different folder, you have to define
the folder to be a scripts directory by setting the Automation Studio™ application variable
in the “Application Options dialog”.
You can access this dialog by selecting the AS menu, and the “Automation Studio™
Options” button.
3. You can add more than one search paths, if you separate them with semicolons.
IronRuby does not come with Automation Studio™ therefore, it has to be installed to be
used. If IronRuby does not exist on the targeted system, it can be installed from the
3-2
Getting Started Writing Scripts
http://ironruby.codeplex.com/downloads/get/217152
You must have system administrator rights, read and accept the appropriate agreements,
and following the IronRuby install instructions in order to install IronRuby. The above
install version is the one that is commonly used within Famic Technologies.
When the IronRuby installer prompts you for the features to be installed, make sure you
select at least the IronRuby main directory. Tools for Visual Studio are also useful if you
are using VS to edit your Ruby files.
Automation Studio™ must be restarted for the new version of IronRuby to be found and
used. If Automation Studio™ was started through a shell, that shell also has to be closed.
When Automation Studio™ runs its first script, it will locate IronRuby in the path defined
These install paths can be verified by opening the “Environment Variables” dialog in
Windows. This is done in the following way: Open up the “Control Panel” “System and
Security” “System” and then launch the “Advanced system settings”. This procedure is
a little different under different versions of windows.
The “System Properties” dialog will be launched. Select the advanced settings and then
press the “Environment Variables” button.
The “Environment Variables” dialog will be launched. In the “System Variable” section,
scroll down until you see the IRONRUBY_<version> variable. This value will contain
3-4
Getting Started Writing Scripts
After that, the path statement will also contain a path to the IronRuby’s installation.
This path will be used if an unknown version of IronRuby has been installed. This allows
Automation Studio™, if more than one version of IronRuby exists, to select a preference.
The uninstallation generally does a good job but for a number of reasons, it is possible
that the environment has not been properly reset. If this happens, the system
environment variable path must have IronRuby removed from it and the
IRONRUBY_<version> variable be deleted.
The scripts can be written using any text editor if international support is not required.
If the scripts are required to support non-ASCII based languages, they must be saved in
UTF8 format. This format is supported by most code editors, but you generally will have
to set the encoding properly.
3-6
Getting Started Writing Scripts
NotePad++ is a good example of a code editor that supports many languages and
provides the syntax coloring rules to simplify the writing of Ruby scripts. IronRuby is a
.NET version of Ruby so any code editor that provides coloring rules for Ruby will work
very nicely. The NotePad++ application is provided by Don HO and can be accessed from
the following link:
The following image is an example of (1) how to set (2) or convert the encoding of a file
currently being edited by NotePad++ to use the UTF8 file format, with or without the byte
order mark (BOM), either will do.
This first example will demonstrate the basic concepts that a script requires to work. This
example will load the project C:\ASExamples\A.prx and start the image simulating.
You can change the name of the file and/or the directory, but you will have to be
Create a text file with the name IRScriptA.rb and place it into the scripts quick start
directory:
#------------------------------------------------------------
# Name of File::IRScriptA.rb
#
# Purpose::
# Loads a project and starts it simulating.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.LoadProject( "C:\\ASExamples\\A.prx" );
applicationApi.StartSimulation();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
#------------------------------------------------------------
Any line that starts with “#” is ignored. This is how to comment IronRuby scripts.
require "AS.API.Share";
This command loads the DLL or script indicated. In this case, it will find the
AS.API.Share.dll assembly in the Automation Studio™ repository.
This is the general public interface to Automation Studio™ that is available to the current
user.
You must not include any other DLL’s from the Automation Studio™ repository.
Application Api;
This is a global constant that points to the interface supplied by Automation Studio™. This
3-8
Getting Started Writing Scripts
applicationApi.LoadProject ( "C:\\ASExamples\\A.prx" );
This is the first example of calling a method from the Automation Studio™’s application
interface. Access to the application is done through the object applicationApi. This
loads the project indicated by the parameter, into Automation Studio™.
Note in the example the two backslashes “\\” indicating directory delimiters, this
is due to the fact that this current example was saved in pure ASCII format and a
single backslash is considered a special character.
Application Api.StartSimulation();
The method StartSimulation places the currently loaded project into simulation
mode.
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING.
This indicates to Automation Studio™ to continue normal processing of the event that
triggered the call to the script after the script is complete. If this script returned
ASAPI_RETURNS.RETURN_FROM_PROCESSING, this would ignore regular processing
of the event. This way, a script builder could create a script that would bypass how
Automation Studio™ handles the open project event replacing it with his own
functionality.
This example will show the general structure of a C# interface that is used to access
Automation Studio™. This shows how to call a method that will open a project and start it
simulating. For any additional examples, just add the new methods to this structure. In
general, only IronRuby examples will be provided through the rest of the document.
//************************************************************
//
// Nom fichier : ClientCSharp.cs
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AS.API.Share;
namespace AS.API.Client
{
class ClientCSharp : IBaseClientApi
{
//-------------------------------------------------------
// This will keep track of the entry point to AS
//-------------------------------------------------------
IApplicationApi appApi;
//-------------------------------------------------------
// This is the first test method
//-------------------------------------------------------
public int IRScriptA() {
appApi.LoadProject("A.prx");
appApi.StartSimulation();
return(AS.API.Share.ASAPI_RETURNS.NORMAL_PROCESSING);
}
//-------------------------------------------------------
// Later in this document additional examples will be
// inserted here.
//-------------------------------------------------------
// ..
// ..
//-------------------------------------------------------
//-------------------------------------------------------
3-10
Getting Started Writing Scripts
// Required method, reproduce as is.
//-------------------------------------------------------
public new void GetBinding(out long testValue) {
testValue = 0;
return;
}
//------------------------------------------------------
// Required method, reproduce as is, the script writer
// may want to keep the other entry points if provided
// by the event.
// ------------------------------------------------------
public bool SetParent(IApplicationApi app,
IProjectApi prj,
IDocumentApi doc,
IBaseApi bb)
{
appApi = app;
return (true);
}
}
}
Any line that starts with “//” is ignored. This is how to comment C# scripts.
using AS.API.Share;
This command provides access to the namespace indicated. The required DLL has
to have been included as a reference to the project.
You must not include any other DLL’s from the Automation Studio™ repository.
appApi.LoadProject("A.prx");
This is the first example of calling a method from the Automation Studio™’s
application interface. Access to the application is done through the object
provided when SetParent() is called. This loads the project indicated by the
parameter, into Automation Studio™.
appApp.StartSimulation();
return(AS.API.Share.ASAPI_RETURNS.NORMAL_PROCESSING);
This example will show the general structure of a VB.NET interface that is used to access
Automation Studio™. This also shows how to call a method that will open a project and
start it simulating. For any additional examples, just add the new methods to this
structure. In general, only IronRuby examples will be provided through the rest of the
document.
'------------------------------------------------------------
' IRScriptA.vb
'
' Purpose::
3-12
Getting Started Writing Scripts
' Loads a project and starts it simulating.
'------------------------------------------------------------
Imports System.Windows.Forms
Imports [AS].API.Share
'---------------------------------------------------------
' This will keep track of the entry point to AS
'---------------------------------------------------------
Private apiApp As Share.IapplicationApi
'---------------------------------------------------------
' This is the first test method
'---------------------------------------------------------
Public Function IRScriptA() As Integer
apiApp.LoadProject("A.prx")
apiApp.StartSimulation()
Return
([AS].API.Share.ASAPI_RETURNS.NORMAL_PROCESSING)
End Function
'---------------------------------------------------------
' Required method, reproduce as is.
'---------------------------------------------------------
Public Sub GetBinding(ByRef testValue As Long)
Implements Share.IBaseClientApi.GetBinding
testValue = 0
End Sub
'---------------------------------------------------------
' Required method, reproduce as is, the script writter may
' want to keep the other entry points.
'---------------------------------------------------------
Public Function SetParent(ByVal app As
Share.IApplicationApi, _
ByVal prj As Share.IProjectApi,
_
ByVal doc As Share.IDocumentApi,
_
ByVal baseApi As Share.IBaseApi)
_
Any line that starts with “'” is ignored. This is how to comment VB.NET scripts.
Imports [AS].API.Share
This command provides access to the namespace indicated. The required DLL has
to have been included as a reference to the project.
Share.IApplicationApi
apiApp.LoadProject("A.prx")
This is the first example of calling a method from the Automation Studio™’s
application interface. Access to the application is done through the object
provided when SetParent() is called. This loads the project indicated by the
parameter, into Automation Studio™.
apiApp.StartSimulation();
3-14
Getting Started Writing Scripts
Return ([AS].API.Share.ASAPI_RETURNS.NORMAL_PROCESSING)
The most universal way to launch a script from Automation Studio™ is to attach it to any
component within a document. The following process will demonstrate this approach.
1. Start Automation Studio™, when the environment has loaded, objects can be
added;
2. Add a component object into the current document like a rectangle or library
component;
5. In the “Add Variable” dialog, select HYPERLINK for the “Select variable type”;
6. Add to the “Edit variable name” field the name you want to use. It must be
unique on the object;
7. To fill in the script to run information, make sure the “Details” section of the
dialog is displayed (click on “Show Details” at the bottom). Select the user
defined variable you just added and add to the “Value” field a script or method
call string. Then, add a appropriate name in the “Alias” field and finally select
the “Is displayed in tooltip” option;
3-16
Getting Started Writing Scripts
9. In the “View” tab of the ribbon, enable the option “Component Tooltip”;
10. The script can now be launched by a left mouse click on the tooltip. For the
related script IRScriptA.rb to work, a project with the name
C:\\ASExamples\\A.prx must exist.
The easiest way to launch a script from Automation Studio™ is to attach it to a graphical
object within a document. This is what this example will show:
1. Start Automation Studio™. When the environment has loaded, objects can be
added;
3-18
Getting Started Writing Scripts
5. Depending whether you work with a script or a method, fill the “destination”
field with:
OR
METHOD:AS.API.Client::ApplicationClientApi::IRScriptA
The path to the file will be relative to the different script search paths that exist.
This relative path name cannot include “..”. This is done to limit where a user can
load scripts from.
7. Pressing CTRL + Left-click over the primitive with the script hyperlink will start the
script;
9. Now you can stop the image from simulating and proceed with the next step.
3-20
Getting Started Writing Scripts
#------------------------------------------------------------
# File::IRScriptB.rb
#
# Purpose::
# This example will show how to register a script to
# the open project event and add a tab, group and
# buttons to the ribbon system.
#------------------------------------------------------------
require "AS.API.Share"
iconFile = api.FindFileFromScriptSearchPaths(
"ico\\mycustom2.ico");
api.RegisterEvent(asEvent.OPEN_FILE,
asProcessType.SCRIPT,
asMode.SYNC,
"OpenFile.rb");
api.AddRibbonCommandUsingDisplayName("Extended","Ruby",
"User Dialog",
"IRScriptC.rb",
iconFile);
api.AddRibbonCommandUsingDisplayName("Extended","Ruby",
"Export",
"IRScriptD.rb",
iconFile);
asEvent = AS::API::Share::ASAPI_EVENTS
iconFile = api.FindFileFromScriptSearchPaths(
"ico\\mycustom2.ico");
This uses the AS options script search paths to find files that are required by the
script writer.
api.RegisterEvent(asEvent.OPEN_FILE,
asProcessType.SCRIPT,
asMode.SYNC,
"OpenFile.rb");
This registers the script OpenFile.rb to the open file event within Automation
StudioTM, therefore this script will be called just before the open file dialog is
supplied to the user, when the user selects the open file command.
api.AddRibbonCommandUsingDisplayName("Extended","Ruby",
"Export",
"IRScriptD.rb",
iconFile);
These two commands add the “Extended” tab to Automation Studio™’s ribbon
bar. This tab will contain the “Ruby” group with buttons “User Dialog” and
“Export”. When one of these buttons is selected, the script IRScriptC.rb or
3-22
Getting Started Writing Scripts
Only the actual methods required will be shown here. See section 3.3.2 First C# Example
Script for the structure of the module AS.API.Client and the class ClientCSharp.
Add the following method to the ClientCSharp class provided above.
//------------------------------------------------------------
//------------------------------------------------------------
// Name of File:: C# version of IRScriptB
//
// This is the second C# test. This example will show how
// to register a C# method to the open project event and add
// a tab, group and buttons to the ribbon system.
// -----------------------------------------------------------
-
public int IRScriptB()
{
appApi.RegisterEvent(ASAPI_EVENTS.OPEN_FILE,
ASAPI_PROCESS_TYPE.CSHARP,
ASAPI_PROCESS_MODE.SYNC,
"AS.API.Client.OpenFile");
System.String iconFile
=
appApi.FindFileFromScriptSearchPaths("ico\\mycustom2.ico");
appApi.AddRibbonCommandUsingDisplayName("Extended","C
Sharp",
"User Dialog",
"AS.API.Client::ClientCSharp::IRScriptC",
iconFile);
appApi.AddRibbonCommandUsingDisplayName("Extended","C
Sharp",
"Export",
"AS.API.Client::ClientCSharp::IRScriptD",
iconFile);
appApi.SetRibbonPanelVisibilityUsingDisplayName("Extended",
return (ASAPI_RETURNS.NORMAL_PROCESSING);
}
The variable appApi is the script writer’s access point to Automation Studio™’s object
model.
Only the actual methods required will be shown here. See 3.3.3 Visual Basic .NET
Example Script (VB.NET) for the structure of the module AS.API.Client and the class
ClientVB. Add the following method ClientVB class provided above.
'------------------------------------------------------------
'-------------------------------------------------------------
'- Name of File:: VB version of IRScriptB
'-
'- This is the second VB test. This example will show how
'- to register a VB method to the open project event and add
'- a tab, group and buttons to the ribbon system.
'- -----------------------------------------------------------
-
Public Function IRScriptB() As Integer
apiApp.RegisterEvent(ASAPI_EVENTS.OPEN_FILE, _
ASAPI_PROCESS_TYPE.CSHARP, _
ASAPI_PROCESS_MODE.SYNC, _
"AS.API.Client.OpenFile")
apiApp.AddRibbonCommandUsingDisplayName("Extended", "Visual
Basic", _
"User Dialog", _
"AS.API.ClientVb::ClientVB::IRScriptC", _
"mycustom2.ico")
apiApp.AddRibbonCommandUsingDisplayName("Extended", "Visual
Basic", _
3-24
Getting Started Writing Scripts
"Export", _
"AS.API.ClientVb::ClientVB::IRScriptD", _
"mycustom2.ico")
Return ([AS].API.Share.ASAPI_RETURNS.NORMAL_PROCESSING)
End Function
The variable apiApp is the script writer’s access point to Automation Studio™’s object
model.
The Automation Studio™ options “Startup Script” sets what Ruby script or .NET method is
called as Automation Studio™ is launched. This script or method should be used to setup
(register) the scripting environment that will augment the runtime version of Automation
Studio™. To run a script or method every time Automation Studio™ starts, just go to the
“Automation Studio Options” dialog, and fill the “Startup Script” field.
When AS is launched the file IRScript.rb will be loaded and run from the directory
defined in one of the “Scripts Location” fields. The script will add to Automation Studio™’s
ribbon bar an additional tab called “Extended” with a group “Ruby” and two commands
“User Dialog” and “Export”. These buttons will be used to test the following examples.
The Application Options dialog contains the option “Display Internal Variable Names in a
Tooltip”:
3-26
Getting Started Writing Scripts
This option, when enabled, sets Automation Studio™ into a mode where internal names
of many variables will be provided in a tooltip.
The above figure shows a tooltip for the variable “Maximum Differential Pressure” of a
“Fixed Displacement Pump – Hydraulic” component. Here the last line indicates the
internal name of that variable that should be used in scripts.
Third party assemblies can be used directly by a script builder. Once the assemblies are
loaded, the public information (namespaces, classes, methods etc...) can be used. In the
following example we use System::Windows::Forms object to create a message
box.
The script uses the Windows registry to find assemblies so it is good practice to include
the public key related to the assembly that has to be loaded.
return
#------------------------------------------------------------
The above line supplies the required information in order to use the
System.dll provided by Windows. If you do not know the version or public
key of a particular DLL, it can be found by using the Assembly Cache viewer
within Windows Explorer. To find the information required to load your
assemblies, simply browsing %windir%\assembly\ (for example,
C:\WINDOWS\assembly) displays assemblies culture and key information
registered with the system.
The second method is to include any missing paths to the DLLs in the
environment variable LOAD_PATH. DLL’s that are loaded in this fashion do not
3-28
Getting Started Writing Scripts
have to be signed.
"
Figure 3-22: Configure where DLL’s can be found.
System::Windows::Forms::MessageBox.
MessageBox.Show("Mail sent");
return (ASAPI_RETURNS.NORMAL_PROCESSING);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AS.API.Share;
using System.Windows.Forms;
Any assembles used need to be accessed using the using command and added as a
reference to the module.
To access a public class supplied by an assembly, the developer needs only to supply the
class name if the namespace is provided using the using command.
'---------------------------------------------------------
---
' Name of File::IRScriptC.rb
'
' Purpose::
' Generate an users dialog box. Notice that if a Ruby
' file does not access elements from Automation Studio’s
' model the script does not require AS.API.Share or the
' return value.
'---------------------------------------------------------
---
Public Function IRScriptC() As Integer
System.Windows.Forms.MessageBox.Show("User Dialog
Box")
Return
([AS].API.Share.ASAPI_RETURNS.NORMAL_PROCESSING)
3-30
Getting Started Writing Scripts
End Function
Imports System
Imports System.Windows.Forms
To access a public class supplied by an assembly, the developer needs to supply the
entire namespace path to the class. In the above example, a MessageBox object is
accessed using the namespace System.Windows.Forms.MessageBox. Notice each
namespace is separated by periods“.”.
In IronRuby a function must be defined before it is used. Here is the required syntax:
The following example will show how to create and call functions from IronRuby:
#------------------------------------------------------------
# Name of File::IRScriptD.rb
#
# Purpose::
# This search for all projects currently loaded and export
# them to the following file formats.
# pdf, dxf, svg, and tiff
#------------------------------------------------------------
require "AS.API.Share"
ObjDoc = AS::API::Share::ASAPI_OBJ.DOCUMENT_API;
ObjPrj = AS::API::Share::ASAPI_OBJ.PROJECT_API;
#------------------------------------------------------------
# FlagDocumentsToBeExported( IProjectApi prj)
# Loop through all documents found in the current
# Set each document’s export flag
# Parameters::
# IProjectApi prj Project to be searched
#------------------------------------------------------------
def FlagDocumentsToBeExported(prj)
iCnt2 = prj.GetChildCount(ObjDoc);
j = 0
until j == iCnt2
doc = prj.GetNthChild(j,ObjDoc);
doc.SetToBeExported(true);
j += 1
end
end
3-32
Getting Started Writing Scripts
#------------------------------------------------------------
# ExportAllExistingProjects(appApi)
# This will be called if the user presses OK from the
# message dialog.
# Parameters::
# * applicationApi is supplied as a parameter.
# Returns::
# * NIL
#------------------------------------------------------------
def ExportAllExistingProjects(appApi)
appApi.SetExportPath( "C:\\temp" );
iCnt = appApi.GetChildCount(ObjPrj);
i = 0
until i == iCnt
prj = appApi.GetNthChild(i, ObjPrj);
strPrjName = prj.GetName();
FlagDocumentsToBeExported(prj)
prj.Export(strPrjName, "pdf" );
prj.Export(strPrjName, "dxf" );
prj.Export(strPrjName, "svg" );
prj.Export(strPrjName, "tiff" );
i += 1
end
end
#------------------------------------------------------------
#------------------------------------------------------------
# Main Ruby Script::
# This process will export all projects and documents
# to many different file formats.
#
# Supplied Interface::
# applicatonApi Interface to Automation Studio's
# application object
#------------------------------------------------------------
MsgBox = System::Windows::Forms::MessageBox
MsgResultOK = System::Windows::Forms::DialogResult.OK
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
MsgBox = System::Windows::Forms::MessageBox
IronRuby assigns variables when they are accessed or changed. In the above
example, the MsgBox variable provides access to the message box object from
the namespace System::Windows::Forms. Now all message box methods
are available through MsgBox.
This segment of code fetches information from the user of the application in
order to get permission to export all projects currently loaded. If the user agrees
the function ExportAllExistingProjects() is called.
def ExportAllExistingProjects(appApi)
# ...
end
This lines show the process of how to create a function that can be called
anywhere within the script.
3-34
Getting Started Writing Scripts
def ExportAllExistingProjects(appApi)
appApi.SetExportPath( "C:\\temp" );
iCnt = appApi.GetChildCount(ObjPrj);
i = 0
until i == iCnt
prj = appApi.GetNthChild(i, ObjPrj);
# Do something with the project object supplied
end
end
This is a classic example of navigating through all the children of the application
object. The application object contains projects. From each project object their
respective documents can be accessed. The parameter above ObjPrj indicates
to the search to return projects. You will see the same form within the function
FlagDocumentsToBeExported().
appApi.SetExportPath( "C:\\temp" );
doc.SetToBeExported(true);
This sets the “To be exported” attribute on a document defined by the variable
doc. When the next export process is run, this attribute will determine if the
document should be exported.
prj.Export(strPrjName, "pdf" );
This process exports the project to the specified file format. All files labeled to be
exported will be exported.
Only the actual methods required will be shown here. See section 3.3.2 First C# Example
Script for the structure of the module AS.API.Client and the class ClientCSharp.
The IRScriptD methods are launched from the “Extended” menu bar created by
example 3.5.2 Registration Script C#.
//------------------------------------------------------------
// Name of File:: IRSCRIPTD
//
// Purpose::
// The following set of methods are the C# version of the
// IRSCRIPTD demo.
//
// This search for all projects currently loaded and export
// them to the following file formats. pdf, dxf, svg, and
// tiff
// -----------------------------------------------------------
-
// -----------------------------------------------------------
-
// -----------------------------------------------------------
-
// Main C# IRSCRIPTD ::
//
// Purpose::
// This process will export all projects and documents
// to many different file formats.
//
// Supplied Interface::
// applicatonApi Interface to Automation Studio's
// application object
// -----------------------------------------------------------
-
3-36
Getting Started Writing Scripts
// -----------------------------------------------------------
-
// FlagDocumentsToBeExported( IProjectApi prj)
//
// Purpose::
// Set all documents export flag to true for all documents
// found in the provided project.
//
// Parameters::
// IProjectApi prj Project to be searched
// -----------------------------------------------------------
-
void FlagDocumentsToBeExported(IProjectApi prj)
{
IDocumentApi doc;
int iCnt2 = prj.GetChildCount(ASAPI_OBJ.DOCUMENT_API);
strPrjName = prj.GetName();
3-38
Getting Started Writing Scripts
prj.Export(strPrjName, "dxf", true );
prj.Export(strPrjName, "svg", true );
prj.Export(strPrjName, "tiff", true );
}
return;
}
The comments in the code should cover most topics. Note that different structure for the
methods within C# as compared to Ruby.
This is an overview of the API and Scripting static and runtime model. This provides some
basic information on how the scripts run within Automation Studio™.
The following should provide the reader with a general idea of how the two basic types
of external process are inserted into Automation Studio™’s process flow.
A minimum of a couple of processes would have to be written, the first process would
tell Automation Studio™ which hooks/events the user would like to add functionality to
and an additional process for each event that would respond to the respective
hooks/events.
The above diagram shows how a startup script registers functionality to different events
that could occur in Automation Studio™ and then, when the events occurs, run the
associate script/method.
Concerning the way the extensibility system has been developed, the user will need a
little understanding of an object model but not much. The basic requirement here is that
the developer understands that the methods supplied through the API will be dependent
on an object. He will have to use the proper object with the correct method to get the
desired effect.
The interface supplied will relate to a simplified version of Automation Studio™’s object
model. Through this view, a client will be able to manipulate the data and process flow
that currently exist.
Automation
Ribbon Studio
Projects
Projects
Projects
Projects
Documents
Projects
(Diagrams) Projects
Projects Projects
Variables
Projects
Components
Projects
Projects
Layers Projects
Views
View
Projects
Projects
Variables
The use of the term base through the document indicates common functionality used by
all objects. For example, this common functionality gives information about:
The parent;
4-2
Static and Runtime Model Overview
The children;
4.2.2 Node
The use of the term node through this document indicates common functionality used by
projects, documents and components. Examples of this common functionality are
Get Variables;
Set Variables.
4.2.3 Application
The application object (Automation Studio™) is the base of the system available to the
user of Automation Studio™. This object can be used as starting point to access all other
available objects. This is the first object created and only one is ever created.
Through the application object, the user can access all other objects that exist in the
system. From the application object, projects can be accessed, then from the projects
documents can be accessed. Finally from documents, views and components may be
accessed.
The application object is the base of the system and every event that will supplies
extended functionality will be processed through this object.
The following are a few examples of what can be directly done using the application
object. For a complete list see the IApplicationApi object in chapter 7 API Reference
Manual.
Load Projects;
Start Simulation;
Stop Simulation.
Some of the above requirements will be handled by generic function/method calls that
will use the form “apply function to all children of type”.
4.2.4 Project
A project is a container of related data and is stored on the file system as a single file.
Mainly projects contain documents and an application may contain many projects.
The following are a few examples of what can be directly done using the project object.
For a complete list see the IProjectApi object in chapter 7 API Reference Manual.
Show Diagrams;
4.2.5 Document
Many documents can be contained by a project and these documents can be many
different things. Therefore what the interface does when called will be dependent on
what the document is. A document could be any of the following objects:
Schematic Diagram;
Folio Diagram;
Report.
4-4
Static and Runtime Model Overview
The following are a few examples of what can be directly done using the document
object. For a complete list, see the IdocumentApi object in chapter 7 API Reference
Manual.
Maximize;
Minimize;
Initial Zoom;
All Zoom;
Show;
Hide;
Show Layers.
4.2.6 View
A document can contain many views. Views are used during navigation to find a
predetermined image within a document.
4.2.7 Component
Set colors;
Push, pop;
Get Properties;
Set Properties.
4.2.8 Ribbons
From the application object, the third-party developer will be able to access the system
ribbon.
This will supply the user with the ability to manipulate the availability of tabs, groups and
buttons (commands), or to add personal tabs, groups, and buttons to the system ribbon.
These new interfaces could be used to significantly alter the behavior of Automation
Studio™.
Scripts will be able to access the following information/methods of the ribbon bar:
Hide All;
Show.
4-6
Static and Runtime Model Overview
4.3 Navigation
The interface supplied will be dependent on the objects that generated the event.
From these objects, it will be possible to obtain access to other objects within the model.
To save some fetching of information, if the object is contained within a project and/or
document, these projects and/or documents are supplied directly to client’s environment.
Any additional information will have to be extracted by navigation through the object
model until the correct object is found. Then the correct object calls the appropriate
methods.
From the application object, the developer can fetch all the projects, the ribbon,
and the picture window.
From a project, accessed through the application object, the developer can access
the contained documents and plotters.
From a document, accessed through a project, the developer can access the
contained layers, views, and components.
A client entry point is a term that is used for either hooks or events. A User Entry Point is
any point in processing (event/hook) where a user can add additional functionality.
When the system starts up, an initialization script or .NET process can be called allowing a
client to set all the different entry points to be processed. Registering or un-registering
points can take place within any third-party method or script.
After registering the different Scripts or .NET processing entry points these events are
handled in the following way.
The entry points/events available to the scripts or .NET extensibility developer are listed
with each object described within the API section of this document and within the
interface files available (IApplicationApi.cs, IProjectApi.cs, etc). These entry
points will be set points at which the redirection can occur, bypassing, or not, normal
processing. These entry points can be system wide or dependent on a single object.
Also during registration, the user will be able to define how the entry points will be
handled, either by a user .NET method or a simple AS script.
4-8
5 AS Scripting Environment
This section may be skipped if the user intends only to use .NET extensibility.
5.1 Initialization
In IronRuby the require command makes an assembly available to the script. In order
to have access to the Automation Studio™ API the script builder must include access to
AS.API.Share for AS’s general interface:
require "AS.API.Share"
The following are a number of definitions that are required by different method calls.
Access to these definitions can be simplified by assigning them to variables at the top of
a script.
asTid = AS::API::Share::ASAPI_OBJ
asVarType = AS::API::Share::ASAPI_VARTYPES
asEvent = AS::API::Share::ASAPI_EVENTS
asProcessType = AS::API::Share::ASAPI_PROCESS_TYPE
asMode = AS::API::Share::ASAPI_PROCESS_MODE
asReturns = AS::API::Share::ASAPI_RETURNS
The following global identifiers are available to any Automation Studio™ script called by
Automation Studio™. These supply access to important objects.
projectApi Supplies access to the project that is related to the object that
initiated the script call. This is only available if the event was
generated by a specific project.
baseApi Supplies access to the object that initiated the script call. This
is only available if the event was generated by a specific
project.
There is only one applicationApi and this variable will always point to the
application object. All the other variables will be dependent on how the script was
launched. Example, if the script was initiated as a parameter to Automation Studio™ as it
was starting only the applicationApi object will exist. All the other variables will be
assigned to “nil” and an exception will be thrown if used. The script developer needs to
know which and when these objects come into existence if s/he intends to use them.
This section provides the steps required to run scripts within Automation Studio™.
The only tool required to write Automation Studio™ user scripts is a text editor of some
kind. These scripts will have to follow the syntax of the supported language. As noted
before (section 3.2 International Support), a good text editor for simple AS scripts is
Notepad++.
The following is the general process that is used to find script files used within AS.:
5-2
AS Scripting Environment
If the search path provided starts with “.\” the script will be loaded relative to
the current directory.
If the search path provided starts with “\”, the script will be loaded relative to
the current drive.
If script string does not use any of the hardcoded paths described above the
following paths will be searched:
AS’s system scripts directory.
AS’s execution path plus the sub directory Scripts.
The user’s application data path plus the sub-directory Scripts.
Common application data path plus the sub-directory Scripts.
The system scripts directory can be set in any of the following ways in order of
precedence:
The section shows the different ways a script can be launched from within Automation
Studio.
Syntax
5.3.4 Hooks
Throughout Automation Studio™, points in processing have been identified, callout hooks
have been supplied. During the running of an initialization script the developer can
register any of these points in processing and to a script to be called when the event
occurs.
As Automation Studio™ receives the “on new project” event a user may need to execute
his own processing. To do this the script developer assigns the “New project” hook to a
script of his choosing. This is done by calling the RegisterEvent() method within an
initialization script. The following is an example of how to assign a script with the name
OnProjectCreate.rb to the NEW_FILE hook.
5-4
AS Scripting Environment
pEvent = AS::API::Share::ASAPI_EVENTS
pType = AS::API::Share::ASAPI_PROCESS_TYPE
pMode = AS::API::Share::ASAPI_PROCESS_MODE
applicationApi.RegisterEvent (pEvent.NEW_FILE,
pType.SCRIPT,
pMode.SYNC,
"OnProjectCreate.rb");
The above lines could be added to a functioning script file like ASScriptSetup.rb
located in the script directory, and this information set to AS through the Automation
Studio™ Options (see section 3.6 Run a Script at Startup).
The return value from the script will indicate to Automation Studio™ whether or not
normal processing should proceed.
The same script callout will exist wherever the user opens a project.
Same goes for the open project event, as Automation Studio™ receives this event a user
needs to be able to execute his own processing. In this case the user will be hooking a
C# method, after the user method has completed its work the script indicates to
Automation Studio™ whether or not normal processing should precede.
To setup this hook the script developer would have had to include the following call in
his initialization script.
applicationApi.RegisterEvent (pEvent.OPEN_FILE,
pType.CSHARP,
pMode.SYNC,
"OnCheckOut");
After this hook has been registered whenever the “Open Project” is selected the user’s
script OnCheckOut.rb is called first.
Above are just a few examples of points in the system where a user may be interested in
applying functionality with the use of scripts or C# methods.
All the interfaces that will be developed will be described in detail in chapter 7 API
Reference Manual.
5.3.5 Events
What is required in the windows environment to be able to run scripts from within
Automation Studio™.
5.4.1 Methodology
The scripting language supplies an object/method based interface to AS’s object model.
This scripting interface simplifies Automation Studio™’s object model so that the script
developer does not have to understand all the complexities of object oriented
programming in order to produce effective scripts.
The user will have to access the desired interface before calling methods related to
specific objects.
5-6
AS Scripting Environment
As far as the user is concerned objects are just pieces of data maintained by Automation
Studio™. As an example objects can be the application itself, projects, documents,
graphical components etc.
The script writer will often call a function that extracts information of a particular type
from objects within Automation Studio™; therefore the user has to supply, as a
parameter, the type. The following list describes the identifiers of the different types of
objects that the user may need access to.
The following is a list of the object types and their identifiers that a developer can expect
to work with (Note: asTid = AS::API::Share::ASAPI_OBJ):
Application asTid.APPLICATION_API
Component asTid.COMPONENT_API
Document asTid.DOCUMENT_API
Layer asTid.LAYOR_API
Project asTid.PROJECT_API
Variable asTid.VARIABLE_API
View asTid.VIEW_API
An example of how these identifiers can be used; a script can query a document for
component type children instead of a view of type children that could also be extracted.
Indicates how a script writer can access key objects within Automation Studio™.
The variable applicationApi points to the application. This is the starting point for
any AS script that requires access to AS’s object model. The methods that are available
through this object are available through the interface IApplicationApi. This
From the application object the script writer can then access objects available through
AS.API.Share module. This is done by using supplied search methods or by
navigating through the object structure from the application object. Here are a few
examples of search methods that can be used from any object dependent on the class
IBaseApi like the application object.
IProjectApi GetProjectApi();
IProjectApi GetProjectApi(string prj);
IDocumentApi GetDocumentApi();
IDocumentApi GetDocumentApi(string doc);
IDocumentApi GetDocumentApi(string doc, string prj)
IViewApi GetViewApi(string view);
IViewApi GetViewApi(string view, string doc);
IViewApi GetViewApi(string view, string doc, string prj);
These are methods that supply access to projects, documents and views. Of course what
is returned is dependent on the object the method was called from.
Here is an example of accessing a project and querying how many documents it contains.
asTid = AS::API::Share::ASAPI_OBJ;
prj = applicationApi.GetProjectApi("Prj1");
nNumDoc = prj.GetChildCount(asTid.DOCUMENT_API);
All interfaces supplied, include the following methods that allows the script builder to
access additional interfaces.
5-8
AS Scripting Environment
// This Nth child will be extracted from the list defined
// by iObjType
// The identifier is global to all objects
IBaseApi GetNthChildId(int id, int iNth,
int iObjType);
With the above set of interfaces it is possible to navigate between the available objects
within Automation Studio™. This is accomplished by the fact that all client available
objects are accessible through the offspring of the application object that all scripts have
access to. The applications contain projects, projects contain documents, and documents
contain views, variables and components; and components contain variables.
The primary object is the object that generated the event that launched the script. In
most cases this is the application object.
IBaseApi GetPrimaryBaseApi();
This returns an object that is dependent on the interface IBaseApi. The primary object
can then be used to access related objects like parents and children as described in the
previous section.
The registration function described in this section is used to assign user functionality to
possible events that can occur. This registration process can be called at anytime, during
initialization (most common) or after any event that has already been hooked to user
functionality.
This method must be called for every event a user wants to hook functionality to.
where:
In the case of a static event, when the event is registered to a specific type of object, all
objects of that type will respond to the event.
In the case of dynamic events, they are dependent on the object that receives the
registration. When the above method is called on a specific object that hooks a specific
dynamic event, this is applied to the object and does not affect any other objects of the
same type.
Most events are applied to the application object. Since there is only one application
object these events are always triggered when they occur.
This allows the registration of how events will be handled. Either the event will use the
user’s C# interface or scripts. This allows the user to use a mix of different techniques to
respond to different events.
5-10
AS Scripting Environment
The unique identifier supplies the script or the method name that has to be called when
the event occurs.
5.5.5 Example
The following text describes how to create a hook to the OnCheckIn.rb script file
using the RegisterEvent() method in an initialization script.
First step is to create a script in a valid script directory using the following name. Call it
InitAS.rb.
Add the following lines to the file InitAS.rb in the scripting directory.
require "AS.API.Share"
pEvent = AS::API::Share::ASAPI_EVENTS
pType = AS::API::Share::ASAPI_PROCESS_TYPE
pMode = AS::API::Share::ASAPI_PROCESS_MODE
applicationApi.RegisterEvent (pEvent.CLOSE_FILE,
pType.SCRIPT,
pMode.SYNC,
"OnCheckIn.rb");
Launch Automation Studio™ using the initialization script InitAS.rb. This is done by
including the following syntax as Automation Studio™ is launched.
AsProjet.exe /SCRIPT:InitAS.rb
When processed, this will register the script OnCheckIn.rb to the close file event.
Now whenever a “close file” event occurs, the OnCheckIn.rb script will be processed
and if this script returns pReturn.NORMAL_PROCESS, the regular handling of the close
file event will be processed. If the script returns
pReturn.RETURN_FROM_PROCESSING the regular handling of the close file event
will be skipped.
The following command will remove any event registration on the related object.
applicationApi.UnRegisterEvent(int iEventType);
With respect to the interface to the Automation Studio™ model the scripts act very much
like equivalent calls found in the C# module. The major differents is performance.
Otherwise you are accessing the same interface that third party .NET developers are
using.
5-12
6 .NET Environment
This section shows what is required to link and call .NET methods from objects unrelated
to Automation Studio.
6.1 Introduction
This section may be skipped if the user intends only to use AS scripting environment.
Running .NET methods from Automation Studio™. We provide in this manual C# and
VB.NET examples. Only these two languages have been tested, other .NET languages
logically should work.
Different methods and the required syntax to call .NET methods from Automation
Studio™.
Throughout this document <Method String> defines the method syntax used in the
interface to indicate to Automation Studio™ what specific assembly object and method to
call. This is a string that uses the following syntax:
Methods can be called from Automation Studio™ through the followining interfaces. To do
this, the user has to supply information about the assembly, class used and the desired
method to be called in the <Method String>.
AS.API.Client::ClientCSharp::IRScriptA
6-2
.NET Environment
Method that can be called by any object within an AS or .NET client script:
IBaseApi.RunMethod(<Method String>);
If the <Method String> does not supply the assembly or class name, the system will
automatically create the following strings, dependent on the object that generated the
call:
AS.API.Client::ApplicationApiClient::<Method Name>
AS.API.Client::ProjectApiClient::<MethodName>
AS.API.Client::DocumentApiClient::<MethodName>
Client can create any modules to be used with Automation Studio™ as long as they do
not conflict with DLLs and classes that exist elsewhere. These modules can be used to
interact with AS through the use of the interface AS.API.Share.
2. Link the external functionality to an object or the application by using one of the
plug-in interfaces described in the section 6.3.1 Method Syntax. The DLL created
by the method builder must be inserted into the system cash or in a directory
that is included in the path environment variable so the assembly can be safely
found by Automation Studio ™;
3. When the interface is called the DLL provided will be loaded and an instance of
the object will be created, and finally using the newly created object the method
indicated will be called. If anything does not exist an exception will be thrown,
caught by AS and the script builders process will be discontinued.
Syntax
<Method to Launch> Method that will be run at start up. See Section 6.5.2
ApplicationClientApi on how to write the class that contains
this method.
6-4
.NET Environment
6.3.7 Hooks
Throughout Automation Studio™ points in processing have been identified callout hooks
have been supplied. During the running of the initialization scripts the developer can
register any of these points in processing and hook it so that his .NET method is called.
6.3.8 Events
The script writer or .NET developer will be working with objects. These objects map back
to equivalent objects found in Automation Studio™’s model. While working with these
objects you may have to supply an object type identifier. The following is a list of the
object interfaces and their identifiers that a developer can expect to work with.
IApplicationApi TID.APPLICATION_API
IComponentApi TID.COMPONENT_API
IDocumentApi TID.DOCUMENT_API
IPictureWindowApi TID.PICTURE_API
IProjectApi TID.PROJECT_API
IViewApi TID.VIEW_API
An example of how these identifiers can be used, a script or .NET method can query for
Any class that will be used to communicate with the Automation Studio™ object model
will have to be derived from IBaseClientApi found in the assemble
AS.API.Share.dll. The following methods are required in the class created for this
purpose.
void GetBinding(out long testValue);
bool SetParent(IApplicationApi app,
IProjectApi prj,
IDocumentApi doc,
IBaseApi baseApi);
void SystemInitialization();
Here is an example of creating a class that can be called from Automation Studio.
Automation Studio™ will use the <Method String> supplied by the different
interfaces within a project, script or startup value to load and run a method from an
external source during the appropriate event
The client module will have to reference the module AS.API.Base.dll that includes
the base class interface required to communicate with Automation Studio™.
C# Example:
At the top of the module this referenced module will have to be included:
using AS.API.Share;
The class created must use the reference IBaseClientApi. The following contains the
manditory methods required by the object.
6-6
.NET Environment
VB.NET Example:
Automation Studio™ finds the clients DLL, loads it, and creates an instance of the class
defined in the <Method String> by <class name>, then calls following expected
methods.
6-8
.NET Environment
The different objects provided by SetParent() will only have a value if they are
available at the time of the event that created the external interface. If the object that
generated the event was a project, then the current project and application are supplied.
No single document can be supplied since no specific document is contained by the
event. The application object is always available.
The IBaseApi instance provided to the SetParent() method provides access to the
object that generated the event. If the object that generated the event was a
component, example button up on a line, then this will return access to
IComponentApi interface object. It is up to the user to cast the result to the correct
object.
Now the objects available to the developer through the above methods are all based on
the base class IBaseApi. This is the base interface into AS’s object model.
class IBaseApi
{
...
bool IsA(int iObjType); // Returns true if
// the type matches
This method is used to validate that an object fetched, using the general methods, is the
correct object type.
The base class IBaseApi also supplies the following access to the object’s children and
parents.
Most objects contain other objects: applications contain projects, projects contain
documents etc. These general methods allow a developer to navigate between such
objects; of course the developer would have to know the existing relationships.
int GetId();
Once in possession of the object’s identifier the actual object can be accessed using the
following method. The object identifier is unique within the system so any object based
on the interface IBaseApi can access any other object if the correct identifier is
supplied.
The registration method described in this section is used to assign user functionality to
possible events that can occur. This registration process can be called at anytime, during
initialization (most common) or after any event that has already been hooked to user
functionality.
This method must be called for every event a user wants to hook functionality to.
string method)
6-10
.NET Environment
iEType Identifier of the required event (user callout entry point) from
table AsApiEvents related to the object that the
RegisterEvent method was called from.
iPType
ASAPI_PROCESS_TYPE.CSHARP : User .NET interface
will be used.
In the case of a static event, when the event is registered to a specific type of object, all
objects of that type will respond to the event.
In the case of dynamic events, they are dependent on the object that receives the
registration. When the above method is called on a specific object that hooks a specific
dynamic event, this is applied to the object and does not affect any other objects of the
same type.
Most events are applied to the application object. Since there is only one application
object these events are always triggered when they occur.
During registration this indicates what process type will handle the events when they are
called. Either the event will use the user’s .NET interface or Automation Studio™ scripts.
This allows the user to use a mix of different techniques to respond to different events.
The <method string> that has to be called when the event occurs.
When the point in processing that gets diverted is related to an object other than the
Application Object the sequence of events is as follows:
When the component receives this event it posts the launch user method with the
application and finishes its processing of the event. After completion of the event, the
application object launches the user’s method or script. This way whatever the user does
in his script it will not destabilize Automation Studio ™. This does limit the user from being
able to bypass Automation Studio™ functionality.
6-12
.NET Environment
When the application generates the event it calls the launch user event and waits for a
user’s response. When user processing is complete the launch user method will return a
code that indicates whether or not Automation Studio ™ will continue processing the
event.
The following command will remove any event registration on the related object:
Automation Studio™ generates calls to the user’s interface when different events occur,
if they have been registered. A few examples of events on the application object are
OPEN_FILE, PROJECT_CREATED, CLOSE_FILE, NEW_FILE, RUN_SCRIPT,
SNAPSHOT_DOC_CREATED, SIMULATE_PAUSED, SIMULATE_STOPPED,
SIMULATE_STOP, SIMULATE_START and CALL_METHOD.
All objects will have a set of possible events that can be registered; these events will be
documented with each object in each section.
These events, when generated, are sent to their respective objects, ApplicationApi,
ProjectApi etc. When these objects process the events, if hooked by client
functionality will create an instance of a mirror object based on the class
IBaseClientApi.cs.
This allows the .NET developer to have an instance of each object to work as an interface
to Automation Studio™.
Third-party developers through this process can add their own process flow to the current
Automation Studio™ environment.
Only one interface object will be created to communicate with their respective objects in
Automation Studio™.
How to access Automation Studio™’s object module from a user’s Automation Studio™
script or.NET modules can be found in the following interfaces:
IApplicationApi.cs
IBaseApi.cs
IComponentApi.cs
IDocumentApi.cs
IProjectApi.cs
IViewApi.cs
IVariableApi.cs
This supplies a complete set of the methods available to the user modules. Of course this
set of interfaces will grow over time.
All .NET objects created by a developer have to be derived from the interface defined in
the module IBaseClientApi.cs.
This interface supplies these objects with a set of standard calls to manipulate their
6-14
.NET Environment
environment.
User functionality will only be loaded when an event takes place that requires it. When
required, any dependent modules will be dynamically loaded. Errors will not be
generated if AS scripting environment DLL’s or the external modules do not exist, unless
they are explicitly called from a display or a loading script.
6.5.2 ApplicationClientApi
Automation Studio™ expects there to be a class derived from the BaseClientApi class
supplied. If the user does not supply the assembly and the class name it will expect a
.NET assembly with the name AS.API.Client that includes the following class:
The rest is up to the third party developer. The developer can create any methods that
will be registered to events or be called by the initialization or hyperlinks processes.
This object ApplicationClientApi will receive most of the user entry point events
as long as this object was the one created by the user’s class factory using the identifier
ASAPI_OBJ.APPLICATION_API. Only one of these objects can be created.
All objects a third party developer would like to register events to need to be created in
the same way that the ApplicationClientApi. Register events that call methods
based on IBaseClientApi.
The system initialization entry point object is expected to be an instance of the class
BaseClientApi so it will receive a call SetParent() that will supply all the required
interfaces for future work. It is good practice to save these interfaces in the external
object and provide them when required. Here is a suggested interface.
After fetching each object the methods described in the following section apply.
The variable applicationApi points to the application. This is the starting point for
any AS script that requires access to AS’s object model. The methods that are available
through this object are available through the interface IApplicationApi. This
interface is described in section 7.4 Application.
Example: The following fetches the application object and tests to see that it is an
application object.
IApplicationApi pApp;
pApp = GetApplication();
if(pApp.IsA(TID.APPLICATION_API))
6-16
.NET Environment
Register Methods to be Launched. Example
This interface can be called in the initialization method in order to hook scripts or
methods onto possible future events.
string szParam)
First step, create the class ApplicationClientApi and compile it into the assembly
AS.API.Client.dll with the following two methods:
void InitializeClientInterface1()
void OnCheckIn(string pStr)
AsProjet.exe /METHOD:InitializeClientInterface1
When the close file event occurs the method OnCheckIn(<filename>) will be called
on the application object. Different events will require different parameters so the third-
party developer has to know the available events and the parameters that will be
supplied with the event. This will all be documented in the interface file IBaseApi
found in Assembly AS.API.Share.
6-18
7 API Reference Manual
This section describes the available access to Automation Studio™’s object model that can
be used by a third-party developer. This interface can be used to manipulate the current
data contained within the current AS environment.
The reference manual will be organized by object that a user is required to manipulate.
Methods may be repeated due to they may behave slightly differently dependent on the
object involved in the call.
Overview of the available objects contained within AS’s model that can be accessed.
With the scripting interface all calls are methods and these methods are generally
applied to objects within the Automation Studio™ environment.
From the client’s script, Automation Studio™ object model can be accessed through the
following interfaces. Each interface will be described in detail in the following sections.
All objects available to a builder can be accessed using a unique identifier. This identifier
is returned by a number of supported methods:
int GetId();
int GetParentId();
The following command can then be used to retrieve the required object using an object
identifier.
IBaseApi GetParent();
It is safe practice to validate that you have the correct object before using it. To do this
the method IsA() is supplied. Example (both parent and obj are IBaseApi based
objects):
parent = obj.GetParent();
if(parent.IsA()){
:
}
This section describes the functions and identifiers that can be used by all object types
available to the script builder. These objects can be identified using a common identifier
supplied by the navigation functions or the launch script interface. Most functions will
require this identifier in order to know what object to apply the function to.
7-2
API Reference Manual
7.1.3 Definitions
This section supplies a common set of identifiers that exist within Automation Studio™.
7.1.3.1 ASAPI_PROCESS_TYPE
pType = AS::API::Share::ASAPI_PROCESS_TYPE Ruby
pType = AS.API.Share.ASAPI_PROCESS_TYPE; CSHARP
The system has been defined to allow a user to make calls to a script, or to methods
written in C#, so these attributes allow the user to set what process method will be used.
pType.CSHARP
pType.SCRIPT
7.1.3.2 ASAPI_EVENTS
pEvent.OPEN_FILE
Just before AS’s open file dialog is initiated. Here a user can bypass this
functionality with his own.
pEvent.CLOSE_FILE
Just before AS’s close file processing occurs. Here a user can bypass this
There are many more, but they will be documents at the beginning of each object
section.
applicationApi.RegisterEvent(pEvent.CLOSE_FILE,
pType.SCRIPT,
pMode.SYNC,
"OnCheckIn.rb");
After this method has been called, when the close file event occurs, Automation
Studio™ will first call the script OnCheckIn.rb. Knowing what events can be
mapped and how to map them comes from the definition of each event found in
this reference manual.
7.1.3.3 ASAPI_RETURNS
A third party script can supply the following flags when the script ends. The hook that
launched a user’s script will be waiting on one of the following two returns.
asReturn.NORMAL_PROCESSING
When the user’s script returns this normal processing will proceed.
7-4
API Reference Manual
asReturn.RETURN_FROM_PROCESSING
If this is returned, any normal processing that can be scripted will be skipped.
Only some hooks that are based on the application object can have normal
processing that can be skipped.
Example:
return(pReturns.RETURN_FROM_PROCESSING);
Automation Studio™ would cancel what it would normally do during a closed file
event since the pReturns.RETURN_FROM_PROCESSING flag was supplied.
The following functions are available to all objects in the system. This supplies common
functionality like navigation between objects, management of objects and control of
events.
The following sections will describe in detail how to use these methods.
7-6
API Reference Manual
bool CreateDocument(int dType, string dN, string pN, string dTmpl, string pTmpl)
This method creates a document in the project using the names provided if the document
does not already exists in memory with the same name. If the document already exists,
it will be selected. If the project provided does not already exist in memory, it will be
created.
If the object is a project or has a parent as a project, it will be used if a project name is
not supplied.
Parameters:
Returns:
Ruby Example:
#------------------------------------------------------------
# Name of File::BaseCreateDocument.rb
#
# Purpose::
# This shows how to create a new document.
#------------------------------------------------------------
require "AS.API.Share"
pDocType = applicationApi.GetDocTypes();
doc = applicationApi.CreateDocument("D1","NewFile");
prj = applicationApi.GetCurrentProject();
doc.CreateDocument(pDocType.Report,"Rp1",prj.GetName(),"BOM");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-8
API Reference Manual
This method creates a project using the name provided if a project does not already
exists in memory with the same name. If the project already exists the project will be
selected.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseCreateProject.rb
#
# Purpose::
# This shows how to create a new project.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.CreateProject("NewFile");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This fetches the number of children an object has of type defined by iObjectType. An
object may have a number of lists, so object type points the query to the correct list. i.e.
a document may have children of type AS.API.Share.ASAPI_OBJ.VIEW_API or
AS.API.Share.ASAPI_OBJ.COMPONENT_API. This field is ignored if the object only
has one object type.
Parameters:
iObjectType (Optional) Objects may contain more than one type of children,
so this parameter indicates what object list count to return.
This uses defines from the structure
AS.API.Share.ASAPI_OBJ and can be one of the
following.
APPLICATION_API
PROJECT_API
DOCUMENT_API
COMPONENT_API
VIEW_API
If a type is provided that the object does not support no
elements will be found. If this parameter is not supplied the
default object type will be used.
Returns:
Example:
#------------------------------------------------------------
# Name of File::GetChildCount.rb
#
# Purpose::
# This ruby script demonstrates fetching the number of
# children of an object.
#------------------------------------------------------------
require "AS.API.Share"
7-10
API Reference Manual
iObjectType = AS::API::Share::ASAPI_OBJ.PROJECT_API
ProjectList = "There are currently [";
iCnt = applicationApi.GetChildCount(iObjectType);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This fetches the iNth child object of type defined by iObjectType. An object may
have a number of children lists, so the object type points the query to the correct list. i.e.
a document may have children of type AS.API.Share.ASAPI_OBJ.VIEW_API or
AS.API.Share.ASAPI_OBJ.COMPONENT_API. This field is ignored if the object only has one
object type.
This allows a script writer to index through all children of a particular type of object
associated to the current object.
Parameters:
iObjectType Objects may contain more than one type of children, so this
parameter indicates what object list count to return. This uses
defines from the structure AS.API.Share.ASAPI_OBJ and
can be one of the following
APPLICATION_API
PROJECT_API
DOCUMENT_API
COMPONENT_API
VIEW_API
Returns:
IBaseApi The objects iNth iChildType child of type IBaseApi.
Warning:
The act of fetching a child from an object builds its API managers. In general the
first time a script or .NET module requires access to a specific object is when the
managers are created. This adds overhead which could lead to performance
problems if many primitive objects like components are accessed.
Example:
7-12
API Reference Manual
#------------------------------------------------------------
# Name of File::BaseGetNthChild.rb
#
# Purpose::
# This ruby script demonstrates the GetNthChild() method.
#------------------------------------------------------------
require "AS.API.Share"
iObjectType = AS::API::Share::ASAPI_OBJ.PROJECT_API
iCnt = applicationApi.GetChildCount(iObjectType);
i = 0
ProjectList = "";
until i == iCnt
prj = applicationApi.GetNthChild(i, iObjectType);
strPrjName = prj.GetName();
ProjectList << "[";
ProjectList << strPrjName;
ProjectList << "] ";
i += 1
end
applicationApi.SetLogFile("");
# Generally this will write a log to the temp directory
# if no logfile has been set by another process.
logType = AS::API::Share::LOGTYPE.FILELOG
applicationApi.LogInformation(logType,ProjectList, false,
false , 0);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method returns the related object’s document. A null document will be returned if
not enough information is supplied relative to the object. i.e. the application object must
include the project and the document names.
Parameters:
docStr The name of the document to get. Optional but must be
supplied if the project is supplied. If not supplied the objects
document will be returned.
prjStr The name of the required document’s project. Optional, If not
supplied the objects project will be used.
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseGetDocumentApi.rb
#
# Purpose::
# This ruby script demonstrates different ways to access
# a document related to an object. It expects specific
# project, document, and views to have been loaded.
#------------------------------------------------------------
require "AS.API.Share"
logType = AS::API::Share::LOGTYPE.FILELOG
prj = applicationApi.GetProjectApi("P2");
if(prj)
doc = prj.GetDocumentApi("D1");
if(doc)
doc.Show();
else
# Generally this will write a log to the temp directory
# if no logfile has been set by another process.
7-14
API Reference Manual
applicationApi.LogInformation(logType, "Document not
found (\"D1\")", false, false, 0);
end
end
if(doc)
doc.Show();
else
# Generally this will write a log to the temp directory
# if no logfile has been set by another process.
applicationApi.LogInformation(logType, "Document not found
(\"D2\",\"P1\")", false, false , 0);
end
view = applicationApi.GetViewApi("View2","D2","P1");
if(view)
doc = view.GetDocumentApi();
if(doc)
doc.Show();
else
# Generally this will write a log to the temp directory
# if no logfile has been set by another process.
applicationApi.LogInformation(logType, "Parent of View
not found.", false, false , 0);
end
else
# Generally this will write a log to the temp directory
# if no logfile has been set by another process.
applicationApi.LogInformation(logType, "View not found
(\"View2\",\"D2\",\"P1\")", false, false, 0);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method returns the object’s parent. The parent is returned in a generic structure that
is common to all objects within the API.
Parameters:
int Optional: When this parameter is not supplied the method will
return the first parent, i.e. a document will return a project, a
view will return a document etc.. Otherwise this parameter
will search through the parents until the parent of type iType
is found.
TID.APPLICATION_API
TID.PROJECT_API
TID.DOCUMENT_API
Null will be returned if no parent is found that meets the
requirements.
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseGetParentApi.rb
#
# Purpose::
# This ruby script demonstrates fetching a parent of the
# object.
#------------------------------------------------------------
require "AS.API.Share"
7-16
API Reference Manual
end
end
This method returns the requested project. A null project will be returned if not enough
information is supplied relative to the object. i.e. The application object must include the
project name.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseGetProjectApi.rb
#
# Purpose::
# This ruby script demonstrates different ways to access
# a view related to an object. It expects that a project
# with the names "P1" with a document D1 and view View2
# exist.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi("P1");
logType = AS::API::Share::LOGTYPE.FILELOG
7-18
API Reference Manual
0);
end
view = applicationApi.GetViewApi("View2","D2","P1");
if(view)
prj = view.GetProjectApi();
msg = "The project ["
msg << prj.GetName();
msg << "] was found using the view";
# Generally this will write a log to the temp directory
# if no logfile has been set by another process.
applicationApi.LogInformation(logType, msg, false,false,
0);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method returns the requested view. A null view will be returned if not enough
information is supplied relative to the object. i.e. The project object must include the
view and the document name.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseGetViewApi.rb
#
# Purpose::
# This ruby script demonstrates different ways to access
# a view related to an object. It expects that projects
# with the names "P1" and "P2"; and the documents "D1" and
# D2; and the views "View2", exist in memory
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi("P2");
if(prj)
view = prj.GetViewApi("View2","D2");
if(view)
7-20
API Reference Manual
view.Show();
end
end
doc = applicationApi.GetDocumentApi("D1","P1");
if(doc)
view = doc.GetViewApi();
if(view)
view.Show();
end
end
view = applicationApi.GetViewApi("View3","D2","P2");
if(view)
view.Show();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method can be used to call a ruby script using Automation Studio™’s script search
paths from within a script. If the script has already run, nothing will happen. The method
RunScript() should be used when it is required to have the script run more than
once.
Point about the Ruby implementation of this method. This is not like the Ruby “load”
command. The ruby load command is run every time it is encountered. Also Ruby load
command will reload classes and models. The LoadScript() just re-interpretes and runs,
line by line, the script defined by scriptName. To get identical behavior to the load
command you will need to also review the Ruby keywords “module” and “include”.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseLoadScript.rb
#
# Purpose:
# This ruby script demonstrates loading a script from a
# script.
# Warning:
# It is easy for a user to crash Automation Studio if a
# script loads itself.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.LoadScript("Base\\BaseGetParentApi.rb");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-22
API Reference Manual
If logging is enabled, this will write the information supplied to the either a file or the
Automation Studio™ message utility. A line will be written to the message utility using
the following format if they include header flag blHdr is set to false.
Where
The Object The namespace and object that called the method.
The Method The method called that generated the line in the log.
Parameters:
blHdr Include header flag. This adds a number of fields to the line that is
written to the file or message utility.
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseLogScriptInformation.rb
#
# Purpose::
# This shows how to write messages to the log system.
#------------------------------------------------------------
require "AS.API.Share"
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
doc.StartLogging(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM)
doc.LogScriptInformation("Message with header",true);
doc.LogScriptInformation("Message no header",false);
doc.StopLogging();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-24
API Reference Manual
This is used to assign user functionality to possible events that can occur. This registration
process can be called within any script, during initialization script (most common) or in
any script that handles events that have been hooked previously. Often the latter type of
registration is called on specific objects just after they have been created. In this case the
user would assign an initialization script to the creation of a particular type of object and
then when this script is called, assign a script to some event processed by the object.
Parameters:
iEvent The type of event that is to be hooked. The possible list of events
is dependent on the object that the event is tied to. This list can
be found with the object type later in this document.
iType This is the type of process (AS Scripting or .NET method) that will
service the event:
AS::API::Share::ASAPI_PROCESS_TYPE.CSHARP Use a C#
interface.
AS::API::Share::ASAPI_PROCESS_TYPE.SCRIPT Use Script
processing
Returns:
asEvent = AS::API::Share::ASAPI_EVENTS
asProcessType = AS::API::Share::ASAPI_PROCESS_TYPE
asMode = AS::API::Share::ASAPI_PROCESS_MODE
applicationApi.RegisterEvent(asEvent.OPEN_FILE,
asProcessType.SCRIPT,
asMode.SYNC,
"Base\\BaseRegisterEventTest.rb");
applicationApi.RegisterEvent(asEvent.CLOSE_FILE,
asProcessType.SCRIPT,
asMode.SYNC,
"Base\\BaseRegisterEventTest.rb");
applicationApi.RegisterEvent(asEvent.NEW_FILE,
asProcessType.SCRIPT,
asMode.SYNC,
"Base\\BaseRegisterEventTest.rb");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
#------------------------------------------------------------
7-26
API Reference Manual
# Name of File::BaseRegisterEventTest.rb
#
# Purpose::
# This just tests that an event has been registed.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Windows.Forms,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'
pRtnNormal = AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
pRtnAbnNrml =
AS::API::Share::ASAPI_RETURNS.RETURN_FROM_PROCESSING
MsgBox = System::Windows::Forms::MessageBox
MsgResultOK = System::Windows::Forms::DialogResult.OK
MsgBtns = System::Windows::Forms::MessageBoxButtons
if (msgboxRtn == MsgResultOK)
pRtn = pRtnAbnNrml
else
pRtn = pRtnNormal
end
return pRtn
This method can be used to call a client method. This provides the developer a simple
interface to C# dynamic loading mechanism. A developer has to be careful of how
variables are handled for recursive calls to this method. Any functionality loaded should
have been register in the system cash.
Parameters:
methodString The name of the Iron Ruby method to run, see section 6.3.1
Method Syntax.
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseRunMethod.rb
#
# Purpose:
# This ruby script demonstrates running a client
# method from a script.
# Warning:
# It is easy for a user to crash Automation Studio if a
# method loads itself.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.RunMethod("OnCheckIn");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-28
API Reference Manual
This method can be used to call a script using Automation Studio™’s script search paths
from within another script. This method works like any method call; every time it is
called the script will be run. The developer has to be careful of how variables are handled
for recursive calls to this method.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseRunScript.rb
#
# Purpose:
# This script demonstrates running a script from an
# script.
# Warning:
# It is easy for a user to crash Automation Studio if a
# script loads itself.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.RunScript("Base\\BaseGetParentApi.rb");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
After this call, every API called by a client generates a message in either a previously
specified file or the Automation Studio™ message utility.
Parameters:
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM
This flag will redirect the scripting messages to the Automation
Studio™ messaging utility.
AS::API::Share::LOGTYPE.FILELOG
This will redirect the scripting messages to a previously
specified file.
AS::API::Share::LOGTYPE.NOLOG
This will turn off logging on the related type of message.
AS::API::Share::LOGTYPE.VERBOSE
A dialog providing the user with a choose to continue or end
processing the script.
ifo Type LOGTYPE, sets the type of logging that will be applied to
general system information.
wrn Type LOGTYPE, sets the type of logging that will be applied to
system warnings. Default is LOGTYPE.NOLOG
err Type LOGTYPE, sets the type of logging that will be applied to
scripting errors. Default is LOGTYPE.VERBOSE
7-30
API Reference Manual
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseStartLogging.rb
#
# Purpose::
# This shows how turn on different logging systems.
#------------------------------------------------------------
require "AS.API.Share"
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
doc.StartLogging(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM)
doc.ShowViews("view1");
doc.SetLogFile("scriptlog.log");
doc.StartLogging(AS::API::Share:: LOGTYPE.FILELOG)
doc.ShowViews("view1");
else
doc.LogScriptInformation("Document[P1:D1] Not found",true);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method determines where the log file will be saved if the script writer selects the
AS::API::Share::LOGTYPE.FILELOG mode. By default, if this method has not
been called script files will be placed in the directory defined by windows environment
variable %TEMP%. Typically this directory is located
C:\Users\<user>\AppData\Local\Temp
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseSetLogDirectory.rb
#
# Purpose::
# This shows how change the directory of the current
# scripting log file..
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.SetLogFile("scriptlog.log");
applicationApi.SetLogDirectory("C:\\Demo")
applicationApi.StartLogging(AS::API::Share:: LOGTYPE.FILELOG);
7-32
API Reference Manual
This allows the user to set the name of the file to be used for all script messages.
Parameters:
logfile The name of the file to be used for the script message output.
Returns:
Example:
#------------------------------------------------------------
# Name of File::BaseSetLogFile.rb
#
# Purpose::
# This shows how to redirect the scripting messages to a
# log file found in the %TEMP% directory.
#------------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
Notice that only the first show view is added to the message utility.
#------------------------------------------------------------
# Name of File::BaseStopLogging.rb
#
# Purpose::
# This shows how turn off the redirection of scripting
# messages.
#------------------------------------------------------------
require "AS.API.Share"
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
doc.StartLogging(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM)
doc.ShowViews("view1");
doc.StopLogging()
doc.ShowViews("view1");
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-34
API Reference Manual
This is used to remove an event that previously had been registered. After which the
user’s methods or scripts will not be called.
Parameters:
iEventType The type of event that had been registered. The possible list of
events is dependent on the object that the event is tied to. This
list can be with the object type later in this document.
Returns:
applicationApi.UnRegisterEvent(asEvent.OPEN_FILE);
applicationApi.UnRegisterEvent(asEvent.NEW_FILE);
applicationApi.UnRegisterEvent(asEvent.CLOSE_FILE);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7.2 Node
Projects, Documents, and Components are nodes. These all share the same behavior.
This section provides how these objects can be accessed.
This object inherited by all node objects. This class is inherited by the following:
IProjectApi;
IDocumentApi;
IComponentApi.
asEvent = AS::API::Share::ASAPI_EVENTS
This table represents the list of points in AS’s process that a third-party developer can
hook into. This process entry points table relate to the application. The event column
indicates the attribute that will be supplied to the RegisterEvent() and
UnRegisterEvent() methods. The bypass processing column indicates whether or
not any code can be bypassed if the user indicates this should happen with the correct
return from his script.
7-36
API Reference Manual
7.2.3 Methods
This method creates a variable on the node using the supplied name. A variable can be
created of any type that exists in the ASAPI_VARTYPES structure.
Parameters:
Returns:
bool This method will return true if the variable was successfully
created or already exists. In the second case a warning
message will be supplied to the message handler.
Example:
#------------------------------------------------------------
# Name of File::NodeCreateVariable.rb
#
# Purpose::
# Provides to the script writer a method to create
# variables. Check the properties of the component “H1”
# for the results.
#------------------------------------------------------------
require "AS.API.Share"
asVarType = AS::API::Share::ASAPI_VARTYPES;
asMsgType = AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM
applicationApi.ChangeAllLogOutputs(asMsgType);
applicationApi.LogScriptInformation("Create variables.",false);
prj = applicationApi.GetCurrentProject();
cmp = prj.GetComponent("H1");
bCreated = cmp.CreateVariable( "MyVar" , asVarType.DOUBLE, true);
bCreated = cmp.CreateVariable( "MyVarA1" , asVarType.SINT, true);
bCreated = cmp.CreateVariable( "MyVarA2" , asVarType.INT, true);
bCreated = cmp.CreateVariable( "MyVarA3" , asVarType.DINT, true);
bCreated = cmp.CreateVariable( "MyVarA4" , asVarType.LINT, true);
bCreated = cmp.CreateVariable( "MyVarA5" , asVarType.USINT, true);
bCreated = cmp.CreateVariable( "MyVarA6" , asVarType.UINT, true);
7-38
API Reference Manual
bCreated = cmp.CreateVariable( "MyVarA7" , asVarType.UDINT, true);
bCreated = cmp.CreateVariable( "MyVarA8" , asVarType.ULINT, true);
bCreated = cmp.CreateVariable( "MyVarA9" , asVarType.REAL, true);
bCreated = cmp.CreateVariable( "MyVarB10" , asVarType.LREAL, true);
bCreated = cmp.CreateVariable( "MyVarB11" , asVarType.TIME, true);
bCreated = cmp.CreateVariable( "MyVarB12" , asVarType.DATE, true);
bCreated = cmp.CreateVariable( "MyVarB13" , asVarType.TIME_OF_DAY,
true);
bCreated = cmp.CreateVariable( "MyVarB14" , asVarType.DATE_AND_TIME,
true);
bCreated = cmp.CreateVariable( "MyVarB15" , asVarType.STRING, true);
bCreated = cmp.CreateVariable( "MyVarB16" , asVarType.BYTE, true);
bCreated = cmp.CreateVariable( "MyVarB17" , asVarType.WORD, true);
bCreated = cmp.CreateVariable( "MyVarB18" , asVarType.DWORD, true);
bCreated = cmp.CreateVariable( "MyVarB19" , asVarType.LWORD, true);
bCreated = cmp.CreateVariable( "MyVarC20" , asVarType.WSTRING, true);
bCreated = cmp.CreateVariable( "MyVarC21" , asVarType.CURRENCY, true);
bCreated = cmp.CreateVariable( "MyVarC22" , asVarType.DECIMAL, true);
bCreated = cmp.CreateVariable( "MyVarC23" , asVarType.COLOR, true);
bCreated = cmp.CreateVariable( "MyVarC24" , asVarType.FILLING_PATTERN,
true);
bCreated = cmp.CreateVariable( "MyVarC25" , asVarType.LINE_THICKNESS,
true);
bCreated = cmp.CreateVariable( "MyVarC26" , asVarType.LINE_STYLE,
true);
bCreated = cmp.CreateVariable( "MyVarC27" , asVarType.LINE_END, true);
bCreated = cmp.CreateVariable( "MyVarC28" , asVarType.HYPERLINK, true);
applicationApi.LogScriptInformation(" ---------------------------
Complete .",false);
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method creates a definition in AS so that complex variable types can then be
created. Complex variables are of type ENUM, STRUCT, and ARRAY.
This will not create the definition if one with the same name already exists.
This does not support combinations of the above like arrays of structures or structures
that contain arrays.
Parameters:
bOkExists True indicates that if the definition name already exists to return that
name and log a message. False indicates to return null indicating that
method failed.
strXML An XML structure defineing the require variable. This XML structure
takes on one of the following forms.
Where [myDef] Is the name of the definition to be created. If the name already exists
it will not be created and a message will be logged.
7-40
API Reference Manual
Where [Enum value discription] indicates the name given to the enum
element and [int value] indicates the value related to the name.
Returns:
string This method will return the name of the newly defined variable type.
The string supplied above in the [myDef] value is extracted and returned. If the
definition already exists null will be returned if the parameter bOkExists is set to false.
Example:
#------------------------------------------------------------
# Name of File::NodeCreateVariableDefinition.rb
#
# Purpose:: Create a complex variable types that then can be
# used within AS. The array type "TypeARRAY0"
# must exist in AS for this script to work fully.
#------------------------------------------------------------
iVarStruct = cmp.GetVariableObject("MyStructVariable3")
iVar2 = cmp.GetVariableObject(iVarStruct, "Contact Name");
cmp.SetVariableObjValue(iVar2, "Paul");
iVar2 = cmp.GetVariableObject(iVarStruct, "Address 1");
cmp.SetVariableObjValue(iVar2, "A Street");
iVar2 = cmp.GetVariableObject(iVarStruct, "Address 2");
cmp.SetVariableObjValue(iVar2, "Dorval");
strOs = System::Environment.OSVersion.ToString();
cmp.SetVariableObjValue(iVar2, strOs);
iVar2 = cmp.GetVariableObject(iVarStruct, "Phone");
cmp.SetVariableObjValue(iVar2, "555 420 0779");
valuePhone = cmp.GetVariableObjValue(iVar2);
7-42
API Reference Manual
000000000000\" T=\"15\" >";
strXML << "<d sz=\"5\" >";
strXML << "</d >";
strXML << "</AR>";
i = 0
while (i < 4)
iVar2 = cmp.GetVariableObject(iVar, i);
iVar3 = cmp.GetVariableObject(iVar2, "Var1");
cmp.SetVariableObjValue(iVar3, 1);
iVar3 = cmp.GetVariableObject(iVar2, "Var2");
cmp.SetVariableObjValue(iVar3, 2);
iVar3 = cmp.GetVariableObject(iVar2, "Var3");
cmp.SetVariableObjValue(iVar3, "Paul");
i += 1
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-44
API Reference Manual
Parameters:
Returns:
bool This method will return true if the variable was successfully
deleted.
Example:
#------------------------------------------------------------
# Name of File::NodeDeleteVariable.rb
#
# Purpose::
# Provides to the script writer a method to delete a
# variables.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.StartLogging(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM,
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM,
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM,
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
if(prj)
cmp = prj.GetComponent("H1");
if(cmp)
cmp.DeleteVariable( "MyVar");
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method fetches the name of the current node. Projects return project name,
documents use document name, components return instance name, and views return
view names.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::NodeGetName.rb
#
# Purpose::
# This shows how to use the Node GetName() method.
#------------------------------------------------------------
require "AS.API.Share"
strPrjName = "Name of Project : ";
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
strPrjName += prj.GetName();
end
applicationApi..LogScriptInformation(strPrjName,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-46
API Reference Manual
When you have a structure, or array variable these two methods provide access to their
members.
This returns a derefrenced access to the variable object within AS. No interface is directly
provided by these methods. The return value must be used in one of the following
methods to access or change the actual variable objects.
Used to access the actual value contained by the variable object returned above.
These two set the value to the variable object returned above.
Parameters:
Returns:
object This method will return “nil” if an error fetching the object
occurred.
Related Methods:
Example:
#------------------------------------------------------------
# Name of File::NodeGetVariableObject.rb
#
# Purpose:: Get and set the elements to a complex array of
# structures. This expects that the variable
# "MyArStrVar1" had been created using the script
# NodeCreateVariableDefinition.rb.
#------------------------------------------------------------
require "System"
require "AS.API.Share"
i = 0
while (i < 4)
iVar2 = cmp.GetVariableObject(iVar, i);
7-48
API Reference Manual
iVar3 = cmp.GetVariableObject(iVar2, "Var1");
cmp.SetVariableObjValue(iVar3, 5);
iVar3 = cmp.GetVariableObject(iVar2, "Var2");
cmp.SetVariableObjValue(iVar3, 6);
iVar3 = cmp.GetVariableObject(iVar2, "Var3");
cmp.SetVariableObjValue(iVar3, "Change the string");
i += 1
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
When you have access to the variable object this gets its value.
The following methods are used to access the variable object required for parameter one.
Parameters:
Returns:
object This method will return “nil” if an error fetching the object
occurred, otherwise it will return the value that exists within
the variable. This can be anyone of the following data
elements.
7-50
API Reference Manual
LINE_STYLE uint
LINE_THICKNESS uint
LINT long
LREAL double
LWORD ulong
REAL float
SINT sbyte
STRING string
TIME TimeSpan
TIME_OF_DAY DateTime
UDINT uint
UINT uint
ULINT ulong
USINT byte
WORD ushort
WSTRING string
Related Methods:
Example:
#------------------------------------------------------------
# Name of File::NodeGetVariableObjValue.rb
#
# Purpose:: Extract the value from a variable object that
# exists within a complex variable. The variable
# "MyArStrVar1". Thos would have been created
# running the example
# NodeCreateVariableDefinition.rb
#------------------------------------------------------------
require "System"
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-52
API Reference Manual
This method fetches the variable object with using the variable’s name. This will return
the a copy of the data controlled by the variable. If the type is not provided, the return
type will be of the same type stored in the system.
The original syntax required the script writer to provide the type of data that should be
returned by the method.
Parameters:
Returns:
object This method will return “nil” if the object does not exist or the
script writer used the wrong type, otherwise it will return the
object of the variable asked for. It may be one of the
following objects.
Example:
#------------------------------------------------------------
# Name of File::NodeGetVariableValue.rb
#
# Purpose::
# This provides an example of the get variable method.
# This expects that all variables have been created by
# NodeCreateVariable.rb and set by NodeSetVariableValue.rb
# The output has been redirected to the message system
# for validation.
#------------------------------------------------------------
require "AS.API.Share"
asVarType = AS::API::Share::ASAPI_VARTYPES
asMsgType = AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM;
7-54
API Reference Manual
strOut = "Validate the output string includes the current values of
variables\n"
strOut << "MyVarA1 ... MyVarC28 \n"
applicationApi.ChangeAllLogOutputs(asMsgType);
cmp = prj.GetComponent("H1");
applicationApi.LogScriptInformation("=== Original Syntax ===",false);
dValue = cmp.GetVariableValue( "MyVarA0" , asVarType.BOOL);
dValue = cmp.GetVariableValue( "MyVarA1" , asVarType.SINT);
dValue = cmp.GetVariableValue( "MyVarA2" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarA3" , asVarType.DINT);
dValue = cmp.GetVariableValue( "MyVarA4" , asVarType.LINT);
dValue = cmp.GetVariableValue( "MyVarA5" , asVarType.USINT);
dValue = cmp.GetVariableValue( "MyVarA6" , asVarType.UINT);
dValue = cmp.GetVariableValue( "MyVarA7" , asVarType.UDINT);
dValue = cmp.GetVariableValue( "MyVarA8" , asVarType.ULINT);
dValue = cmp.GetVariableValue( "MyVarA9" , asVarType.REAL);
dValue = cmp.GetVariableValue( "MyVarB10" , asVarType.DOUBLE);
dValue = cmp.GetVariableValue( "MyVarB11" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB12" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB13" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB14" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB15" , asVarType.STRING);
dValue = cmp.GetVariableValue( "MyVarB16" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB17" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB18" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarB19" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarC20" , asVarType.STRING);
dValue = cmp.GetVariableValue( "MyVarC21" , asVarType.FLOAT);
dValue = cmp.GetVariableValue( "MyVarC22" , asVarType.FLOAT);
dValue = cmp.GetVariableValue( "MyVarC23" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarC24" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarC25" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarC26" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarC27" , asVarType.INT);
dValue = cmp.GetVariableValue( "MyVarC28" , asVarType.STRING);
7-56
API Reference Manual
When you have access to the variable object or its parent these provide methods to
change their values.
The following methods are used to access the variable object required for parameter one.
Parameters:
varValue The value to set. This value must be of a type that can be
converted to the actual variable on the object. An example
which would fail would be if you provided a long value to be
set on a boolean variable.
Returns:
object This method will return “nil” if an error fetching the object
occurred, otherwise it will return the value that exists within
the variable. This can be anyone of the following data
elements.
WSTRING string
Related Methods:
Example:
#------------------------------------------------------------
7-58
API Reference Manual
# Name of File::NodeSetVariableObjValue.rb
#
# Purpose:: Set the value to a variable within an array and
# structure. The variables "MyStructVariable3 and
# "MyArrayVariable3" are expected to exist. They
# can be created while running the example
# NodeCreateVariableDefinition.rb
#------------------------------------------------------------
require "System"
require "AS.API.Share"
# Set the field "Address 1" using the variable from within
# structure.
iVar2 = cmp.GetVariableObject(iVarStruct, "Address 1");
cmp.SetVariableObjValue(iVar2, "Ted");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method set the object with the name equal to the name provided in the strName
variable with the supplied value. See CreateVariableValue() and GetVariableValue() for
more information on manipulating variable values.
Parameters:
value The value to be used to set the variable. This value has to be
of a type that can be convertibled to the of target variable. As
an example a “long” based value cannot be set to an “short”
based object.
Returns:
bool Will return false if the variable does not exist or could not be
set.
Example:
#------------------------------------------------------------
# Name of File::NodeSetVariableValue.rb
#
# Purpose::
# Provides to the script writer a method to set variables.
# This expects that all the variables have been created
# using NodeCreateVariable.rb
#------------------------------------------------------------
require "AS.API.Share"
asVarType = AS::API::Share::ASAPI_VARTYPES
asMsgType = AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM
strOut = "Not found"
applicationApi.ChangeAllLogOutputs(asMsgType);
prj = applicationApi.GetCurrentProject();
if(prj)
cmp = prj.GetComponent("H1");
7-60
API Reference Manual
if(cmp)
cmp.SetVariableValue( "MyVar" , 32.0);
cmp.SetVariableValue( "MyVarA1" , -33);
cmp.SetVariableValue( "MyVarA2" , -34);
cmp.SetVariableValue( "MyVarA3" , -35);
cmp.SetVariableValue( "MyVarA4" , -36);
cmp.SetVariableValue( "MyVarA5" , 37);
cmp.SetVariableValue( "MyVarA6" , 38);
cmp.SetVariableValue( "MyVarA7" , 39);
cmp.SetVariableValue( "MyVarA8" , 40);
cmp.SetVariableValue( "MyVarA9" , 41.1);
cmp.SetVariableValue( "MyVarB10" , 42.2);
cmp.SetVariableValue( "MyVarB11" , 55);
cmp.SetVariableValue( "MyVarB12" , 55);
cmp.SetVariableValue( "MyVarB13" , 55);
cmp.SetVariableValue( "MyVarB14" , 55);
cmp.SetVariableValue( "MyVarB15" , "Test String");
cmp.SetVariableValue( "MyVarB16" , 0x1A);
cmp.SetVariableValue( "MyVarB17" , 0x1B1B);
cmp.SetVariableValue( "MyVarB18" , 0x1C1C1C1C);
cmp.SetVariableValue( "MyVarB19" , 0x1D1D1D1D);
cmp.SetVariableValue( "MyVarC20" , "Test String 2");
cmp.SetVariableValue( "MyVarC21" , 44.6);
cmp.SetVariableValue( "MyVarC22" , 44.7);
cmp.SetVariableValue( "MyVarC23" , 255);
cmp.SetVariableValue( "MyVarC24" , 5);
cmp.SetVariableValue( "MyVarC25" , 5);
cmp.SetVariableValue( "MyVarC26" , 5);
cmp.SetVariableValue( "MyVarC27" , 5);
cmp.SetVariableValue( "MyVarC28" , "www.simply4.ca");
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method sets the visibility of the object. Dependent on the object this method will
force the visibility of the object when closed.
Parameters:
showType Type of show that will be applied.
Default value is SHOW_TYPE.SHOW.
Returns:
7-62
API Reference Manual
cmp = prj.GetComponent( "REC1" );
if(cmp)
cmp.Show(false);
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7.3 Variable
This section defines how to add, delete or modify variables on Components, Documents
or Projects.
Any node may have a number of attributes that affect behavior. These attributes can be
accessed through a variable object. The variable object supplies a standard set of
methods that can be used to modify these attributes.
asEvent = AS::API::Share::ASAPI_EVENTS
This table represents the list of points in AS’s process that a third-party developer can
hook into. This process entry points table relate to the application. The event column
indicates the attribute that will be supplied to the RegisterEvent() and
UnRegisterEvent() methods. The bypass processing column indicates whether or
not any code can be bypassed if the user indicates this should happen with the correct
return from his script.
7-64
API Reference Manual
7.3.3 Methods
This method sets the component link attribute on the variable to on or off.
Parameters:
toShow True indicates to show the alias of the variable if the variable is
visible.
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarActivateComponentLink.rb
#
# Purpose::
# Turns on/off component linking for the component
#------------------------------------------------------------
require "AS.API.Share"
if(cmp)
var = cmp.GetVariable("#VcLayer");
if(var)
var.ActivateComponentLink(true);
end
end
end
applicationApi.Refresh();
7-66
API Reference Manual
This activates a tooltip related to the component. When a pointer device is placed over
the component the tooltip object will become visible if this attribute of the variable has
been set.
Parameters:
setActive True turns on tool tips for this component. For this to work the
Tooltip attribute on the view ribbon bar also has to be
activated.
Returns:
if(cmp)
var = cmp.GetVariable("#VcLayer");
if(var)
var.ActivateTooltip(true);
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarGetAlias.rb
#
# Purpose::
# Returns the alias of the variable.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
n = "";
if (prj)
cmp = prj.GetComponent( "REC1" );
if(cmp)
var = cmp.GetVariable("#VcLayer");
if(var)
n = var.GetAlias();
end
end
end
applicationApi.LogScriptInformation("[" + n + "]",false);
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-68
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarGetDescription.rb
#
# Purpose::
# Returns the description of the variable.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
n = "";
if (prj)
cmp = prj.GetComponent( "REC1" );
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
n = var.GetDescription();
end
end
end
applicationApi.LogScriptInformation("[" + n + "]",false);
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarGetInternalName.rb
#
# Purpose::
# Returns the internal name of the variable.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
n = "";
if (prj)
cmp = prj.GetComponent( "REC1" );
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
n = var.GetInternalName();
end
end
end
applicationApi.LogScriptInformation("[" + n + "]",false);
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-70
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarGetName.rb
#
# Purpose::
# Returns the name of the variable.
#------------------------------------------------------------
require "AS.API.Share"
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
n = var.GetName();
end
end
end
applicationApi.LogScriptInformation("[" + n + "]",false);
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Interface that will change the name of the variable. This is treated as an internal name,
so after this is set anywhere this is displayed will show this name translated to the
current environment.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarSetName.rb
#
# Purpose::
# Method that will change the name of the variable.
#------------------------------------------------------------
require "AS.API.Share"
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
var.SetName( "Layer2" );
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-72
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarSetAlias.rb
#
# Purpose::
# Method that will change the variables alias.
#------------------------------------------------------------
require "AS.API.Share"
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
var.SetAlias( "Alias Test" );
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This is the method to use to change the text that currently exists for the description of
the component attribute.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarSetDescripton.rb
#
# Purpose::
# Example of changing the description on a component.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if (prj)
cmp = prj.GetComponent( "REC1" );
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
var.SetDescription( "New text" );
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-74
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarSetValue.rb
#
# Purpose::
# Script that will modify the value of component ‘H1’
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if (prj)
cmp = prj.GetComponent( "REC1" );
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
var.SetValue( "P3" );
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
If a variable has a visible representation related to its component, this method can be
used to turn on or off the visibility of this attribute.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarShow.rb
#
# Purpose::
# Makes a variable visible. Expects a component “REC1”
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if (prj)
cmp = prj.GetComponent( "REC1" );
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
var.Show(true);
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-76
API Reference Manual
If a variable is visible and has a visible representation related to its component, this
method can be used to turn on or off the visibility the alias.
Parameters:
toShow True indicates to show the alias of the variable if the variable is
visible.
Returns:
Example:
#------------------------------------------------------------
# Name of File::VarShowAlias.rb
#
# Purpose::
# Makes an alias attribute of a variable, visible or not.
#------------------------------------------------------------
require "AS.API.Share"
if(cmp)
var = cmp.GetVariable( "#VcLayer" );
if(var)
var.Show(true);
var.ShowAlias(true);
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7.4 Application
The application object is the main interface available to Automation Studio™ ’s object
model. This section describes how to access it and how it can be used.
This is used to access the system wide attributes found in Automation Studio™. The
application is the first object to be created and contains all other objects. There will only
be one application object ever created. It can be used as an interface that supplies access
that a user can use to manipulate his environment using scripts.
Whenever an object id of zero is used the user is accessing the application object.
All method calls available to a script are actually being managed by the application
object.
asEvent = AS::API::Share::ASAPI_EVENTS
This table represents the list of points in AS’s process that a third-party developer can
hook into. This process entry points table relate to the application. The event column
indicates the attribute that will be supplied to the RegisterEvent() and
UnRegisterEvent() methods. The bypass processing column indicates whether or
not any code can be bypassed if the user indicates this should happen with the correct
return from his script.
7-78
API Reference Manual
7-80
API Reference Manual
7.4.3 Methods
This interface will add ribbon components to Automation Studio ™’s main ribbon panel.
Any elements that do not already exist will be created. The strings used will be expecting
the string displayed in Automation Studio™.
If developing a script that must work when the language environment changes the script
writer should use the internal name of any elements that already exists in Automation
Studio™ and use the translation method TranslateASElementString(string
internalName) to get the name that will be displayed at runtime.
Parameters:
Returns:
7-82
API Reference Manual
#------------------------------------------------------------
# File::AppAddRibbonCommandUsingDisplayName.rb
#
# Purpose::
# This will show how to add ribbon tabs, groups, and
# commands to Automation Studio.
#------------------------------------------------------------
require "AS.API.Share"
app = applicationApi; # Simplify the expression.
#Creates a ribbon element that when selected will call
#the script “AppResponceTest.rb”
app.AddRibbonCommandUsingDisplayName(
"Tb" , "Gp" , "Run" ,
"Application\\AppResponseTest.rb",
"mycustom2.ico");
str1 = app.TranslateASElementString("#TrHome");
str2 = app.TranslateASElementString("#TrDrawing");
app.AddRibbonCommandUsingDisplayName(
str1, str2, "Run" ,
"Application\\AppResponseTest.rb",
"mycustom2.ico");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
#------------------------------------------------------------
# Name of File::AppResponseTest.rb
#
# Purpose::
# Used by other scripts to show a script responding to a
# an event.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Windows.Forms,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'
strMsg = "Response From Action"
System::Windows::Forms::MessageBox.show strMsg
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Allow Automation Studio™ to close down, with the option to save the files currently in
memory. This must be called from a registered event and not from within an object.
Parameters:
Returns:
Example:
#-------------------------------------------------------------
# File::AppCloseApplication.rb
#
# Purpose::
# When called this script will shut down a currently
# running Automation Studio with saving modifications.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.CloseApplication(true)
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-84
API Reference Manual
Parameters:
Returns:
Warning:
This method must be called from a registered event from the application frame.
It can’t be called from an event from an object within the project that is being
closed.
Example:
#-------------------------------------------------------
# Name of File::AppCloseProject.rb
#
# Purpose::
# Demonstrates how to use the application objects
# CloseProject(). This will close project P2 if
# open.
#
#-------------------------------------------------------
require "AS.API.Share"
applicationApi.CloseProject("P2",true);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Get the document using its name from within a project that is in memory.
Parameters:
Returns:
Example:
#-------------------------------------------------------
# Name of File::AppGetDocument.rb
#
# Purpose::
# Demonstrates how to use the base object’s
# GetDocument() method.
# This expects a project “P1” and a document “D1” to
# have been previously loaded.
#-------------------------------------------------------
require "AS.API.Share"
doc = applicationApi.GetDocument("P1","D1");
if(doc)
doc.Maximize();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-86
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppGetEnvString.rb
#
# Purpose:
# This ruby script demonstrates the application objects
# GetEnvString method.
#------------------------------------------------------------
require "AS.API.Share"
msg = "The open file dialog used the following directory ["
msg << applicationApi.GetEnvString("DefaultProjectDirectory")
msg << "]"
applicationApi.LogScriptInformation(msg,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method returns the currently set directory to place project files
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppGetProjectHomeDirectory.rb
#
# Purpose::
# Demonstrates how to use the application method
# AppGetProjectHomeDirectory()
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.LogScriptInformation(msg,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-88
API Reference Manual
Parameters:
Returns:
IProjectApi Project object, which will be set to “nil” if it does not exist.
Example:
#------------------------------------------------------------
# Name of File::AppGetCurrentProject.rb
#
# Purpose::
# Demonstrates how to use AppGetCurrentProject.rb
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetCurrentProject();
if(prj)
strPrjName = prj.GetName();
applicationApi.LogScriptInformation(strPrjName,false);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This provides access to a project which is currently in memory using the project’s name.
Parameters:
Returns:
IProjectApi The project object, which will be set to “nil” if it does not exist.
Example:
#------------------------------------------------------------
# Name of File::AppGetProject.rb
#
# Purpose::
# Demonstrates how to use the method GetProject on the
# application object.
# Warning::
# Expects that a project with the name Test.prx is in
# memory.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProject("P1");
if(prj)
strPrjName = prj.GetName();
applicationApi.LogScriptInformation(strPrjName,false);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-90
API Reference Manual
This method allows the script builder to access the names of the directories that are
searched first. The following lists provides the default set of searches that are used to
find scripts. This method returns a string where each directory is separated by “;”. All
the following strings may be made up of multiple directories.
The script directories set be the application option “Custom Scripts Location”
The script directories set by the application option “Enterprise Scripts Location”
AS’s common application data path plus the sub directory “Scripts”.
The script directory is automatically set if Automation Studio™ is started using the
parameter /SCRIPTS:<script directory>.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppGetScriptDirectory.rb
#
# Purpose::
# This ruby script demonstrates fetching the script
# directory.
#------------------------------------------------------------
7-92
API Reference Manual
This will force the dialog identifier defined by the id provided to be hidden. The runtime
version of AS can’t change the visibility of the message output, the graphical library, or
the variables dialog.
Parameters:
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_LAYERS
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_OUTPUT
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PROJECT_EXPLORER
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_LIBRARY
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PLOTTER
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PLOTTER_ELECTROTECHNIQUE
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_STATUS_BAR
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_VARIABLES
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppHideDialog.rb
# Purpose::
# Make a dialogs invisible.
#------------------------------------------------------------
require "AS.API.Share"
mthd = AS::API::Share::ASAPI_METHODS
nlogType = AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM
applicationApi.ChangeAllLogOutputs(nlogType);
applicationApi.HideDialog(mthd.MTHD_SHOWDLG_LAYERS);
applicationApi.HideDialog(mthd.MTHD_SHOWDLG_PROJECT_EXPLORER);
applicationApi.HideDialog(mthd.MTHD_SHOWDLG_LIBRARY);
applicationApi.HideDialog(mthd.MTHD_SHOWDLG_VARIABLES);
applicationApi.HideDialog(mthd.MTHD_SHOWDLG_OUTPUT);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-94
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppHideRibbon.rb
#
# Purpose::
# Demonstrates how to use the method HideRibbon on the
# application object.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.HideRibbon();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This loads the project defined by szProjectName. If the project already exists it will be
made active. This expects either the full path or that the project exist in the current
project directory.
Parameters:
If the path begins with a drive letter or “\\” it will be interpreted as the full
path name. No other rule will be applied.
Otherwise the first of the following rules to find the file will be used.
The default project directory. This is the current directory set by the last call to
open file dialog.
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppLoadProject.rb
#
# Purpose::
# This example will load a project with the name
# “ApiTest.prx”
7-96
API Reference Manual
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.LoadProject("ApiTest.prx");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Refresh all projects, dialogs, and documents within an application. Points used by the
interface are of type System::Drawing::Point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppRefresh.rb
#
# Purpose::
# Shows how a script writer can refresh all elements in an.
# application.
#------------------------------------------------------------
require "AS.API.Share"
7-98
API Reference Manual
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method activates a particular or many views denoted by the string szView. This
expects the view to already be loaded in memory.
Parameters:
<<project>,<document >,<view>>[:<<project>,<document>,<view>>]
The view name may use the view number instead of the string.
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppSelectView.rb
#
# Purpose:
# This ruby script demonstrates the application objects
# SelectView method.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.SelectView("P3,D3,View2");
applicationApi.SelectView("P3,D1,3:P2,D1,View3:P3,D1,1");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-100
API Reference Manual
This method allows the script where exported files will be saved.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppSetExportPath.rb
#
# Purpose::
# Demonstrates how to use the application method
# SetExportPath()
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.SetExportPath( "C:\\Temp" );
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
prj.Export( "SVG" );
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method allows the script builder to send a number of UI events to Automation
Studio™. These are specifically good if you are replacing ribbon buttons with your own
ribbon.
Parameters:
The event to be sent. It can be any of the following. They will only produce valid results if
the display can respond to the event when it is sent.
ID_SIMULATION_PROJECT_START
ID_SIMULATION_DIAGRAM_START
ID_SIMULATION_NORMAL
ID_SIMULATION_STEP
ID_SIMULATION_SLOW_MOTION
ID_SIMULATION_PAUSE
ID_SIMULATION_STOP
ID_ZOOM_DYNAMIC
ID_ZOOM_PREVIOUS
ID_ZOOM_PAGE
ID_ZOOM_WINDOW
ID_ZOOM_PLUS
ID_ZOOM_MINUS
ID_ZOOM_COMPONENTS
ID_CLEAR_MESSAGE_WINDOW
ID_TROUBLESHOOT_ HYDRAULIC
ID_TROUBLESHOOT_GAUGE
ID_TROUBLESHOOT_THERMOMETER
ID_TROUBLESHOOT_MULTIMETER
ID_TROUBLESHOOT_DISCONNECT_WIRE
ID_TROUBLESHOOT_RECONNECT_WIRE
ID_TROUBLESHOOT_DISCONNECT_LINE
ID_TROUBLESHOOT_RECONNECT_LINE
ID_TROUBLESHOOT_REPAIR
ID_TROUBLESHOOT_OPEN_HYDRAULIC_DETECTION_TOOL
ID_TROUBLESHOOT_EDIT_FAILURE
ID_WINDOW_TILE_HORZ
ID_WINDOW_TILE_VERT
ID_WINDOW_CASCADE
ID_PRJ_BACK
7-102
API Reference Manual
ID_PRJ_FORWARD
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppSendUserInterfaceMessage.rb
#
# Purpose::
# This tests how the script builder can launch events
# that the user interface can respond to.
#------------------------------------------------------------
require "AS.API.Share"
idMessage = AS::API::Share::IdMessage
applicationApi.SendUserInterfaceMessage(idMessage.ID_TROUBLESHOOT_DIS
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method allows the script builder to specify where project files will be located if no
path has been specified. If this variable is not set, the following search will take place:
Current Directory;
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppSetProjectHomeDirectory.rb
#
# Purpose::
# Demonstrates how to use the application method
# AppSetProjectHomeDirectory(). This expects that
# C:\Temp\A1.prx exists
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.SetProjectHomeDirectory("C:\\Temp");
applicationApi.LoadProject("P1.prx");
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-104
API Reference Manual
This method removes or restores a specific application ribbon panel using display names
of the ribbon objects to be affected. Ribbons elements created by the script writer are
only known by the displayed name provided.
When the panel is restored it is restored to the end of the ribbon bar.
If developing a script that must work when the language environment changes, the script
writer should use the internal name of any elements that already exists in Automation
Studio™ and use the translation method TranslateASElementString(string
internalName) on the name that will be displayed at runtime.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# File:: AppSetRibbonPanelVisibilityUsingDisplayName.rb
# Purpose::
# This will show how to add ribbon tabs and groups to
# Automation Studio.
#------------------------------------------------------------
require "AS.API.Share"
app = applicationApi;
str1 = app.TranslateASElementString("#TrEdit");
str2 = app.TranslateASElementString("#TrArrange");
7-106
API Reference Manual
This method hides or restores a specific application ribbon tab using the displayed name
of the ribbon object to be affected. Client ribbons are only known by their displayed
name.
If developing a script that must work when the language environment changes the script,
the writer should use the internal name of the required tab and use the translation
method TranslateASElementString(string internalName) to get the name
that will be displayed at runtime.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# File:: AppSetRibbonTabVisibilityUsingDisplayName.rb
#
# Purpose::
# This will make a particular ribbon tab invisible
#------------------------------------------------------------
require "AS.API.Share"
app = applicationApi;
str1 = app.TranslateASElementString("#TrTools");
#Make visible our custom ribbon tab and panel
app.SetRibbonTabVisibilityUsingDisplayName(str1, false);
app.SetRibbonTabVisibilityUsingDisplayName("Tb", false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-108
API Reference Manual
This will force the dialog defined by the ID provided to be shown. The runtime version of
Automation Studio™ can’t change the visibility of the message output, the graphical
library, or the variables dialog.
Parameters:
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PLOTTER_ELECTROTECHNIQUE
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_STATUS_BAR
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_VARIABLES
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppShowDialog.rb
# Purpose::
# Make a dialogs visible.
#------------------------------------------------------------
require "AS.API.Share"
mthd = AS::API::Share::ASAPI_METHODS
nlogType = AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM
applicationApi.ChangeAllLogOutputs(nlogType);
applicationApi.ShowDialog(mthd.MTHD_SHOWDLG_LAYERS);
applicationApi.ShowDialog(mthd.MTHD_SHOWDLG_PROJECT_EXPLORER);
applicationApi.ShowDialog(mthd.MTHD_SHOWDLG_LIBRARY);
applicationApi.ShowDialog(mthd.MTHD_SHOWDLG_VARIABLES);
applicationApi.ShowDialog(mthd.MTHD_SHOWDLG_OUTPUT);
7-110
API Reference Manual
This method runs a simulation in slow motion and uses a factor between 2 and 25. The
larger the number is, the slower is the simulation.
Parameters:
iFactor Factor used to slow the simulation down by. A value between 1
and 25 with 25 being the slowest simulation.
Returns:
Example:
#------------------------------------------------------------
# Name of File::Application\AppSimulateInSlowMotion.rb
#
# Purpose::
# This starts a simulation using a different update rate.
#------------------------------------------------------------
require "AS.API.Share"
asVarType = AS::API::Share::ASAPI_VARTYPES
applicationApi.ChangeAllLogOutputs(
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
applicationApi.SimulateInSlowMotion(8);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method starts the currently selected set of documents and layers to be simulated.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::StartSimulationExample.rb
#
# Purpose::
# This example will start the system simulating.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.StartSimulation()
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-112
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::StoptSimulation.rb
#
# Purpose::
# This example will stop the simulation.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.StopSimulation()
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This will force the dialog defined by the id provided to be shown if hidden and hidden if
shown. The runtime version of AS can’t change the visibility of the message output, the
graphical library, or the variables dialog.
Parameters:
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_LAYERS
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_OUTPUT
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PROJECT_EXPLORER
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_LIBRARY
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PLOTTER
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_PLOTTER_ELECTROTECHNIQUE
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_STATUS_BAR
AS::API::Share::ASAPI_METHODS.MTHD_SHOWDLG_VARIABLES
Returns:
Example:
#------------------------------------------------------------
# Name of File::AppShowDialog.rb
# Purpose::
# Make a dialogs visible.
#------------------------------------------------------------
require "AS.API.Share"
mthd = AS::API::Share::ASAPI_METHODS
nlogType = AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM
applicationApi.ChangeAllLogOutputs(nlogType);
applicationApi.ToggleDialog(mthd.MTHD_SHOWDLG_LAYERS);
applicationApi.ToggleDialog(mthd.MTHD_SHOWDLG_PROJECT_EXPLORER);
applicationApi.ToggleDialog(mthd.MTHD_SHOWDLG_LIBRARY);
applicationApi.ToggleDialog(mthd.MTHD_SHOWDLG_VARIABLES);
applicationApi.ToggleDialog(mthd.MTHD_SHOWDLG_OUTPUT);
7-114
API Reference Manual
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
String If the string is not found in the language database the original
name will be returned.
Example:
#------------------------------------------------------------
# Name of File::AppTranslateASElementString.rb
#
# Purpose::
# Shows how to access the translated name of an Automation
# Studio component using an internal name.
#
#------------------------------------------------------------
require "AS.API.Share"
app = applicationApi;
internalName = "_AS_Dynamic Measurements";
str = app.TranslateASElementString(internalName);
applicationApi.LogScriptInformation(str,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-116
API Reference Manual
7.5 Project
This is used to access the attributes that are managed by an Automation Studio™ project.
7.5.1.1 Access
int GetProject();
This method returns the project identifier that initiated the current event. If no project
initiated the event then this will return “-1”. A project will exist if a project that initiated
the event or a child or grandchild etc... initiated the event.
The second method to find a project is to navigate through the project children of the
application.
nCnt = applicationApi.GetChildCount(asTid.PROJECT_API);
nIdx = 0
while (nIdx < nCnt) do
pPrj=applicationApi.GetNthChild(nIdx,asTid.PROJECT_API);
… # Then you use the project object.
nIdx += 1
end
This table represents the list of points in Automation Studio™’s process that a third-party
developer can hook into dependent on a variable on the project. This process entry points
table relates to the project object. The event column indicates the variable that can be
set and that will be tested when the event occurs. The bypass processing column
indicates whether or not any code can be bypassed if the user indicates this should
happen with the correct return from his script.
7-118
API Reference Manual
7.5.3 Methods
This method closes the project represented by the object. This will not save the project if
modified. Use the CloseProject() from the application object if this is required.
Parameters:
Returns:
Warning:
This method must be called from a registered event from the application frame. It can’t
be called from an event from an object within the project that is being closed.
Example:
#-------------------------------------------------------
# Name of File::PrjCloseProject.rb
#
# Purpose::
# Demonstrates how to use the projects CloseProject()
# method.
#-------------------------------------------------------
require "AS.API.Share"
7-120
API Reference Manual
This method exports all documents, within the project, selected for export to the file type
supplied. This will places the files in the file export directory set by the method
SetExportPath(string pathName)on the application object. The following
naming convention will be used.
In the case of a .pdf, only one file will be created using the following naming convention.
<project name>.pdf
Parameters:
type Type of file to be saved to. Can be one of dxf, pdf, svg, or tiff.
Returns:
Example:
#--------------------------------------------------------
# Name of File::PrjExport.rb
#
# Purpose::
# Demonstrates the use of the method Export()
#--------------------------------------------------------
require "AS.API.Share"
applicationApi.SetExportPath( "C:\\temp" );
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
prj.SetToBeExported(true);
prj.Export( "svg" );
prj.Export( "dxf" );
prj.Export( "xml" );
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-122
API Reference Manual
This method gets the component within the project that has a component identifier equal
to the one provided in the parameter.
Parameters:
Returns:
Example:
#-------------------------------------------------------
# Name of File::PrjGetComponent.rb
#
# Purpose::
# Demonstrates how to use the GetComponent() method.
# This expects a component with the supplied ID".
#-------------------------------------------------------
require "AS.API.Share"
This method gets the document using its name from within a project that is in memory.
Parameters:
Returns:
Example:
This example expects that the project containing the document has already been loaded.
#-------------------------------------------------------
# Name of File::PrjGetDocument.rb
#
# Purpose::
# Demonstrates how to use the GetDocument() method.
# This expects a document with the name "D1" exists.
#-------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-124
API Reference Manual
Parameters:
Returns:
Example:
This example expects that the project containing the document has already been loaded.
#-------------------------------------------------------
# Name of File::PrjGetLanguage.rb
#
# Purpose::
# Tests the method that extracts the current language
# used from the document.
#-------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-126
API Reference Manual
This method saves the object’s project. If saveAs is set to true, the method will query
the user with the file “save as” dialog.
Parameters:
saveAs True and the “save as” dialog will pop up.
Returns:
Example:
#-------------------------------------------------------
# Name of File::PrjSaveProject.rb
#
# Purpose::
# Demonstrates how to use the projects SaveProject
# method.
#-------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method sets the current language for text objects with translation enabled.
Parameters:
7-128
API Reference Manual
Returns:
Example:
This example expects that the project containing the document has already been loaded.
#-------------------------------------------------------
# Name of File::PrjSetLanguage.rb
#
# Purpose:
# This ruby script demonstrates the project objects
# SetLanguage method. For this to work the language
# used has to have been added to the projects
# Properties translation language tab.
#------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
7-130
API Reference Manual
Example:
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
if (prj)
if($simCurMode == 1)
prj.SetSimulationMode(AS::API::Share::SIM_MODE.Selected);
elsif($simCurMode == 2)
prj.SetSimulationMode(AS::API::Share::SIM_MODE.Document);
else
prj.SetSimulationMode(AS::API::Share::SIM_MODE.Project);
$simCurMode = 0;
end
$simCurMode += 1;
end
applicationApi.StartSimulation();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
#------------------------------------------------------------
# Name of File::PrjSetSimValues.rb
#
# Purpose::
# Used to initialize and keep global variable for the
# project scripts.
#------------------------------------------------------------
require "AS.API.Share"
$simCurMode = 1;
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method sets the export flag on all documents within a project.
Parameters:
bSet The export document flag is set to this value. Next time the
export process is run, the exportation of each document will be
dependent on this flag.
Returns:
Example:
#--------------------------------------------------------
# Name of File::PrjSetToBeExported.rb
#
# Purpose::
# Demonstrates the use of the method SetToBeExported
#--------------------------------------------------------
require "AS.API.Share"
applicationApi.SetExportPath( "C:\\temp" );
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
prj.SetToBeExported(true);
prj.Export( "svg" );
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-132
API Reference Manual
Parameters:
Returns:
Example:
#-------------------------------------------------------
# Name of File::PrjSimulateSnapshot.rb
#
# Purpose::
# Demonstrates how to use the project’s
# SimulateSnapshot(..) method.
#-------------------------------------------------------
require "AS.API.Share"
snapshotName = "Simulation1";
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This sets a current list of documents within the project that will be simulated when
simulation starts. The current mode will also be modified to simulate only selected
documents. Any documents omitted from the list will not be simulated.
Parameters:
Returns:
Example:
#-------------------------------------------------------
# Name of File::PrjSimulationSelection.rb
#
# Purpose::
# Demonstrates how to use the project’s
# SimulationSelection(..) method.
#-------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
if (prj)
prj.SimulationSelection("D1,D2");
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-134
API Reference Manual
Parameters:
Returns:
Example:
#-------------------------------------------------------
# Name of File::PrjTakeManualSnapshot.rb
#
# Purpose::
# Demonstrates how to use the project’s
# TakeManualSnapshot(..) method.
#-------------------------------------------------------
require "AS.API.Share"
snapshotName = "Simulation1";
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7.6 Document
int GetDocument();
This method returns the document identifier that initiated the current event. If no
document initiated the event then this will return “-1”. A document will exist if a
document or a child or grandchild initiated the event.
The second method to find a document is to navigate through the document children of a
project.
nCnt = projectApi.GetChildCount(asTid.DOCUMENT_API);
nIdx = 0
while (nIdx < nCnt) do
pPrj = projectApi.GetNthChild(nIdx,
asTid.PROJECT_API);
… # Then you use the project object.
nIdx += 1
end
7-136
API Reference Manual
7.6.2 Methods
This method adds an arc to an image. Points used by the interface are of type
System::Drawing::Point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddArc.rb
#
# Purpose::
# Shows how a script writer can add a Arc to a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptMin = System::Drawing::Point.new;
ptMax = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
ptMin.X = 0;
ptMin.Y = 0;
ptMax.X = 400;
ptMax.Y = 400;
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-138
API Reference Manual
Parameters:
szPath Path to the object within the current system catalog structure.
szOption Option.
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddCatalogComponent.rb
#
# Purpose::
# Shows how a script writer can add a component from a
# catalog.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
st=doc.AddCatalogComponent(ptOrg,"C:\\ASExamples\\HydraforceIDesign_1.ctg",
20","");
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-140
API Reference Manual
Alternate Syntax
This provides to the script writer a method to connect components to each other with a
connector. If the second component or both components is/are not supplied, it/they will
be replaced by nodes.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddConnection.rb
#
# Purpose::
# Add a connectors between two component ports. This expects
# the two components H2 and H3 to exist in the current
# document.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
applicationApi.ChangeAllLogOutputs(
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
doc = applicationApi.GetCurrentDocument();
prj = applicationApi.GetCurrentProject();
ptValue1 = cmp1.GetDocRelativePortPosition(2);
ptValue2 = cmp2.GetDocRelativePortPosition(2);
ptOrg.X = ptValue1.X;
ptOrg.Y = ptValue1.Y + 100; listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 150; listVertex.Add(ptOrg);
ptOrg.Y = ptValue2.Y - 100; listVertex.Add(ptOrg);
ptOrg.X = ptValue2.X; listVertex.Add(ptOrg);
cmpAdded = doc.AddConnection("H2",2,"H3",2,listVertex);
cmpName = cmpAdded.GetName();
7-142
API Reference Manual
listVertex = applicationApi.CreatePointList();
ptValue1 = cmp1.GetDocRelativePortPosition(1);
ptValue2 = cmp2.GetDocRelativePortPosition(1);
ptOrg.X = ptValue1.X;
ptOrg.Y = ptValue1.Y - 100; listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 200; listVertex.Add(ptOrg);
ptOrg.Y = ptValue2.Y + 100; listVertex.Add(ptOrg);
ptOrg.X = ptValue2.X; listVertex.Add(ptOrg);
cmpAdded = doc.AddConnection("H2","A","H3","A",listVertex);
cmpName = cmpAdded.GetName();
listVertex2 = applicationApi.CreatePointList();
ptValue1 = cmp1.GetDocRelativePortPosition(3);
ptOrg.X = ptValue1.X - 300;
ptOrg.Y = ptValue1.Y; listVertex2.Add(ptOrg);
ptOrg.X = ptOrg.Y - 200; listVertex2.Add(ptOrg);
ptOrg.Y = ptOrg.X - 300; listVertex2.Add(ptOrg);
cmpAdded = doc.AddConnection("H2","C","","",listVertex2);
cmpName = cmpAdded.GetName();
listVertex = applicationApi.CreatePointList();
ptValue1 = cmp1.GetDocRelativePortPosition(2);
ptOrg.X = ptValue1.X;
ptOrg.Y = ptValue1.Y + 300; listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 200; listVertex.Add(ptOrg);
ptOrg.Y = ptOrg.Y - 100; listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 100; listVertex.Add(ptOrg);
cmpAdded = doc.AddConnection(listVertex);
cmpName = cmpAdded.GetName();
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method adds an ellipse to an image. Points used by the interface are of type
System::Drawing::Point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddEllipse.rb
#
# Purpose::
# Shows how a script writer can add an ellipse to a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptMin = System::Drawing::Point.new;
ptMax = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 300;
7-144
API Reference Manual
ptMin.X = 0;
ptMin.Y = 0;
ptMax.X = 200;
ptMax.Y = 500;
doc.AddEllipse(ptOrg, ptMin, ptMax);
doc.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
szPath Path to the object within the current system library structure.
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddLibraryComponent.rb
#
# Purpose::
# Shows how a script writer can add a component from the
# system libraray.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
ptOrg = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
st = doc.AddLibraryComponent(ptOrg,"Hydraulic\\Flow Lines
and Connections\\Vertical Flexible Line","");
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-146
API Reference Manual
This method adds a line to an image. Points used by the interface are of type
System::Drawing::Point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddLine.rb
#
# Purpose::
# Shows how a script writer can add a line to a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptFirst = System::Drawing::Point.new;
ptLast = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
7-148
API Reference Manual
ptFirst.X = 0;
ptFirst.Y = 0;
ptLast.X = 400;
ptLast.Y = 400;
doc.AddLine(ptOrg,ptFirst,ptLast);
ptFirst.X = 700;
doc.AddLine(ptOrg,ptFirst,ptLast);
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method adds a set of polygons to an image. This allows the script builder to add
holes to polygons. Points used by the interface are of type
System::Drawing::Point.
Parameters:
listPoints List of points. The API supplies a method to create a point list
for this method, see IApplicationApi
CreatePointList().
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddNestedPolygons.rb
#
# Purpose::
# Shows how a script writer can add nested polygons also
# known as PolyPolygons.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
System::Drawing::Point.new;
7-150
API Reference Manual
listVertex = applicationApi.CreatePointList();
#Polygon 1
ptOrg.X = 0;
ptOrg.Y = 500;
listVertex.Add(ptOrg);
ptOrg.X = 500;
ptOrg.X = ptOrg.X + 100;
listVertex.Add(ptOrg);
ptOrg.Y = ptOrg.Y + 100;
listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 100;
listVertex.Add(ptOrg);
ptOrg.Y = ptOrg.Y + 100;
listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 100;
listVertex.Add(ptOrg);
ptOrg.Y = ptOrg.Y + 300;
listVertex.Add(ptOrg);
#Polygon 2
ptOrg.X = 300;
ptOrg.Y = 600;
listVertex.Add(ptOrg);
ptOrg.X = 400;
ptOrg.X = ptOrg.X + 100;
listVertex.Add(ptOrg);
ptOrg.Y = ptOrg.Y + 100;
listVertex.Add(ptOrg);
ptOrg.X = ptOrg.X + 100;
listVertex.Add(ptOrg);
ptOrg.Y = ptOrg.Y + 120;
listVertex.Add(ptOrg);
ptOrg.X = 800;
ptOrg.Y = 400;
listCounts = applicationApi.CreateIntList();
listCounts.Add(7);
listCounts.Add(5);
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-152
API Reference Manual
This method adds a polygon to an image. Points used by the interface are of type
System::Drawing::Point.
Parameters:
listPoints List of points. The API supplies a method to create a point list
for this method. see IApplicationApi
CreatePointList().
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddPolyline.rb
#
# Purpose::
# Shows how a script writer can add a polyline to a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-154
API Reference Manual
This method adds a rectangle to an image. Points used by the interface are of type
System::Drawing::Point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddRectangle.rb
#
# Purpose::
# Shows how a script writer can add a rectangle to
# a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptMin = System::Drawing::Point.new;
ptMax = System::Drawing::Point.new;
ptOrg.X = 500;
doc.AddRectangle(ptOrg,ptMin,ptMax);
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-156
API Reference Manual
This method adds a spline also known as a curve to an image. Points used by the
interface are of type System::Drawing::Point.
Parameters:
listPoints List of points. The API supplies a method to create a point list.
For this method, see IApplicationApi
CreatePointList().
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddSpline.rb
#
# Purpose::
# Shows how a script writer can add a spline to a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
listCtrlPoints = applicationApi.CreatePointList();
ptOrg.X = 520;
ptOrg.Y = 920;
listCtrlPoints.Add(ptOrg)
ptOrg.X = 540;
ptOrg.Y = 520;
listCtrlPoints.Add(ptOrg)
ptOrg.X = 620;
ptOrg.Y = 500;
listCtrlPoints.Add(ptOrg)
ptOrg.X = 580;
ptOrg.Y = 560;
listCtrlPoints.Add(ptOrg)
ptOrg.X = 620;
ptOrg.Y = 640;
listCtrlPoints.Add(ptOrg)
ptOrg.X = 660;
ptOrg.Y = 640;
listCtrlPoints.Add(ptOrg)
ptOrg.X = 800;
ptOrg.Y = 1800;
doc.AddSpline(ptOrg,listVertex,listCtrlPoints);
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-158
API Reference Manual
This adds a bounded MTEXT object to the document. Points used by the interface are of
type System::Drawing::Point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocAddText.rb
#
# Purpose::
# Shows how a script writer can add text to a document.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(doc)
ptOrg = System::Drawing::Point.new;
ptMin = System::Drawing::Point.new;
ptMax = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
ptMin.X = 0;
ptMin.Y = 0;
ptMax.X = 400;
ptMax.Y = 400;
doc.AddText("The String",ptOrg,ptMin,ptMax,24,24,"Arial");
doc.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-160
API Reference Manual
Parameters:
“View2” = “2”
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocCloseView.rb
#
# Purpose::
# This method closes a view with the name view2 in
# the current document.#
#------------------------------------------------------------
require "AS.API.Share"
This method creates a view in the current document if the view does not already exist. If
the view already exists, it will be selected.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocCreateView.rb
#
# Purpose::
# This shows how to create a new view.
#------------------------------------------------------------
require "AS.API.Share"
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
view = doc.CreateView("V1");
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-162
API Reference Manual
Parameters:
standards = applicationApi.GetConstantOptionStrings();
standards.k_VdPageSetupStandard;
standards.k_VdMapLocatorStandard;
standards.k_VdReferenceStandard;
standards.k_VdDimensioningStandard;
standards.k_VdDrawingToolsStandard;
standards.k_VdFluidStandard;
standards.k_VdHydraulicStandard;
standards.k_VdPneumaticStandard;
standards.k_VdElectrotechnicalStandard;
standards.k_VdOneLineStandard;
standards.k_VdPanelLayoutStandard;
standards.k_VdSFCStandard;
standards.k_VdLadderLogicStandard;
standards.k_VdElectricalStandard;
standards.k_VdDigitalElectronicStandard;
standards.k_VdConnectionDiagramStandard;
Returns:
Example:
if(doc)
st = doc.GetStandardName(pageSetup);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-164
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::HideAllLayers.rb
#
# Purpose::
# Hides all layers in the current document
#------------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method sets the frame of the first view of the document to use the entire window
space.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocMaximize.rb
#
# Purpose::
# This maximizes the current document.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-166
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocMinimize.rb
#
# Purpose::
# This minimizes the current document.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
This method searches and returns the view object related to the document.
Parameters:
Returns:
IViewApi The view object. Null will be returned if the view does not
exist.
Example:
#------------------------------------------------------------
# Name of File::DocGetView.rb
#
# Purpose::
# To shows an implementation of the documents GetView method.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
7-168
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocHideAllLayers.rb
#
# Purpose::
# This shows how to use a documents HideAllLayers method.
#------------------------------------------------------------
require "AS.API.Share"
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocRefresh.rb
#
# Purpose::
# Shows how a script writer can refresh a document. This
# script adds an arc and then refreshes the image.
#
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
ptOrg = System::Drawing::Point.new;
ptMin = System::Drawing::Point.new;
ptMax = System::Drawing::Point.new;
ptOrg.X = 500;
ptOrg.Y = 500;
ptMin.X = 0;
ptMin.Y = 0;
ptMax.X = 400;
ptMax.Y = 400;
doc.AddArc(ptOrg, ptMin, ptMax, 90, 180);
doc.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-170
API Reference Manual
Parameters:
Returns:
Example:
7-172
API Reference Manual
#------------------------------------------------------------
# Name of File::SetSimulateAllLayers.rb
#
# Purpose::
# This search for all documents currently loaded and
# sets the simulation flag to false on any layers found
#------------------------------------------------------------
require "AS.API.Share"
iCnt = applicationApi.GetChildCount(1);
i = 0
until i == iCnt
prj = applicationApi.GetNthChild(i, 1);
iCnt2 = prj.GetChildCount(2);
j = 0
until j == iCnt2
doc = prj.GetNthChild(j, 2);
doc.SetSimulateAllLayers(false);
j += 1
end
i += 1
end
applicationApi.StartSimulation();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method sets the simulation attribute to true on any layers that match the provided
list. When a project is saved and reopened in a different language environment the layer
names do not change so scripts can be written with these names.
Parameters:
Returns:
Example:
7-174
API Reference Manual
#------------------------------------------------------------
# Name of File::SetSimulateLayers.rb
#
# Purpose::
# This search for all documents currently loaded and
# sets the simulation flag to false on any layers found
# that match the supplied list.
#------------------------------------------------------------
require "AS.API.Share"
iCnt = applicationApi.GetChildCount(1);
i = 0
until i == iCnt
prj = applicationApi.GetNthChild(i, 1);
iCnt2 = prj.GetChildCount(2);
j = 0
until j == iCnt2
doc = prj.GetNthChild(j, 2);
doc.SetSimulateLayers("Layer 3,Layer 4",false);
doc.SetSimulateLayers("Layer 1,Layer 2",true);
j += 1
end
i += 1
end
applicationApi.StartSimulation();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
standards = applicationApi.GetConstantOptionStrings();
standards.k_VdPageSetupStandard;
standards.k_VdMapLocatorStandard;
standards.k_VdReferenceStandard;
standards.k_VdDimensioningStandard;
standards.k_VdDrawingToolsStandard;
standards.k_VdFluidStandard;
standards.k_VdHydraulicStandard;
standards.k_VdPneumaticStandard;
standards.k_VdElectrotechnicalStandard;
standards.k_VdOneLineStandard;
standards.k_VdPanelLayoutStandard;
standards.k_VdSFCStandard;
standards.k_VdLadderLogicStandard;
standards.k_VdElectricalStandard;
standards.k_VdDigitalElectronicStandard;
standards.k_VdConnectionDiagramStandard;
Returns:
Example:
7-176
API Reference Manual
#------------------------------------------------------------
# Name of File::DocSetStandard.rb
#
# Purpose::
# Allows a script writer to change the standard of a document
#------------------------------------------------------------
require "AS.API.Share"
if(doc)
st = doc.SetStandard(pageSetup,"ISO A3");
applicationApi.Refresh();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
bSet The export document flag is set to this value. Next time the
export process is run on its project, the exportation of this
document will depend on this flag.
Returns:
Example:
#--------------------------------------------------------
# Name of File::DocSetToBeExported.rb
#
# Purpose::
# Demonstrates the use of the documents method
# SetToBeExported()
#--------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
prj.SetToBeExported(false);
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
if(doc)
doc.SetToBeExported(true);
end
prj.Export("svg");
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-178
API Reference Manual
This will turn on or off the interface that allows a user to zoom or pan the primary view
of the document.
Parameters:
bPan True: allows a user to zoom and pan the primary view.
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocSetPanAndZoom.rb
#
# Purpose:
# Demonstrates the use of the document objects method
# SetPanAndZoom().
#------------------------------------------------------------
require "AS.API.Share"
Show the primary view of a document, first view in the array of views.
Parameters:
bShow Optional, default is true which will make the primary view
visible.
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocShow.rb
#
# Purpose::
# Shows the primary view of a document.
#------------------------------------------------------------
require "AS.API.Share"
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-180
API Reference Manual
Show all views within the document. the set of views supplied in the list.
Parameters:
bShow Optional, default is true which will make the primary view
visible.
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocShowAllViews.rb
#
# Purpose::
# Shows all views within a document.
#------------------------------------------------------------
require "AS.API.Share"
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method shows the set of layers supplied in the layer list szLayerList.
Parameters:
Returns:
Example:
7-182
API Reference Manual
#------------------------------------------------------------
# Name of File::DocShowLayers.rb
#
# Purpose::
# This search for all documents currently loaded and
# shows/hides any layers found that match the supplied list.
#------------------------------------------------------------
require "AS.API.Share"
iCnt = applicationApi.GetChildCount(1);
i = 0
until i == iCnt
prj = applicationApi.GetNthChild(i, 1);
iCnt2 = prj.GetChildCount(2);
j = 0
until j == iCnt2
doc = prj.GetNthChild(j, 2);
doc.ShowLayers("Default Layer,Layer 2,Layer 4",true);
j += 1
end
i += 1
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
7-184
API Reference Manual
#------------------------------------------------------------
# Name of File::DocShowView.rb
#
# Purpose::
# This search for a loaded project called AppSelectViews
# that contains at least the document D2 and the views
# view1 and view2 and brings them to the foreground.
#------------------------------------------------------------
require "AS.API.Share"
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocShowViews.rb
#
# Purpose::
# This search for a loaded project called AppSelectViews
# that contains at least the document D2 and the views
# view1 and view2 and brings them to the foreground.
#------------------------------------------------------------
require "AS.API.Share"
7-186
API Reference Manual
A set of methods to defined the space used by the documents primary view. The units
used will be dependent on the base drawing units of the document. If the display uses
cm the base drawing unit is 1/10 of a millimeter.
or
or
or
Parameters:
cmpObj Fit the view to use the bounding box of the provided
component.
cmpObjs Fit the view to use the bounding box of the provided
component list.
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocZoom.rb
#
# Purpose::
# Demonstartes the views methods related to zooming.
# Expects in memory
# A project with the name ViewZoom.prx
# A component with the name "PPO1"
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
pt1 = System::Drawing::Point.new;
pt2 = System::Drawing::Point.new;
7-188
API Reference Manual
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method fits all document components into the documents primary views frame.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::DocZoomExtents.rb
#
# Purpose::
# Demonstrates how to use the documents method ZoomExtents
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-190
API Reference Manual
7.7 Component
This method is used to access the attributes that are managed by a view.
int GetBaseId();
This method returns the identifier of the object that generated the event. If this was not
a component the identifier returned will not work. A component will exist if a component
or a child or grandchild initiated the event.
The second method to find a view is to navigate through the view children of a
document.
nCnt = documentApi.GetChildCount(asTid.COMPONENT_API);
nIdx = 0
while (nIdx < nCnt) do
obj = documentApi.GetNthChild(nIdx,
asTid.COMPONENT_API);
… # Then you use the component object returned.
nIdx += 1
end
7.7.2 Methods
Parameters:
bHorizontal When set to true the object will be flipped end to end
otherwise the component will be flipped top to bottom.
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpFlip.rb
#
# Purpose::
# Demonstrates the two methods of flipping an objects
#------------------------------------------------------------
require "AS.API.Share"
# Find the size and location of the component for the zoom
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
cmp.Flip(true);
end
cmp = prj.GetComponent( "PPO2" );
if(cmp)
cmp.Flip(false);
end
end
7-192
API Reference Manual
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpAngle.rb
#
# Purpose:: Demonstrates rotating an object using degrees
# or radians.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
angle = cmp.GetAngle();
if (angle < 40)
cmp.SetAngle(45);
else
cmp.SetAngle(0);
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method is used to get the point in a graphical primitive that is used to lined it up
within a display. A symbol will have its own drawing coordinates, this defines the point
in that system that will be used when the object is moved.
Parameters:
Returns:
Point Position in the symbol coordinate system that will line up with
the insertion point within the display.
Example:
#------------------------------------------------------------
# Name of File::CmpGetAnchor.rb
#
# Purpose:: Get the anchor on the component.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetProjectApi( "P1" );
strOut = "Anchor found = [";
if(prj)
cmp = prj.GetComponent( "H1" );
if(cmp)
ptValue = cmp.GetAnchor();
strOut << ptValue.to_s; strOut << "]";
end
end
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-194
API Reference Manual
This method is used to get the point within a graphical primitive’s coordinate system that
is used when it is rotated. A symbol will have its own drawing coordinates, this defines
the point in that system that will be used when the object is rotated.
Parameters:
Returns:
Point Position in the symbol coordinate system that will be its center
of rotation.
Example:
#------------------------------------------------------------
# Name of File::CmpGetRotationCenter.rb
#
# Purpose:: Get center point to rotate the object arount.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
strOut = "Center of rotation found at = [";
cmp = prj.GetComponent( "H1" );
ptValue = cmp.GetRotationCenter();
strOut << ptValue.to_s; strOut << "]";
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method returns the background color of the component using an RGB value between
the hexadecimal value 0x00 to 0x00FFFFFF.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpColor.rb
#
# Purpose:: Moves the different colors between the
# different color attributes on the object. This script
# expects an object PPO1 with different colors on
# each attribute, color, foreground and background.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
rgbBgColor = cmp.GetBackgroundColor();
cmp.SetForegroundColor(rgbBgColor);
rgbColor = cmp.GetColor();
cmp.SetBackgroundColor(rgbColor);
rgbFColor = cmp.GetForegroundColor();
cmp.SetForegroundColor(rgbFColor);
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-196
API Reference Manual
This method returns the color of the component using an RGB value between the
hexadecimal value 0x00 to 0x00FFFFFF.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpColor.rb
#
# Purpose:: Moves the different colors between the
# different color attributes on the object. This script
# expects an object PPO1 with different colors on
# each attribute, color, foreground and background.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
rgbBgColor = cmp.GetBackgroundColor();
cmp.SetForegroundColor(rgbBgColor);
rgbColor = cmp.GetColor();
cmp.SetBackgroundColor(rgbColor);
rgbFColor = cmp.GetForegroundColor();
cmp.SetForegroundColor(rgbFColor);
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpGetDocRelativePortPosition.rb
#
# Purpose:: Print out the position of all ports existing on
# the component "H1" relative to to their document.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetProjectApi( "P1" );
strOut = "["; i = 0;
if(prj)
cmp = prj.GetComponent( "H1" );
if(cmp)
ptNum = cmp.GetNumberOfPorts();
while (i< ptNum)
ptValue = cmp.GetDocRelativePortPosition(i+1);
i += 1; strOut << "Port["; strOut << i.to_s;
strOut << "]="; strOut << ptValue.to_s; strOut << " : ";
end
end
end
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-198
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpGetNumberOfPorts.rb
#
# Purpose:: Gets the number of ports that exist on the
# component "H2" in the current project.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
strOut = "[ Number of ports = "; i = 0;
if(prj)
cmp = prj.GetComponent( "H2" );
if(cmp)
ptNum = cmp.GetNumberOfPorts();
strOut << ptNum.to_s; strOut << " ] : ";
while (i< ptNum)
ptValue = cmp.GetDocRelativePortPosition(i+1);
i += 1; strOut << "Port["; strOut << i.to_s;
strOut << "]="; strOut << ptValue.X.to_s;
end
end
end
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpGetPortName.rb
#
# Purpose:: Get one of the port names found on the component.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
strOut = "Port Name found = [";
if(prj)
cmp = prj.GetComponent( "H1" );
if(cmp)
ptValue = cmp.GetPortName(2);
strOut << ptValue.to_s; strOut << "]";
end
end
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-200
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpGetPortPosition.rb
#
# Purpose:: Print out the position of all ports on a
# component
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(
AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
strOut = "["; i = 0;
if(prj)
cmp = prj.GetComponent( "H1" );
if(cmp)
ptNum = cmp.GetNumberOfPorts();
while (i< ptNum)
ptValue = cmp.GetPortPosition(i+1);
i += 1; strOut << "Port["; strOut << i.to_s;
strOut << "]="; strOut << ptValue.to_s; strOut << " : ";
end
end
end
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method returns the foreground color of the component using an RGB value between
the hexadecimal value 0x00 to 0x00FFFFFF.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpColor.rb
#
# Purpose:: Moves the different colors between the
# different color attributes on the object. This script
# expects an object PPO1 with different colors on
# each attribute, color, foreground and background.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
rgbBgColor = cmp.GetBackgroundColor();
cmp.SetForegroundColor(rgbBgColor);
rgbColor = cmp.GetColor();
cmp.SetBackgroundColor(rgbColor);
rgbFColor = cmp.GetForegroundColor();
cmp.SetForegroundColor(rgbFColor);
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-202
API Reference Manual
This method returns the name of the layer used by the component.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpGetLayerName.rb
#
# Purpose:: Gets the layer of the current component PPO1
#------------------------------------------------------------
require "AS.API.Share"
This method returns the linestyle currently used. The linestyle is an index into a table of
linestyles supported by Automation Studio™.
Parameters:
Returns:
Example:
#----------------------------------------------------------
# Name of File::CmpGetLineStyle.rb
#
# Purpose: Displays the linestyle used by component “POL1”
#----------------------------------------------------------
require "AS.API.Share"
7-204
API Reference Manual
This method returns index to the components line width. The return value is an index
into a table of widths supported by Automation Studio ™.
Parameters:
Returns:
Example:
#----------------------------------------------------------
# Name of File::CmpLineWidth.rb
#
# Purpose: Changes the line width used by the component
# “PPO1”
#----------------------------------------------------------
require "AS.API.Share"
Parameters:
Returns:
Point Current location of the object using the project base units, in
th
the case metric this is 1/10 of a mm.
Example:
#------------------------------------------------------------
# Name of File::CmpGetLocation.rb
#
# Purpose::
# Demonstrates the use of the components GetLocation method.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi("P1" );
doc = applicationApi.GetDocumentApi( "D1" , "P1" );
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-206
API Reference Manual
Returns the pattern currently used by the component. The pattern is an index into a table
of patterns supported by Automation Studio ™.
Parameters:
Returns:
Example:
#----------------------------------------------------------
# Name of File::CmpGetPatternFill.rb
#
# Purpose: Changes the pattern used by the component “PPO1”
#----------------------------------------------------------
require "AS.API.Share"
This method is used to ges the point within a graphical primitive’s coordinate system that
is used when it is rotated. A symbol will have its own drawing coordinates, this defines
the point in that system that will be used when the object is rotated.
Parameters:
Returns:
Point Position in the symbol coordinate system that will be its center
of rotation.
Example:
#------------------------------------------------------------
# Name of File::CmpGetRotationCenter.rb
#
# Purpose:: Get center point to rotate the object arount.
#------------------------------------------------------------
require "AS.API.Share"
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
strOut = "Center of rotation found at = [";
cmp = prj.GetComponent( "H1" );
ptValue = cmp.GetRotationCenter();
strOut << ptValue.to_s; strOut << "]";
applicationApi.LogScriptInformation(strOut,false);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-208
API Reference Manual
This method provides the current scale on the component. Scale is represented as the X
and the Y scale of the object returned in a point.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpScale.rb
#
# Purpose::
# Demonstartes scaling an object "DAO7"
#------------------------------------------------------------
require "AS.API.Share"
This method provides the original size in base units of the component. The size of the
object in the image will also be affected by its scale and rotation.
Parameters:
Returns:
Size Current size of the object using the project base units, in the
th
case metric this is 1/10 of a mm.
Example:
#------------------------------------------------------------
# Name of File::CmpGetSize.rb
#
# Purpose::
# Demonstartes the components method GetSize.
# Expects in memory a component with the name "PPO1"
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
# Find the size and location of the component for the zoom
if(cmp)
loc = cmp.GetLocation();
size = cmp.GetSize();
# Calculate the zoom frame around the component
Xmin = loc.X - 10;
Ymin = loc.Y - 10;
Xmax = loc.X + size.Width + 10;
Ymax = loc.Y + size.Height + 10;
doc = prj.GetDocumentApi( "D1" );
if(doc)
doc.Zoom(Xmin,Ymin,Xmax,Ymax);
end
end
7-210
API Reference Manual
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpGetText.rb
#
# Purpose:: Displays the text found on the component TXT1
#-
#------------------------------------------------------------
require "AS.API.Share"
7-212
API Reference Manual
Parameters:
Returns:
Size
Example:
#------------------------------------------------------------
# Name of File: CmpDuplicate.rb
#
# Purpose::
# This will copy a component and add it to the current doc.
#------------------------------------------------------------
require "AS.API.Share"
objType = AS::API::Share::ASAPI_OBJ.DOCUMENT_API;
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
#Retrieve component with id
cmp =prj.GetComponent( "REC1" );
if(cmp)
#Retrieve parent document of component
parent = cmp.GetParent(objType);
if(parent)
#Retrieve offset values
xOffset = 100;
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-214
API Reference Manual
This method moves the object to the point supplied. This uses base display co-ordinates.
This expects the object to be refreshed before the attribute is visible.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpMoveTo.rb
#
# Purpose:: Moves the component DAO4
#-
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
ptOrg = System::Drawing::Point.new;
ptOrg.X = 700;
ptOrg.Y = 700;
cmp.MoveTo(ptOrg); end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method moves the current component to a point in the document which will line up
with the port indicated. This method is expecting Automation Studio™ coordinates.
Parameters:
PortNumber The port number that will line up with the location in the
document provided. These numbers go from 1 to n.
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpMoveRelativeToPort.rb
#
# Purpose:: Move the component so that the indicated port
# lines up with the point in the display provided.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
prj = applicationApi.GetCurrentProject();
if(prj)
cmp = prj.GetComponent( "H3" );
if(cmp)
ptOrgNew = System::Drawing::Point.new;
ptOrgNew.X = 950; ptOrgNew.Y = 1100;
ptNum = cmp.GetPortNumber("A");
7-216
API Reference Manual
# Now move the component so that port B lines
# up with the point 850, 1000
cmp.MoveRelativeToPort(ptNum, ptOrgNew);
ptPortPos = cmp.GetDocRelativePortPosition(ptNum);
ptOrg = cmp.GetPosition();
strOut = "Position ="; strOut << ptOrg.to_s;
strOut << "\nPort ="; strOut << ptPortPos.to_s;
applicationApi.LogScriptInformation(strOut,false);
applicationApi.Refresh();
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This will rotate the component to the angle specified in relation to the insertion point
using either degrees or radians.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpAngle.rb
#
# Purpose:: Demonstrates rotating an object using degrees
# or radians.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
angle = cmp.GetAngle();
if (angle < 40)
cmp.SetAngle(45);
else
cmp.SetAngle(0);
end
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-218
API Reference Manual
This method sets the background color of the component using an RGB value between
the hexadecimal value 0x00 to 0x00FFFFFF.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpColor.rb
#
# Purpose:: Moves the different colors between the
# different color attributes on the object. This script
# expects an object PPO1 with different colors on
# each attribute, color, foreground and background.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
rgbBgColor = cmp.GetBackgroundColor();
cmp.SetForegroundColor(rgbBgColor);
rgbColor = cmp.GetColor();
cmp.SetBackgroundColor(rgbColor);
rgbFColor = cmp.GetForegroundColor();
cmp.SetForegroundColor(rgbFColor);
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-220
API Reference Manual
This method sets the color of the component using an RGB value between the
hexadecimal value 0x00 to 0x00FFFFFF.
Parameters:
Returns:
This method sets the foreground color of the component using an RGB value between
the hexadecimal value 0x00 to 0x00FFFFFF.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpColor.rb
#
# Purpose:: Moves the different colors between the
# different color attributes on the object. This script
# expects an object PPO1 with different colors on
# each attribute, color, foreground and background.
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
rgbBgColor = cmp.GetBackgroundColor();
cmp.SetForegroundColor(rgbBgColor);
rgbColor = cmp.GetColor();
cmp.SetBackgroundColor(rgbColor);
rgbFColor = cmp.GetForegroundColor();
cmp.SetForegroundColor(rgbFColor);
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-222
API Reference Manual
This method moves the object to the layer specified by the parameter layerName. This
expects the object to be refreshed before the attribute is visible.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpSetLayerByName.rb
#
# Purpose:: Moves the object to a different layer #-
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
cmp.SetLayerByName( "Layer 1" );
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Parameters:
lineStyle The line style to use. The linestyle is a table of styles used by
Automation Studio™.
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpSetLineStyle.rb
#
# Purpose: Changes the linestyle of component PP01
#-#----------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "PPO1" );
if(cmp)
fontName = cmp.SetLineStyle(8);
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-224
API Reference Manual
Sets the width to be used by the component. The idxWidth value is an index into a table
of widths supported by Automation Studio™. This expects the object to be refreshed
before the attribute is visible.
Parameters:
Returns:
Example:
#----------------------------------------------------------
# Name of File::CmpLineWidth.rb
#
# Purpose: Changes the line width used by the component
# “PPO1”
#----------------------------------------------------------
require "AS.API.Share"
This method sets the text used by the component. This expects the object to be
refreshed before the attribute is visible.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpSetText.rb
#
# Purpose:: Sets the text on the component TXT1
#-
#------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetProjectApi( "P1" );
if(prj)
cmp = prj.GetComponent( "TXT1" );
if(cmp)
cmp.SetText( "TXT1 text changed" );
end
end
applicationApi.Refresh();
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-226
API Reference Manual
AS::API::Share::ASAPI_PARAM_TYPE.iSetSpoolCurrent
AS::API::Share::ASAPI_PARAM_TYPE.iIsSpoolLocked
AS::API::Share::ASAPI_PARAM_TYPE.iRefreshComponent
AS::API::Share::ASAPI_PARAM_TYPE.iSetSpool
AS::API::Share::ASAPI_PARAM_TYPE.iDoesSpoolExists
AS::API::Share::ASAPI_PARAM_TYPE.iLockCurrentSpool
The object image has to be refreshed before the change will be visible within the image.
Parameters:
Returns:
Example:
#-------------------------------------------------------------------------
# Name of File::CmpSetParameter.rb
#
# Purpose::
#
# This will demonstrate how a script writer can set parameters on
# a component. In this case we will be changing the spool position
# of a directional Valve. The component "1-1V32" must exist in the
# current project.
#-------------------------------------------------------------------------
require "AS.API.Share"
prj = applicationApi.GetCurrentProject();
if( prj )
cmp = prj.GetComponent("H84");
if(cmp)
spoolPos = 1;
cmp.SetParameter(setSpool,spoolPos);
cmp.SetParameter(lockSpool,spoolPos);
cmp.SetParameter(refreshSpool,spoolPos);
end
end
return
7-228
API Reference Manual
Sets the pattern to be used by the component. The pattern is an index into a table of
patterns supported by Automation Studio™. This expects the object to be refreshed
before the attribute is visible.
Parameters:
Returns:
Example:
#----------------------------------------------------------
# Name of File::CmpSetPatternFill.rb
#
# Purpose: Changes the pattern used by the component “PPO1”
#----------------------------------------------------------
require "AS.API.Share"
This method is used to set the point in a graphical primitive that will be used when it is
rotated. A symbol has its own drawing coordinates, this defines the point in that system
that will be used when it is rotated.
Parameters:
centerPoint The new position in the symbol’s coordinate system that will
be used when it is rotated.
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpSetRotationCenter.rb
#
# Purpose:: Set a components rotation center
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
applicationApi.ChangeAllLogOutputs(AS::API::Share::LOGTYPE.AS_MESSAGE_SYSTEM);
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-230
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::CmpScale.rb
#
# Purpose::
# Demonstartes scaling an object "DAO7"
#------------------------------------------------------------
require "AS.API.Share"
7-232
API Reference Manual
7.8 View
int GetBaseId();
This method returns the identifier of the object that generated the event. If this was not
a view the identifier returned will not work. A view will exist if a view, or a child or
grandchild initiated the event.
The second method to find a view is to navigate through the view children of a
document.
nCnt = documentApi.GetChildCount(asTid.VIEW_API);
nIdx = 0
while (nIdx < nCnt) do
view = documentApi.GetNthChild(nIdx,
asTid.VIEW_API);
… # Then you use the view object.
nIdx += 1
end
7.8.2 Methods
This method sets the frame of the view to use the entire window space.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewMaximize.rb
#
# Purpose::
# This maximizes the current view.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View3");
if(view)
view.Maximize();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-234
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewMinimize.rb
#
# Purpose::
# This minimize the current view.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View3");
if(view)
view.Minimize();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method changes how the current view handles the zoom level when the frame size
changes.
Parameters:
bValue True sets the image into a mode so that the same image is
provided no mater what the frame size used, of course the
image will be a different size. False the zoom level will not
change so less or more of the image will be supplied when the
frame size changes.
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewSetAutoZoom.rb
#
# Purpose::
# Sets the view so that the zoom level does not change when
# the view frame changes.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View2");
if(view)
view.SetAutoZoom(true);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-236
API Reference Manual
After a call to this method, the user will be able to modify the height of the view’s frame
using the UI.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::SetVerticalStretch.rb
#
# Purpose::
# Demonstrates the view's vertical stretch method.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView( "View2" );
if(view)
view.SetVerticalStretch();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
After a call to this method, the user will be able to modify the width of the view’s frame
using the UI.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::SetHorizontalStretch.rb
#
# Purpose::
# Sets the horizontal stretch to true. This locks the
# ability of the user to stretch the frame vertically
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View2");
if(view)
view.SetHorizontalStretch();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-238
API Reference Manual
After a call to this method, when the user tries to modify the size of the frame using the
UI, proportion between the width and the height will be maintained.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewSetSymmetricStretch.rb
#
# Purpose::
# Sets any change to the views frame to be done maintaining
# the current frames aspect ratio.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View2");
if(view)
view.SetSymmetricStretch();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
After a call to this method, the user will be able to modify the width or the height of the
view’s frame using the UI.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewSetStretch.rb
#
# Purpose::
# Removes resizing restrictions on the view’s frame.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View2");
if(view)
view.SetStretch();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-240
API Reference Manual
Parameters:
bSet true/false to set or unset the attribute that dictates that the
view will remain on top of view stack.
Returns:
Example:
#------------------------------------------------------------
# Name of File::SetAlwaysOnTop.rb
#
# Purpose::
# Demonstrates the view's SetAlwaysOnTop method.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View2");
if(view)
view.SetAlwaysOnTop(true);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This method allows the script writer to modify the position of a view on the screen.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewSetWindowPosition.rb
#
# Purpose::
# Demonstrates the SetWindowPosition() method
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
doc = applicationApi.GetDocumentApi("D1","P1");
if(doc)
view = doc.GetView("View1");
if(view)
ptOrg = System::Drawing::Point.new;
ptOrg.X = 100
ptOrg.Y = 100
view.SetWindowPosition(ptOrg);
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-242
API Reference Manual
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewSetWindowSize.rb
#
# Purpose:
# How to resize a views window.
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
doc = applicationApi.GetDocumentApi("D1","P1");
if(doc)
view = doc.GetView("View1");
if(view)
ptOrg = System::Drawing::Size.new;
ptOrg.Width = 300
ptOrg.Height = 300
view.SetWindowSize(ptOrg);
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
This will turn on or off the interface that allows a user to zoom or pan the view.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewSetZoomAndPan.rb
#
# Purpose:
# Demonstrates the use of the view objects method
# SetPanAndZoom().
#------------------------------------------------------------
require "AS.API.Share"
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View1");
if(view)
view.SetZoomAndPan(false);
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-244
API Reference Manual
bool Show(AS::API::Share::SHOW_TYPE)
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewShow.rb
#
# Purpose::
# Demonstrates the views Show method.
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
if(doc)
view = doc.GetView("View2");
if(view)
showType = AS::API::Share::SHOW_TYPE.SHOW;
view.Show(showType);
doc.Refresh();
end
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
A set of methods to defined the space used by a view. The units used will be dependent
on the base drawing units of the document. If the display uses cm the base drawing unit
is 1/10 of a millimeter.
or
or
or
Parameters:
cmpObj Fit the view to use the bounding box of the provided
7-246
API Reference Manual
component.
cmpObjs Fit the view to use the bounding box of the provided
component list.
Returns:
Example:
#------------------------------------------------------------
# Name of File::ViewZoom.rb
#
# Purpose::
# Demonstrates the views methods related to zooming.
# Expects in memory the following in the current project.
# A document with the name "D1" and views 1, 2, 3 & 4
# Two components with the names "PPO1" and "DA02"
#------------------------------------------------------------
require "AS.API.Share"
require 'System.Drawing,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
pt1 = System::Drawing::Point.new;
pt2 = System::Drawing::Point.new;
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
7-248
API Reference Manual
This method fits all document components into the views frame.
Parameters:
Returns:
Example:
#------------------------------------------------------------
# Name of File::SetZoomExtents.rb
#
# Purpose::
# Demonstrates how to use the views method ZoomExtents
#------------------------------------------------------------
require "AS.API.Share"
viewApi = AS::API::Share::ASAPI_OBJ.VIEW_API;
doc = applicationApi.GetDocumentApi("D1","P1");
view = doc.GetView("View1");
if(view)
view.ZoomExtents();
end
return AS::API::Share::ASAPI_RETURNS.NORMAL_PROCESSING
Administrator
API
Automation Studio™
Drawing and simulation software that includes many workshops such as, electrical,
pneumatics, hydraulics, and the Catalogue module.
AS
Automation Studio™.
Display Builder
Boolean
C#
DLL
Software assemblies that can contain code and are shared by many applications. They
can contain data code and resources that can be used by a program. The code can be
executed from within the applications that load the DLL.
Entry Point
Event
The user’s functionality can also be driven by events that occur within Automation
Studio™. These events do not follow a predetermined path.
Events are a little different than hooks; events are generated by the windows operating
system in response to an action. These events can be redirected to the developer’s
module.
Events can be registered with a third-party script or .NET method within any user process
(including the startup process described below.
A-2
Glossary
Extensibility
Hook
Is a point in processing that can be redirected by a third party developer allowing him to
inject their own implementation required for the particular point in processing. This is
much like an “event” except it does not rely on windows event processing.
The users functionality will be driven by points in processing that occur within
Automation Studio™ that can be hooked by the developer.
Hooks can be registered to a third-party script or .NET method within any user process, or
by adding the required method or script to a component’s hyperlink attribute within a
document.
An example of such a point in processing is when the open file menu option is selected.
Here a user may be interested in affecting how Automation Studio ™ normally handles
this event so he indicates to Automation Studio ™ to call his open file process instead of
AS’s version.
Hyperlink
Generally associated with the Internet, it offers the possibility of opening a text element
or image by clicking on a link that contains an underlying address.
Logical operators
Elements establishing the link between two search criteria. These operators are: “AND”,
“OR”.
This term is used with reference to moving around AS’s data model. How can you access
an element of data required from within a .NET module or script.
Script
Is a text file that provides a set of controls that can direct Automation Studio™ to change
its behavior or manipulate its data. Scripts where previously known as batch languages
or job control languages.
Scripting
Startup
The first point in processing where a user may redirect functionality is during Automation
Studio™ startup. At this point if a client has created a startup .NET method or script it will
be processed.
Within this process the user can then call the register method that will map future events
to the user’s .NET methods or scripts.
Third-Party
Third-Party developer describes anybody who will be extending the runtime behavior of
Automation Studio™ on top of a released version of the software.
A-4
B IronRuby Syntax
This chapter will point out a few elements required to write IronRuby scripts that can be
called from, and interface with, Automation Studio™. This chapter can also be used to
introduce a user to the IronRuby language. Ruby is a significant language which will not
be documented here. For additional information please refer to the following link:
www.ruby-doc.org/docs/ProgrammingRuby/
The AS Scripting Language applies restrictions to the expected scope and use of the
scripts. Due to this environment; it can improve the power of the scripts by adding some
C# protocols to the scripting language.
The other issue is that there is included a significant interface to the Automation Studio™
model that can be used by the scripts.
Case sensitivity
Comments
Multi-line comment syntax, the =begin and =end have to start at the beginning of the
line
Variables
You do not have to specify variable type in IronRuby, and the moment you assign a
previously assigned value to a different type it will be changed to the new type.
str= "PPO1";
cmp = projectApi.GetComponent(str);
str = 1
count = str + 2
The above code, though difficult to read will work. What does matter is that you supply
the correct data to any interface used. Problems would occur if you assigned str = 1
before you called projectApi.GetComponent(str).
Reserved Words
Here is a list of some of the basic reserved words that exist in the IronRuby language.
__FILE__ __LINE__ alias and begin break case
class def defined? do else elsif end
ensure false for if in module next
nil not or redo rescue retry return
self super then true undef unless until
when while yield
Math
Ruby supports the following operators that can be used within expressions.
( + - * / % ** & | ^
It also supports the simplified version for any of the above. (+= -= etc.)
B-2
IronRuby Syntax
Comparison
Traditional Description
operators
<=> Zero indicates the operands are equal, 1 indicates left is greater than
the right operand, -1 indicates that the left is less than the right
operand.
=== Tests equality with clauses. example (1…10) === 5 returns true
.eql? True if both operands are of the same type and are equal.
.equal? True if the receiver and the argument are the same object
If…else
if conditional [then]
code …
[elsif conditional [then]
code …]
[else
code …]
end
Example:
Unless
unless conditional [then]
code
[else
code ]
end
B-4
IronRuby Syntax
Switch/Case Statement
case expression
[when expression [,
expression ...] [then]
code … ]...
[else
code …]
end
Example:
# The following tests to see what combo box item has been
selected.
case @comboBoxNodeType.SelectedIndex
when 0 : node =
@m_project.GetComponent(@textBoxVarNodeID.Text);
when 1 : node =
@m_project.GetDocument(@textBoxVarNodeID.Text);
when 2 : node = @m_project;
end
Example:
# The following example loops though all the projects within an application
:
iCnt = applicationApi.GetChildCount(1);
until i == iCnt
prj = applicationApi.GetNthChild(i, 1);
While Loop
while conditional [do]
code
end
Example:
# The following example also loops though all the projects within an application
:
i = 0
iCnt = applicationApi.GetChildCount(1);
while i != iCnt do
prj = applicationApi.GetNthChild(i, 1);
Function Calls
B-6
IronRuby Syntax
Classes
end
Exceptions
When an exception occurs that relates to improper use of the IronRuby language it is
caught by Automation Studio. Automation Studio™ will provide an error message box
that will include some information that may help the script builder correct the issue.
In a number of the cases the user will be able to choose whether to continue the script.
Standards
The internal names for different document standards can be accessed through the
following variables. These are not provided through tooltips. In the .NET world the prefix
“AS::API::Share::” can be omitted. The following are the Ruby variables. These
variables will be required in the IDocumentApi.SetStandard(), and
IDocumentApi.GetStandardName(), methods.
standards = applicationApi.GetConstantOptionStrings();
standards.k_VdPageSetupStandard;
standards.k_VdMapLocatorStandard;
standards.k_VdReferenceStandard;
standards.k_VdDimensioningStandard;
standards.k_VdDrawingToolsStandard;
standards.k_VdFluidStandard;
standards.k_VdHydraulicStandard;
standards.k_VdPneumaticStandard;
standards.k_VdElectrotechnicalStandard;
standards.k_VdOneLineStandard;
standards.k_VdPanelLayoutStandard;
standards.k_VdSFCStandard;
standards.k_VdLadderLogicStandard;
standards.k_VdElectricalStandard;
standards.k_VdDigitalElectronicStandard;
standards.k_VdConnectionDiagramStandard;
To run a script when Automation Studio™ is just starting, create a shortcut to Automation
Studio™. Select the properties dialog on the shortcut. Add to the target field the
following information.
"/SCRIPT:Getting Started\\IRScriptB.rb"
When this icon is now selected it will launch AS with the parameter
/SCRIPT:IRScriptB.rb. This registration script will add the “Extended” tab to
Automation Studio™’s ribbon bar. This tab will contain the “Ruby” group with buttons
“User Dialog” and “Export”.