[Generative Components C#] Sample Solution - SimpleLine - GCBugException 723484

Hello,

I am using Generative Components Update 8 (Version 10.08.00.40). I can compile the C# Sample Solution and place the SimpleLineNode into the graph however, the SetElement() call throws an exception as per the attached screenshot. Has anyone else experienced this? Is there a workaround?

Regards,

Trevor

Parents
  • HI Trevor,

    This is a known problem with the U8 Sample Solution file. As a workaround, you may use the old U7  Sample Solution file. 

    Thanks,

    Anik

  • Hello Trevor, 

    No you do not need to downgrade your installation. We have upgraded the Update 7's sample solution code to work with update 8. Please use the below attached code to compile the sample solution.

    Please put this .CS inside the Sample Solution's folder and while opening the SampleAddin.sln file it should pick this CS too. 

    I hope this helps you to compile the sample solution. 

    line Upgraded for U8.cs
    // This file contains the definition of a new GC node type named SimpleLine. It is an extremely simplified version of GC's
    // own Line node type.
    //
    // GC supports two distinct architectures for node types, differentiated by which of the two classes, Feature or Node, the
    // node type is ultimately based upon.
    //
    // Feature-based node types are designed for generating new graphical elements into GC/MicroStation's geometry view. This
    // class, SimpleLine, is an example: Its only technique, ByPoints, generates a new graphical line element.
    //
    // Node-based node types (we know, that sounds weird) are designed for non-graphical-element-based "utility" operations,
    // which usually require a custom appearance and/or behavior in GC's graph. The Calculator node type, which is defined
    // elsewhere in this project, is an example.
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using Bentley.GenerativeComponents;
    using Bentley.GenerativeComponents.AddInSupport;
    using Bentley.GenerativeComponents.ElementBasedNodes;
    using Bentley.GenerativeComponents.GCScript;
    using Bentley.GenerativeComponents.GCScript.NameScopes;
    using Bentley.GenerativeComponents.GeneralPurpose;
    using Bentley.GenerativeComponents.MicroStation;
    using Bentley.GenerativeComponents.View;
    using Bentley.Interop.MicroStationDGN;
    
    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.
    
        [GCNodeTypePaletteCategory("Sample Add-In")]              // 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".
    
        [GCNodeTypeIcon("Resources/SimpleLineNode.png")]          // The NodeTypeIcon attribute lets us specify the graphical image (icon)
                                                                // that will appear on the SimpleLine node type's button within GC's Node
                                                                // Types dialog.
    
        [GCSummary("A line that connects two points in space.")]  // The Summary attribute lets us provide a brief description of this
                                                                // node's intended purposed. The text will be displayed when the user
                                                                // hovers over our node type in GC's Node Types dialog.
    
        public class Line_u7 : ElementBasedNode  // All Feature-based node types are derived from the class type, Feature (or from some
        {                                 // other class type that is, itself, derived from Feature.
    
            // No explicit constructor is needed or wanted; the default constructor is sufficient.
    
            // protected override void OnInitialized()
            // {
            //     // Here is where we perform any custom initialization of this class instance.
            //     // (It is NOT necessary to call the base class implementation.)
            // }
    
            // One of the fundamental differences between the Feature-based node architecture and the Node-based node architecture
            // is that, in the former, reflection is used to extract the technique names, the documentation, and the names and types
            // of the inputs and outputs, directly from the compiled C# class. GC provides a number of custom attributes to provide
            // more information to the that reflection process.
    
            [GCDefaultTechnique]  // Every technique method -- that is, every method that implements a technique of a Feature-based
                                // node type -- must be marked with one of the attributes [Technique] or [DefaultTechnique]. If a
                                // method doesn't have either of those attributes, then it's not exposed to the GC user; it's just
                                // an ordinary C# class method.
                                //
                                // (Only ONE method in the class may have the [DefaultTechnique] attribute.)
    
            // The following attributes -- Summary and Parameter -- do not affect the functionality of this node within GC. They do,
            // however, enhance the user's experience by providing documentation, which appears in various tooltip / flyover labels
            // in GC's UI.
    
            [GCSummary("Creates a line between a given start and end point, or a list of lines between lists of start points and/or end points.")]
            [GCParameter("StartPoint", "Start point of the line.")]
            [GCParameter("EndPoint", "End point of the line.")]
    
            public NodeUpdateResult ByPoints
            (
                NodeUpdateContext updateContext,
                [GCReplicatable, GCDgnModelProvider] IPointNode StartPoint,
                [GCReplicatable] IPointNode EndPoint,
                [GCOut] ref double Length
            )
            {
                // The first argument of every technique method must be of the type, NodeUpdateContext.
                //
                // The remaining arguments will become the input and output properties that the GC user sees and manipulates.
                //
                // Specific to these particular arguments:
                //
                //   - The [Replicatable] attribute denotes that, at the GC level, the value assigned to this property may be
                //     either a single item or a list. If it's a list, then this node will become replicated, and (therefore) this
                //     method, ByPoints, will be called multiple times, once for each item in the given list.
                //
                //     (Note that, except in very rare circumstances, you'll never need to worry about whether the node is in
                //     singleton or replicated mode. You simply write your code to handle the singleton case, and GC takes care of
                //     the rest.)
                //
                //   - The [ParentNodeScope] attribute denotes that, if this is a new instance of SimpleLine, it will be added to
                //     the same node scope (model) as that of the node given by this argument (StartPoint).
                //
                //   - The interface type, IPoint, is implemented by various node types, such as Point and CoordinateSystem.
                //     Essentially, IPoint represents any node type that can provide X, Y, and Z coordinates. If, for some reason,
                //     you wanted to restrict this technique to take only actual Point nodes, you would simply change the argument
                //     types accordingly.
                //
                //  - Together, the Out attribute and the "ref" keyword denote that this argument represents an output property,
                //    rather than an input property, of this technique.
    
                // We start by checking the validity of the inputs. If necessary, we return a result that indicates which
                // particular inputs are invalid. (Subsequently, the node will be displayed with an error badge and a tooltip
                // showing the names of the invalid inputs.)
    
                if (StartPoint == EndPoint)
                    return new NodeUpdateResult.TechniqueInvalidArguments("StartPoint", "EndPoint");
    
                // Okay, the inputs are valid. What follows is the actual functionality of this technique method.
    
                // 'SetElement' is a method of the Feature class.
                //
                // We can get an Element value by making an appropriate call to MicroStation.
    
                Point3d startP = NativeDgnTools.ToComPoint3d(StartPoint.GetDPoint3d());
                Point3d endP = NativeDgnTools.ToComPoint3d(EndPoint.GetDPoint3d());
    
                LineElement element = ComMSApp.CreateLineElement2(TemplateComElement(), ref startP, ref endP);
                
    
                SetComElement(element);
    
                Length = element.Length;  // Don't forget to assign a value to this technique method's "Out" argument.
    
                return NodeUpdateResult.Success;
            }
    
        } // class
    
    } // namespace
    
    

    regards,
    Alifur

    Answer Verified By: Trevor Watling 

Reply Children
No Data