Automation in code generation: Lesson 5 – Adding objects via scripts.

Most Elipse E3’s and Elipse Power’s objects can be inserted via scripts with AddObject method:

AddObject(ClassName[[, Activate], ObjectName])

This method’s parameters are:

  • ClassName: indicates the type of object to be created.
  • Activate: optional; indicates whether the object will be activated upon its creation. If set up as False, it can later be activated via Activate method.
  • ObjectName: optional; indicates a name for the new object.

Example:

'points to the desired location 
set folder = Application.GetObject("Data")

'creates the object inside the location 
set new_tag = folder.AddObject("DemoTag", FALSE, "DemoTag1")

'sets up a few properties of the new object 
new_tag.Scan = 2500
new_tag.Minimum = 25
new_tag.Maximum  =500

'activates the object 
new_tag.Activate()

'saves the folder 
folder.Save()

You should notice that AddObject method can only be called from an object (a data folder, a screen, a driver, etc.). In other words, the new object must be created inside another one.

On the other hand, EcoFiles objects, those that are inserted directly into the object’s root (examples: screens, historics, substations, databases, etc.), can be created via CreateFile method.

An example:

'creates 5 screens in 'Project1'
for i=1 to 5
Application.CreateFile "Project1", "Panel.Screen", "NewScreen"& i
next

NOTE: this method only works in when executed at edition time, by using CustomConfig event, which will be discussed later on.

Before proceeding to Lesson 6, we recommend reading the following articles:

Basic VBScript for Elipse E3: Lesson 9 – Adding Objects in Execution.
KB-34747: Error code 80070057 at E3 Studio.

Related articles


Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *