Exemplo n.º 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //  AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Name: " + RoomName +"\nArea: " + RoomArea);

            //AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, AdjacentRoomsList.Count.ToString());

            GH_Document   GrasshopperDocument = Instances.ActiveCanvas.Document;
            List <String> nms = new List <string>();

            nms.Add("ValueContainer"); //node name
            List <IGH_DocumentObject> valueComp = GrasshopperDocument.FindObjects(nms, 1);

            if (valueComp.Count != 0)
            {
                Guid          instGUID    = valueComp[0].InstanceGuid;
                IGH_Component comp        = GrasshopperDocument.FindComponent(instGUID);
                int           userListLen = comp.Params.Input[0].VolatileData.PathCount;
                for (int i = 0; i < userListLen; i++)
                {
                    var roomIDFromNode = comp.Params.Input[0].VolatileData.get_Branch(i)[0].ToString();

                    if (Convert.ToInt16(roomIDFromNode) == this.RoomId)
                    {
                        var  roomNameFromNode = comp.Params.Input[0].VolatileData.get_Branch(i)[1].ToString();
                        var  roomAreaFromNode = comp.Params.Input[0].VolatileData.get_Branch(i)[2].ToString();
                        bool roomIsEnabled    = Convert.ToBoolean(comp.Params.Input[0].VolatileData.get_Branch(i)[3].ToString());

                        RoomName = roomNameFromNode;
                        RoomArea = Convert.ToDouble(roomAreaFromNode);
                        if (roomIsEnabled == false)
                        {
                            this.Locked = true;
                        }
                        else
                        {
                            this.Locked = false;
                        }
                    }
                }
            }

            DA.SetData(0, RoomName);
        }
        //Grab the elementgoo based on its guid and index
        public static UIElement_Goo getElementGoo(GH_Document doc, Guid id, int index)
        {
            IGH_Component comp = doc.FindComponent(id);

            return(comp.Params.Output[0].VolatileData.AllData(true).ToArray()[index] as UIElement_Goo);
        }
Exemplo n.º 3
0
        public void  getdatagenInputParams()
        {
            // Get the document this component belongs to.
            this.doc = OnPingDocument();
            if (doc == null)
            {
                return;
            }

            //CSVtype csvinput = this.Params.Input[0].Sources[0] as CSVtype;

            // Gain access to datgen component that is connected to this component
            IGH_Param source = this.Params.Input[0].Sources[0];


            // Get GUID of the connected datagen component
            Guid guid = source.Attributes.GetTopLevel.DocObject.InstanceGuid;

            this.datagencomponent = doc.FindComponent(guid);

            foreach (GH_String dat in datagencomponent.Params.Input[2].Sources[0].VolatileData.AllData(true))
            {
                this.directory.Add(dat.Value);
            }

            //List<PSlider> PSliders = datagencomponent.Params.Input[0].Sources as List<PSlider>;
            List <PSlider> PSliders = new List <PSlider>();

            //List<POutput> POutputs = datagencomponent.Params.Input[1].Sources as List<POutput>;
            List <POutput> POutputs = new List <POutput>();
            //List<Param_Number> outputs = datagencomponent.Params.Input[1].Sources as List<Param_Number>;

            List <IGH_Param> datagen_input_sources  = this.datagencomponent.Params.Input[0].Sources as List <IGH_Param>;
            List <IGH_Param> datagen_output_sources = this.datagencomponent.Params.Input[1].Sources as List <IGH_Param>;

            foreach (IGH_Param s in datagen_input_sources)
            {
                PSliders.Add(s as PSlider);
            }

            foreach (IGH_Param o in datagen_output_sources)
            {
                POutputs.Add(o as POutput);
            }

            this.PSliders = new List <PSlider>(PSliders);
            this.POutputs = new List <POutput>(POutputs);

            // get target names from POutput compnent nicknames and store as targetnames
            //List<string> targetnames = new List<string>();
            string[] targetnames = new string[POutputs.Count];

            int index = 0;

            foreach (POutput POutput in this.POutputs)
            {
                string name = POutput.NickName as string;
                targetnames[index] = name;
                index++;
            }

            this.targets = new List <string>(targetnames);

            string projfilename = Path.GetFileNameWithoutExtension(this.doc.FilePath);

            this.csvfilepath = Path.Combine(this.directory[0], projfilename + "_CSVdata.txt");
        }