コード例 #1
0
    private int runCount;                              //Legacy field.

    public override void InvokeRunScript(IGH_Component owner, object rhinoDocument, int iteration, List <object> inputs, IGH_DataAccess DA)
    {
        //Prepare for a new run...
        //1. Reset lists
        this.__out.Clear();
        this.__err.Clear();

        this.Component           = owner;
        this.Iteration           = iteration;
        this.GrasshopperDocument = owner.OnPingDocument();
        this.RhinoDocument       = rhinoDocument as Rhino.RhinoDoc;

        this.owner    = this.Component;
        this.runCount = this.Iteration;
        this.doc      = this.RhinoDocument;

        //2. Assign input parameters
        DataTree <Point3d> P = null;

        if (inputs[0] != null)
        {
            P = GH_DirtyCaster.CastToTree <Point3d>(inputs[0]);
        }



        //3. Declare output parameters
        object A = null;
        object B = null;
        object C = null;
        object D = null;
        object E = null;


        //4. Invoke RunScript
        RunScript(P, ref A, ref B, ref C, ref D, ref E);

        try
        {
            //5. Assign output parameters to component...
            if (A != null)
            {
                if (GH_Format.TreatAsCollection(A))
                {
                    IEnumerable __enum_A = (IEnumerable)(A);
                    DA.SetDataList(1, __enum_A);
                }
                else
                {
                    if (A is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(1, (Grasshopper.Kernel.Data.IGH_DataTree)(A));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(1, A);
                    }
                }
            }
            else
            {
                DA.SetData(1, null);
            }
            if (B != null)
            {
                if (GH_Format.TreatAsCollection(B))
                {
                    IEnumerable __enum_B = (IEnumerable)(B);
                    DA.SetDataList(2, __enum_B);
                }
                else
                {
                    if (B is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(2, (Grasshopper.Kernel.Data.IGH_DataTree)(B));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(2, B);
                    }
                }
            }
            else
            {
                DA.SetData(2, null);
            }
            if (C != null)
            {
                if (GH_Format.TreatAsCollection(C))
                {
                    IEnumerable __enum_C = (IEnumerable)(C);
                    DA.SetDataList(3, __enum_C);
                }
                else
                {
                    if (C is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(3, (Grasshopper.Kernel.Data.IGH_DataTree)(C));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(3, C);
                    }
                }
            }
            else
            {
                DA.SetData(3, null);
            }
            if (D != null)
            {
                if (GH_Format.TreatAsCollection(D))
                {
                    IEnumerable __enum_D = (IEnumerable)(D);
                    DA.SetDataList(4, __enum_D);
                }
                else
                {
                    if (D is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(4, (Grasshopper.Kernel.Data.IGH_DataTree)(D));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(4, D);
                    }
                }
            }
            else
            {
                DA.SetData(4, null);
            }
            if (E != null)
            {
                if (GH_Format.TreatAsCollection(E))
                {
                    IEnumerable __enum_E = (IEnumerable)(E);
                    DA.SetDataList(5, __enum_E);
                }
                else
                {
                    if (E is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(5, (Grasshopper.Kernel.Data.IGH_DataTree)(E));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(5, E);
                    }
                }
            }
            else
            {
                DA.SetData(5, null);
            }
        }
        catch (Exception ex)
        {
            this.__err.Add(string.Format("Script exception: {0}", ex.Message));
        }
        finally
        {
            //Add errors and messages...
            if (owner.Params.Output.Count > 0)
            {
                if (owner.Params.Output[0] is Grasshopper.Kernel.Parameters.Param_String)
                {
                    List <string> __errors_plus_messages = new List <string>();
                    if (this.__err != null)
                    {
                        __errors_plus_messages.AddRange(this.__err);
                    }
                    if (this.__out != null)
                    {
                        __errors_plus_messages.AddRange(this.__out);
                    }
                    if (__errors_plus_messages.Count > 0)
                    {
                        DA.SetDataList(0, __errors_plus_messages);
                    }
                }
            }
        }
    }
