Hi All,
I’ve just started learning Grasshopper component development in Visual Studio VB and I’m a bit stuck.
I want to create a component with two inputs (datatree, key-string) - search the first branch of the datatree for a match with the key-string, then export the same index of the remaining branches.
I started simple, and at this stage I’m just trying to loop through an input tree, and manual copy data into the output tree but running into errors.
I think I’ve create the inputs OK, hopefully got the access right, and got the loop working. I can make the input = output - but for some reason when i try and loop and use Insert or Append, I’m getting errors:
Code is as follows:
INPUTS:
Protected Overrides Sub RegisterInputParams(pManager As GH_Component.GH_InputParamManager)
pManager.AddGenericParameter("Tree", "A", "Titled data tree to search and return data from", GH_ParamAccess.tree)
pManager.AddGenericParameter("Key", "B", "Key to search for and return data on", GH_ParamAccess.item)
End Sub
OUTPUTS
Protected Overrides Sub RegisterOutputParams(pManager As GH_Component.GH_OutputParamManager)
pManager.AddGenericParameter("Data", "C", "Dataset matching search key", GH_ParamAccess.tree)
End Sub
And the SolveInstance:
Protected Overrides Sub SolveInstance(DA As IGH_DataAccess)
' Declares variables for internal code
Dim i As Int32 = 0
Dim j As Int32 = 0
Dim searchterm As Grasshopper.Kernel.Types.GH_String
Dim output As Grasshopper.Kernel.Data.GH_Structure(Of Grasshopper.Kernel.Types.IGH_Goo)
Dim searchtree As Grasshopper.Kernel.Data.GH_Structure(Of Grasshopper.Kernel.Types.IGH_Goo)
' Checks that key inputs are present, if not, terminates
If (Not DA.GetDataTree(0, searchtree)) Then Return
If (Not DA.GetData(1, searchterm)) Then Return
For i = 0 To searchtree.Count - 1
'output.Insert(searchtree.Branch(i).Item(0), searchtree.Path(i), 0)
'output.Append(searchtree.Branch(i).Item(0))
output.AppendRange(searchtree.Branch(i), searchtree.Path(i))
Next
DA.SetDataTree(0, output)
End Sub
If anyone can help point me in the right direction, I would be very grateful.
Thanks in advance.
Lyndonj