private void writeCustomControls(GH_IWriter writer, IEnumerable <GHControl> customControls, string path) { foreach (GHControl control in customControls) { string name = (path.Length > 0) ? (path + "." + control.Name): control.Name; if (control is GHParameter) { GHParameter param = (GHParameter)control; switch (param.DataType) { case GH_Types.gh_bool: writer.SetBoolean(name, (bool)param.CurrentValue); break; case GH_Types.gh_double: writer.SetDouble(name, (double)param.CurrentValue); break; case GH_Types.gh_int32: writer.SetInt32(name, (int)param.CurrentValue); break; case GH_Types.gh_decimal: writer.SetDecimal(name, Convert.ToDecimal(param.CurrentValue)); break; } } if (control is IGHPanel) { writeCustomControls(writer, ((IGHPanel)control).Items, name); } } }
/// <summary> /// retrive the value of the custom control by name. /// if the path is invalid or the control is not a parameter then thorws an exception. /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value">the current value of the control</param> /// <param name="path">path to the control</param> /// <returns></returns> public void GetControlData <T>(ref T value, params string[] path) { GHControl control = GetControl(path); if (control is GHParameter) { GHParameter param = (GHParameter)control; value = (T)param.CurrentValue; return; } throw new Exception("Invalid path to control"); }
private void readCustomControls(GH_IReader reader, IEnumerable <GHControl> customControls, string path) { foreach (GHControl control in customControls) { string name = (path.Length > 0) ? (path + "." + control.Name) : control.Name; if (control is GHParameter) { if (reader.FindItem(name) == null) { continue; } GHParameter param = (GHParameter)control; switch (param.DataType) { case GH_Types.gh_bool: param.CurrentValue = reader.GetBoolean(name); break; case GH_Types.gh_double: param.CurrentValue = reader.GetDouble(name); break; case GH_Types.gh_int32: param.CurrentValue = reader.GetInt32(name); break; case GH_Types.gh_decimal: param.CurrentValue = (float)reader.GetDecimal(name); break; } } if (control is IGHPanel) { readCustomControls(reader, ((IGHPanel)control).Items, name); } } }