Example #1
0
 protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
 {
     GHParam_DHr param = new GHParam_DHr();
     pManager.RegisterParam(param, "Dhours", "Dhrs", "The Dhours from which to calculate statistics", GH_ParamAccess.list);
     pManager.Register_StringParam("Period", "P", "The time period to cycle through.  Choose 'yearly', 'monthly', 'monthly diurnal', 'weekly', 'weekly diurnal', or 'daily'.  Output values are labeled 'SURROGATE' to remain distinguished from original Dhour lists.");
 }
Example #2
0
        private bool SetFilepath( string newfilepath)
        {
            // do we  really want to do this before testing that the file exists?  if we do, and the file does not exist, at least the user can see what file was meant to be loaded.
            this.filepath = newfilepath;
            this.NickName = Path.GetFileNameWithoutExtension(filepath); // set nickname to the new filepath

            if (!File.Exists(newfilepath)) {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Failed to set filepath.  Check that file exists: " + newfilepath);
                return false;
            }
            else {
                ClearParsedData(); // clear dictionaries

                // parse current filepath and store information in col_mapping and zone_hours dictionaries
                if (!ParseFilepath()) { return false; }

                // if successful, create a new output parameter for each entry in zone_hours
                #region // THANK YOU DAVID RUTTEN

                //Step 2. cache all existing parameters.
                List<IGH_Param> existingParams = new List<IGH_Param>(Params.Output);

                //Step 3. create a sync object for cleanup.
                object sync = Params.EmitSyncObject();

                //Step 4. remove all parameters manually, this is naughty, normally you'd call Params.UnregisterOutputParameter()
                Params.Output.Clear();

                //Step 5. recreate all parameters.
                List<string> zonenames = new List<string>();
                zonenames.AddRange(persistentOutputParams);
                foreach (KeyValuePair<string, List<DHr>> entry in zone_hours) { zonenames.Add(entry.Key); }

                foreach (string zonename in zonenames)
                {
                    IGH_Param zoneParam = null;

                    //First, we need to check whether a parameter pointing at this file used to exist.
                    //If that's the case, recycle it.
                    foreach (IGH_Param oldParam in existingParams)
                    {
                        if ((oldParam.NickName.Equals(zonename, StringComparison.OrdinalIgnoreCase)))
                        {
                            zoneParam = oldParam;
                            existingParams.Remove(oldParam);
                            break;
                        }
                    }

                    if (zoneParam == null)
                    {
                        //It would seem there was no parameter for this file, create a new one.
                        zoneParam = new GHParam_DHr();
                        if (zonename == this.persistentOutputParams[0]) { zoneParam = new Grasshopper.Kernel.Parameters.Param_String(); }
                        zoneParam.Name = zonename;
                        zoneParam.NickName = zonename;
                    }

                    Params.RegisterOutputParam(zoneParam);
                }

                //Step 6. use the sync object to perform cleanup on all lost parameters.
                Params.Sync(sync);

                //Step 7. make sure everyone knows we've just been naughty.
                Params.OnParametersChanged();

                //Step 8. invoke the cleanup code.
                VariableParameterMaintenance();

                //Step 9. invoke a new solution.
                ExpireSolution(true);

                #endregion

                this.Params.OnParametersChanged();
                this.OnAttributesChanged();
                ExpireSolution(true);
                return true;

            }
        }