Skip to content

Commit

Permalink
Added a merge node
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Welch-Aurecon committed May 14, 2020
1 parent 995b56f commit d1a2a0f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Binary file modified dist/jSwan.gha
Binary file not shown.
56 changes: 56 additions & 0 deletions jSwan/Merge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace jSwan
{
public class Merge : JSwanComponent
{
public Merge() : base("Merge Json", "JMerge", "Merge a subset of Json into a given string")
{
}

public override Guid ComponentGuid => new Guid("ecd4d2fd-e522-4dd2-861a-5afc9bb8689c");

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Source JSON", "J", "The Json to modify", GH_ParamAccess.item);
pManager.AddTextParameter("Override Json", "O", "The Json to merge", GH_ParamAccess.item);
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Merged Json", "J", "The resultant Json", GH_ParamAccess.item);
}

protected override void SolveInstance(IGH_DataAccess DA)
{
GH_String jsonA = null;
if (!DA.GetData(0, ref jsonA)) return;

GH_String jsonB = null;
if (!DA.GetData(1, ref jsonB)) return;

var a = JsonConvert.DeserializeObject<JObject>(jsonA.Value);
var b = JsonConvert.DeserializeObject<JObject>(jsonB.Value);



a.Merge(b, new JsonMergeSettings
{
// union array values together to avoid duplicates
MergeArrayHandling = MergeArrayHandling.Union
});

//Do something

DA.SetData(0, new GH_String() { Value = a.ToString() });
}
}
}
1 change: 1 addition & 0 deletions jSwan/jSwan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="jSwanInfo.cs" />
<Compile Include="JTokenGoo.cs" />
<Compile Include="LockableJSwanComponent.cs" />
<Compile Include="Merge.cs" />
<Compile Include="Param_JsonInput.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down

0 comments on commit d1a2a0f

Please sign in to comment.