Beispiel #1
0
        /// This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GeomObjGoo objGoo = new GeomObjGoo();

            if (!DA.GetData(0, ref objGoo))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No Object received");
                return;
            }

            this.obj = objGoo.Value.Duplicate();
            if (obj.MemberDict.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Object is empty");
                return;
            }
            //making a copy of the object in case mutation fails
            GeomObject obj_original = obj.Duplicate();

            MemberSelect param0 = Params.Input[0] as MemberSelect;

            param0.Update(obj);

            //now mutating the object
            List <IGH_Goo> obj_in = new List <IGH_Goo>();

            if (!DA.GetDataList(1, obj_in))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "The member was not replaced: No replacement received");
                DA.SetData(0, new GeomObjGoo(obj_original));
                return;
            }
            //Debug.WriteLine(obj_in[0] == null);
            //here check if all data are of same type within the list of this param
            if (!ObjectifyComponent.validDatatypes(obj_in))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "All data in an object member should be of the same type!");
                return;
            }

            MemberInput param1 = Params.Input[1] as MemberInput;

            param1.HasGeometry = typeof(IGH_GeometricGoo).IsAssignableFrom(obj_in[0].GetType());
            if (!obj.MemberDict.ContainsKey(param0.NickName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The object does not have a member with this name !");
                return;
            }

            //deleting the old member
            obj.MemberDict.Remove(param0.NickName);
            obj.MemberDict.Add(param0.NickName, obj_in);

            //now updating the visibility and bakability settings
            this.obj.Visibility[param0.NickName] = param1.Settings["Visible"];
            this.obj.Bakability[param0.NickName] = param1.Settings["Bakable"];

            DA.SetData(0, new GeomObjGoo(obj));
        }
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <IGH_Goo> members = new List <IGH_Goo>();

            for (int i = 0; i < Params.Input.Count; i++)
            {
                GeomObjGoo   objGoo   = new GeomObjGoo();
                MemberSelect curParam = Params.Input[i] as MemberSelect;
                if (curParam == null)
                {
                    continue;
                }
                if (!DA.GetData(i, ref objGoo))
                {
                    curParam.Reset(objGoo);
                    continue;
                }

                GeomObject obj = objGoo.Value;
                if (obj.MemberDict.Count == 0)
                {
                    //AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Nothing to show");
                    curParam.Reset(objGoo);
                    continue;
                }

                curParam.Update(obj);
                string key = curParam.NickName;
                if (obj.MemberDict.ContainsKey(key))
                {
                    members.AddRange(obj.MemberDict[key]);
                }
            }

            //returning as a list or as a single item based how many things need to be returned
            if (members.Count == 1)
            {
                Params.Output[0].Access = GH_ParamAccess.item;
                DA.SetData(0, members.First());
            }
            else
            {
                Params.Output[0].Access = GH_ParamAccess.item;
                DA.SetDataList(0, members);
            }
        }