Features, discussions, tips, tricks, questions, problems and feedback

How to open a graphic form from script

Code Snippet:

      //Fetch the graphic form, from the Server for a project called Samples, graphic form name: Sample2
  string gfName = "Samples.Sample2";
  DataElement de = DataElementEngine.NewDataElement(gfName);
  //this indicates that, if the form does not exist in the current folder, it will search in other folders of the project, if not found, the server will search for an alternate match in other projects as well. 
  de.Status = DataElement.DataElementStatus.SEARCHFORALTERNATES; 
  DataElementCollection dec = DataElementEngine.NewDataElementCollection();
  dec.Add(de);
  MethodReturnInfo info = MyConnection.ReadDataElements(dec);
  if (info.Success)
  {
     DataElementCollection returnDec = info.ReturnObject as DataElementCollection;
     DataElement returnDe = returnDec[gfName] as DataElement;
     GraphicObject go = returnDe.Value as GraphicObject;
     //Load this form - NOTE: WILL ONLY WORK IN THE OPERATOR
     MyApplication.OpenGraphicObject(go, GraphicObjectDialogType.ModalForm);
  }
  else
  {        
     MessageBox.Show("An error occurred trying to retrieve graphic form");
  }

References required:

using VIZNET.Shared.DataElements.Engine;
using VIZNET.UI.Shared;
using VIZNET.Shared.Runtime;

This is the preferred way to open a graphic form.

You can use one of these three methods in your script to open a graphic form with an application spider.
You will need to drop an application spider into the spider workspace of the form you want to open from, then use the name of the spider in one of the methods bellow.

Note: Remember to remove the event on the application spider, unless you are using it.

1. Simply trigger an application spider
A simple way to do this is if you have already set the [Graphic Form] input of an application spider and do not want to edit it then you can just trigger the application spider outright.

ISpider __spider = MyController[appSpdrName] as ISpider;
__spider.Trigger();

2. Set graphic form path before triggering

private void OpenGfWithApplicationSpider(string appSpdrName, string gfPath)
{
ISpider __spider = MyController[appSpdrName] as ISpider;
DataElement __setDe = DataElementEngine.NewDataElement(“de”);
__setDe.Value = gfPath;
__spider.SetValue(__setDe, “Graphic Form”);
__spider.Trigger();
}

Example:
OpenGfWithApplicationSpider(“Application1”, “projName.graphicFormName”);

3. Set graphic form path and aliases of the graphic form before triggeriing

private void OpenGfWithApplicationSpider(string appSpdrName, string gfPath, EventHashtable htAliases)
{
ApplicationSpider __spider = MyController[appSpdrName] as ApplicationSpider;
DataElement __setDe = DataElementEngine.NewDataElement(“de”);
__setDe.Value = gfPath;
__spider.SetValue(__setDe, “Graphic Form”);
__spider.Trigger();
__spider.AliasInputs = htAliases;
}

Example:
EventHashtable aliases = new EventHashtable();
aliases.Add(“Alias1”, “Alias1 value”);
aliases.Add(“Alias2”, “Alias2 value”);
OpenGfWithApplicationSpider(“applicationSpiderName”, “proj.gfThatIWantToOpen”, aliases);

2 Likes