...
5. Rename the Class1.cs file to cPlugin.cs and paste in the following codeView file
| Code Block | ||
|---|---|---|
| ||
using CSiAPIv1;
namespace CSiNET8PluginExample1
{
public class cPlugin : cPluginContract
{
private static string _modality = "Non-Modal";
internal static string _versionString = "2.0";
public int Info(ref string Text)
{
try
{
Text = "This plugin is supplied by Computers and Structures, Inc., " +
"as a simple example for developers of new plugins for CSI products. " +
"It starts a new blank model, then converts a line of text into " +
"frame objects and adds them to the model. If you enter the " +
"text \"crash\", an error will be generated for testing purposes. " +
"Version " + _versionString;
}
catch (Exception)
{
}
return 0;
}
public void Main(ref cSapModel sapModel, ref cPluginCallback pluginCallback)
{
var aForm = new Form1();
try
{
aForm.SetSapModel(ref sapModel, ref pluginCallback);
if (string.Compare(_modality, "Non-Modal", true) == 0)
{
// Non-modal form, allows graphics refresh operations in CSI program,
// but Main will return to CSI program before the form is closed.
aForm.Show();
}
else
{
// Modal form, will not return to CSI program until form is closed,
// but may cause errors when refreshing the view.
aForm.ShowDialog();
}
// It is very important to call pluginCallback.Finish(iError) when the form closes, !!!
// otherwise, the CSI program will wait and be hung !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// This must be done inside the closing event for the form itself, not here !!!!!!!!!!!
// If you simply have algorithmic code here without any forms,
// then call pluginCallback.Finish(iError) here before returning to the CSI program
// If your code will run for more than a few seconds, you should exercise
// the Windows messaging loop to keep the program responsive. You may
// also want to provide an opportunity for the user to cancel operations.
}
catch (Exception ex)
{
MessageBox.Show("The following error terminated the plugin:" + Environment.NewLine + ex.Message);
// call Finish to inform the CSI program that the plugin has terminated
try
{
pluginCallback.Finish(1);
}
catch (Exception)
{
}
}
}
}
}
|