コード例 #2
0
    private int runCount;                              //Legacy field.

    public override void InvokeRunScript(IGH_Component owner, object rhinoDocument, int iteration, List <object> inputs, IGH_DataAccess DA)
    {
        //Prepare for a new run...
        //1. Reset lists
        this.__out.Clear();
        this.__err.Clear();

        this.Component           = owner;
        this.Iteration           = iteration;
        this.GrasshopperDocument = owner.OnPingDocument();
        this.RhinoDocument       = rhinoDocument as Rhino.RhinoDoc;

        this.owner    = this.Component;
        this.runCount = this.Iteration;
        this.doc      = this.RhinoDocument;

        //2. Assign input parameters
        DataTree <Curve> cTree = null;

        if (inputs[0] != null)
        {
            cTree = GH_DirtyCaster.CastToTree <Curve>(inputs[0]);
        }

        DataTree <double> oTree = null;

        if (inputs[1] != null)
        {
            oTree = GH_DirtyCaster.CastToTree <double>(inputs[1]);
        }

        double angleThreshold = default(double);

        if (inputs[2] != null)
        {
            angleThreshold = (double)(inputs[2]);
        }



        //3. Declare output parameters
        object crvs  = null;
        object crvs2 = null;
        object pts   = null;
        object perps = null;


        //4. Invoke RunScript
        RunScript(cTree, oTree, angleThreshold, ref crvs, ref crvs2, ref pts, ref perps);

        try
        {
            //5. Assign output parameters to component...
            if (crvs != null)
            {
                if (GH_Format.TreatAsCollection(crvs))
                {
                    IEnumerable __enum_crvs = (IEnumerable)(crvs);
                    DA.SetDataList(1, __enum_crvs);
                }
                else
                {
                    if (crvs is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(1, (Grasshopper.Kernel.Data.IGH_DataTree)(crvs));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(1, crvs);
                    }
                }
            }
            else
            {
                DA.SetData(1, null);
            }
            if (crvs2 != null)
            {
                if (GH_Format.TreatAsCollection(crvs2))
                {
                    IEnumerable __enum_crvs2 = (IEnumerable)(crvs2);
                    DA.SetDataList(2, __enum_crvs2);
                }
                else
                {
                    if (crvs2 is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(2, (Grasshopper.Kernel.Data.IGH_DataTree)(crvs2));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(2, crvs2);
                    }
                }
            }
            else
            {
                DA.SetData(2, null);
            }
            if (pts != null)
            {
                if (GH_Format.TreatAsCollection(pts))
                {
                    IEnumerable __enum_pts = (IEnumerable)(pts);
                    DA.SetDataList(3, __enum_pts);
                }
                else
                {
                    if (pts is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(3, (Grasshopper.Kernel.Data.IGH_DataTree)(pts));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(3, pts);
                    }
                }
            }
            else
            {
                DA.SetData(3, null);
            }
            if (perps != null)
            {
                if (GH_Format.TreatAsCollection(perps))
                {
                    IEnumerable __enum_perps = (IEnumerable)(perps);
                    DA.SetDataList(4, __enum_perps);
                }
                else
                {
                    if (perps is Grasshopper.Kernel.Data.IGH_DataTree)
                    {
                        //merge tree
                        DA.SetDataTree(4, (Grasshopper.Kernel.Data.IGH_DataTree)(perps));
                    }
                    else
                    {
                        //assign direct
                        DA.SetData(4, perps);
                    }
                }
            }
            else
            {
                DA.SetData(4, null);
            }
        }
        catch (Exception ex)
        {
            this.__err.Add(string.Format("Script exception: {0}", ex.Message));
        }
        finally
        {
            //Add errors and messages...
            if (owner.Params.Output.Count > 0)
            {
                if (owner.Params.Output[0] is Grasshopper.Kernel.Parameters.Param_String)
                {
                    List <string> __errors_plus_messages = new List <string>();
                    if (this.__err != null)
                    {
                        __errors_plus_messages.AddRange(this.__err);
                    }
                    if (this.__out != null)
                    {
                        __errors_plus_messages.AddRange(this.__out);
                    }
                    if (__errors_plus_messages.Count > 0)
                    {
                        DA.SetDataList(0, __errors_plus_messages);
                    }
                }
            }
        }
    }