Some content on this site is available only to logged-in subscribers. Contact Us for information on becoming a subscriber.

InSource.Solutions | InSource Training | InSource Client Portal
InSource Solutions Logo
Log In Sign Up
InSource.Solutions InSource Training InSource Client Portal Log In Sign Up
  • Home
  • AVEVA Application Server
  • AVEVA Application Server Tech Notes

TN Appsvr137 Using GR Access to Create and Deploy New Object Instances

Last updated: March 7th, 2025

Description

  • Author: Brian Schneider
  • Published: March 7th, 2025

Details:

Description

GR Access is a toolkit that allows custom application development to extend the capabilities of the standard Wonderware software product. This example from InSource demonstrates the use of the GR Access toolkit to automate galaxy operations.

  • Author: Michael Walker
  • Published: 06/25/2015
  • Applies to: GR Access 2014, Wonderware System Platform 2014 and later

Details

The following example application will automate the following galaxy operations:

  1. Logon to a specified galaxy
  2. Search for a specified template
  3. Generate a specified number of instances for the specified template
  4. Auto-assign the Area of each instance
  5. Auto-deploy each instance as it is created

The application is a simple windows form application. It prompts the user to enter a template name, the number of instances to create and then a button to create these instances.

The code behind is on the 'Create New Instances' button and it randomly assigns on instance name for each object to make it unique.

Here is a breakdown of the code:

  • Logon to a specified galaxy
string nodeName = Environment.MachineName;
string galaxyName = "MWSYSSIM";
GRAccessApp grAccess = new GRAccessApp();
ICommandResult cmd;

IGalaxies gals = grAccess.QueryGalaxies(nodeName);

if (gals == null || grAccess.CommandResult.Successful == false)
{
MessageBox.Show(grAccess.CommandResult.CustomMessage + grAccess.CommandResult.Text);

}

IGalaxy galaxy = gals[galaxyName];

galaxy.Login("", "");
cmd = grAccess.CommandResult;

if (!cmd.Successful)
{
MessageBox.Show("Login To Galaxy Failed! " + cmd.Text.ToString() + " : " + cmd.CustomMessage.ToString());
}
  • Search for a specified template
string[] tagnames = { tbxTemplateName.Text.ToString()};

IgObjects queryResult = galaxy.QueryObjectsByName(
EgObjectIsTemplateOrInstance.gObjectIsTemplate,
ref tagnames);

cmd = galaxy.CommandResult;
if (!cmd.Successful)
{
Console.WriteLine("QueryObjectsByName Failed for template:" +
cmd.Text + " : " +
cmd.CustomMessage);
return;
}

ITemplate userDefinedTemplate = (ITemplate)queryResult[1];

Generate a specified number of instances for the specified template, auto-assign the Area for each instance and Auto-deploy each instance as it is created. 

DateTime now = DateTime.Now;
for (int i = 1; i <= Convert.ToInt32(tbxInstanceCount.Text.ToString()); i++)
{
string instanceName = String.Format("object_{0}_{1}_{2}_{3}"
, now.Hour.ToString("00")
, now.Minute.ToString("00")
, now.Second.ToString("00")
, i.ToString());
IInstance sampleinst = userDefinedTemplate.CreateInstance(instanceName, true);
sampleinst.Area = "Area";
sampleinst.Deploy(EActionForCurrentlyDeployedObjects.deployChanges, ESkipIfCurrentlyUndeployed.dontSkipIfCurrentlyUndeployed, EDeployOnScan.doDeployOnScan, EForceOffScan.doForceOffScan, ECascade.doCascade, true);

Below is all the code that performs this action. 

try

{
string nodeName = Environment.MachineName;
string galaxyName = "MWSYSSIM";
GRAccessApp grAccess = new GRAccessApp();
ICommandResult cmd;

IGalaxies gals = grAccess.QueryGalaxies(nodeName);

if (gals == null || grAccess.CommandResult.Successful == false)
{
MessageBox.Show(grAccess.CommandResult.CustomMessage + grAccess.CommandResult.Text);

}

IGalaxy galaxy = gals[galaxyName];

galaxy.Login("", "");
cmd = grAccess.CommandResult;

if (!cmd.Successful)
{
MessageBox.Show("Login To Galaxy Failed! " + cmd.Text.ToString() + " : " + cmd.CustomMessage.ToString());
}

// seach for specified template.
string[] tagnames = { tbxTemplateName.Text.ToString()};

IgObjects queryResult = galaxy.QueryObjectsByName(
EgObjectIsTemplateOrInstance.gObjectIsTemplate,
ref tagnames);

cmd = galaxy.CommandResult;
if (!cmd.Successful)
{
Console.WriteLine("QueryObjectsByName Failed for template:" +
cmd.Text + " : " +
cmd.CustomMessage);
return;
}

ITemplate userDefinedTemplate = (ITemplate)queryResult[1];

// create an instance of selected template, named with current time to keep unique
DateTime now = DateTime.Now;
for (int i = 1; i <= Convert.ToInt32(tbxInstanceCount.Text.ToString()); i++)
{
string instanceName = String.Format("object_{0}_{1}_{2}_{3}"
, now.Hour.ToString("00")
, now.Minute.ToString("00")
, now.Second.ToString("00")
, i.ToString());
IInstance sampleinst = userDefinedTemplate.CreateInstance(instanceName, true);
sampleinst.Area = "Area";
sampleinst.Deploy(EActionForCurrentlyDeployedObjects.deployChanges, ESkipIfCurrentlyUndeployed.dontSkipIfCurrentlyUndeployed, EDeployOnScan.doDeployOnScan, EForceOffScan.doForceOffScan, ECascade.doCascade, true);

}

}

catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}

Here is screenshot of the resulting objects, created and deployed. 

 

object instances deployment
Give feedback about this article

Recommended articles

TN - 1240 Creating a Watchlist Using an Import File

Read More

How to receive group emails

Read More
Support Icon

CONTACT SUPPORT

How to reach us

10800 Midlothian Turnpike Tpke, Suite 209, Richmond, VA 23235

1.877.INSOURCE

Technical Support - 1.888.691.3858

Contact Us

  • InSource Solutions
  • InSource Training
  • InSource Client Portal
  • Log In
InSource Solutions Logo

© 2025 InSource Solutions. All Rights Reserved.

Knowledge Base Software powered by Helpjuice

Expand