Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default values not assigned for Enumerables #611

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion Grasshopper_UI/Helpers/ToGH_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
using BH.UI.Grasshopper.Templates;
using BH.Engine.Grasshopper;
using Grasshopper.Kernel.Parameters.Hints;
using Grasshopper.Kernel.Types;
using Grasshopper.Kernel.Data;

namespace BH.UI.Grasshopper
{
Expand Down Expand Up @@ -124,13 +126,47 @@ public static IGH_Param ToGH_Param(this ParamInfo info)
try
{
if (info.HasDefaultValue && !info.IsRequired)
((dynamic)param).SetPersistentData(info.DefaultValue.IToGoo());
{
var data = Helpers.IToGoo(info.DefaultValue as dynamic);
SetPersistentData(param as dynamic, data as dynamic);
}
}
catch { }

return param;
}


/*************************************/
/**** Private Methods ****/
/*************************************/

private static void SetPersistentData<T>(GH_PersistentParam<T> param, IGH_Goo data) where T : class, IGH_Goo
{
param.SetPersistentData(data);
}

/*************************************/

private static void SetPersistentData<T>(GH_PersistentParam<T> param, List<IGH_Goo> data) where T : class, IGH_Goo
{
param.SetPersistentData(data.Cast<T>());
}

/*************************************/

private static void SetPersistentData<T>(GH_PersistentParam<T> param, GH_Structure<IGH_Goo> data) where T : class, IGH_Goo
{
param.SetPersistentData(data.Cast<T>());
}

/*************************************/

private static void SetPersistentData(object param, object data)
{
// Do nothing;
}

/*******************************************/
}
}
Expand Down