Skip to content

Commit

Permalink
adding feature to allow for optional inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
andyopayne committed Aug 16, 2024
1 parent a2ca6e6 commit d4a530b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/compute.geometry/GrasshopperDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
var treeAccess = Convert.ToBoolean(contextualParameter.GetType().GetProperty("TreeAccess")?.GetValue(contextualParameter, null));
if (contextualParameter != null)
{
if (contextualParameter.AtLeast == 0)
(contextualParameter as IGH_Param).Optional = true;
switch (ParamTypeName(inputGroup.Param))
{
case "Boolean":
Expand Down
5 changes: 4 additions & 1 deletion src/hops/HopsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Rhino.Geometry;
using System.Threading.Tasks;
using System.IO;
using Rhino;

namespace Hops
{
Expand Down Expand Up @@ -1086,6 +1085,10 @@ void DefineInputsAndOutputs()
break;
}

//make this parameter optional if user specified AtLeast value of zero
if (input.AtLeast == 0)
Params.Input[paramIndex].Optional = true;

if (paramIndex >= 0 && inputSources.TryGetValue(name, out List<IGH_Param> rehookInputs))
{
foreach (var rehookInput in rehookInputs)
Expand Down
5 changes: 4 additions & 1 deletion src/hops/RemoteDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,10 @@ static string GetPathFromInputData(IGH_DataAccess DA, HopsComponent component, i
int pathIndex = 0;
if (component?.Params.Input[paramIndex].VolatileData?.PathCount > 1)
pathIndex = DA.Iteration;
return component?.Params.Input[paramIndex].VolatileData?.Paths[pathIndex].ToString();
if (component?.Params.Input[paramIndex].VolatileData?.Paths.Count > 0)
return component?.Params.Input[paramIndex].VolatileData?.Paths?[pathIndex].ToString();
else
return null;
}

static void CollectDataHelper<T>(IGH_DataAccess DA,
Expand Down

0 comments on commit d4a530b

Please sign in to comment.