Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Selecting C# as the language, create a new project of type Class Library. Ensure that the selected project type targets .NET or .NET Standard, not .NET Framework.

Image RemovedImage Added


2. For convenience, set your project name to the desired name of your plugin.

...

For this example, we will use the name CSiNET8PluginExample1

Image Added


3. Select .NET 8.0 as the desired Framework

Image RemovedImage Added


4. Once your project is created, add a reference to the CSI API library. This will be located in the installed ETABS directory, typically C:\Program Files\Computers and Structures\ETABS 22\ . If you are making a plugin only for ETABS, select the ETABSv1.DLL . If you'd like your plugin to be compatible with other CSi CSI products, such as SAFE or SAP2000, use the cross-product API library, CSiAPIv1.DLL .

Image RemovedImage Added


5. Rename the Class1.cs file to cPlugin.cs and paste in the following code. Please note that while the cPlugin code implements the cPluginContract interface, you should not implement the Info or Main methods explicitlypay attention to the comments in the code, they contain important information about correct plugin operation.

Code Block
languagec#
using CSiAPIv1;

namespace OmniCorp_Robo1
{
    CSiNET8PluginExample1
{
    // Implementing the cPluginContract interface is not required, however
    // it is recommended to ensure that the required cPlugin methods are created correctly.
    // Do not implement the Info or Main methods explicitly,
    // i.e. their method signatures are correct as is
    public class cPlugin : cPluginContract
    {
        private static string _modality = "Non-Modal";

        private 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)
                {
                }
            }
        }
    }
}