forked from andrewheumann/jSwan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
995b56f
commit d1a2a0f
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters