using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bentley.GenerativeComponents; using Bentley.GenerativeComponents.AddInSupport; using Bentley.GenerativeComponents.Features; using Bentley.GenerativeComponents.Features.Specific; using Bentley.GenerativeComponents.GeneralPurpose; using Bentley.GenerativeComponents.GCScript; using Bentley.GenerativeComponents.GCScript.FundamentalValues; using Bentley.GenerativeComponents.GCScript.GCTypes; using Bentley.GenerativeComponents.GCScript.NameScopes; using Bentley.GenerativeComponents.MicroStation; using Bentley.Interop.MicroStationDGN; using Bentley.GeometryNET; using System.ComponentModel; using Bentley.GenerativeComponents.View; namespace SampleAddIn { [GCNamespace("User")] // The GCNamespace attribute lets us specify where this SimpleLine node // type will appear within GCScript's namespace tree (that is, the // namespaces that are perceived by the GC user). This namespace has no // relation to our C# namespace, which is (in this case) SampleAddIn. [NodeTypePaletteCategory("Wayne")] // The NodeTypePaletteCategory attribute lets us specify where this // SimpleLine node type will appear within GC's Node Types dialog. // So, it will appear within a group named "Sample Add-In". [NodeTypeIcon("Resources/SimpleLineNode.png")] [Summary("Is a script i wrote")] public class ScriptFunctions //static internal class ScriptFunctions { static internal void Load() { // This method is called from within the constructor of the class, Initializer (within this project). So, this // method will be called automatically whenever the user loads this assembly, SampleAddIn, into GC. IGCEnvironment environment = UniversalGCEnvironment.TheOnlyInstance; NameCatalog nameCatalog = environment.TopLevelNameCatalog(); // To add a new function to the GCScript processor, we call the method, nameCatalog.AddNamespaceLevelFunction. // // 1. The first argument is the name of the new function, as the GC user will see it. (It's our responsibility // to ensure that the name doesn't conflict with another top-level name in GC.) // // 2. The second argument is the type (also known as the signature) of the new function, expressed in GCScript // language. // // 3. The third argument is the name of the C# method that implements the new function. That method can have any // name; however, we recommend that it have the same name as the function. DefineScriptFunctionsWrittenInScript(); } // Each method that implements a script function may be prefaced by a 'Summary' attribute, which provides user // documentation for that function. The documentation text will appear in GC's Functions dialog. (The presence // or absence of a Summary attribute has no effect on how the function may be used in GC.) static void DefineScriptFunctionsWrittenInScript() { // The following script is copied from the contents of the script transaction that results if we define one or more // new script function in the Functions dialog, then commit that transaction. string scriptwayne = "global redeclare object WayneReverse(object List)\n" + "{\n" + "object NewList = Reverse(List);\n" + "return NewList;\n" + "}\n"; // Now run the aforementioned script, which results in the script functions (in this case, the one function 'Angle360') being defined, // as though we were running a script transaction containing that script. GCScriptTools.ExecuteInItsEntirety(GCTools.UIGCSpace(), scriptwayne, ScriptFlags.UserAuthored, BreakpointAcknowledgement.Ignore); } } }