algorithmic modeling for Rhino
Out of curiosity, why are you using both DataTrees and GH_Structures?
--
David Rutten
david@mcneel.com
I want to make a component which will store datatree directly in the input of another component... using input.addvolatitedatatree(and here it wants a gh_structure).
And this is a Script component right? You're not doing this in Visual Studio?
Are you trying to set the volatile or the persistent data of another parameter? What data-type is in the tree, or should it work for any data type?
--
David Rutten
david@mcneel.com
I'm doing it in the Visual Studio. It should be volatile data of any type (hence system.object).
In that case I recommend ignoring DataTree altogether. Just use GH_Structure from the start.
Maybe it's time to post some code...
--
David Rutten
david@mcneel.com
OK, so here are the two guys -> sender and receiver. Forget the previous questions since this code is a little different.
1. sender gets data from its input(0)
2. sender sends data with output(0)
3. receiver gets data from sender via input (0) < the data here may be changed in the meantime, for instance if its a double then I would like to add 1 to it.
4. receiver sends data to sender's input(2)
5. go to 1.
SENDER
Public Class loopStart
Inherits GH_ComponentDim cnt As Integer
Friend Property counter() As Integer
Get
Return cnt
End Get
Set(value As Integer)
cnt = value
End Set
End PropertyDim iData As New GH_Structure(Of IGH_Goo)
Friend Property startData() As GH_Structure(Of IGH_Goo)
Get
Return iData
End Get
Set(value As GH_Structure(Of IGH_Goo))
iData = value
End Set
End PropertyPublic Sub New()
MyBase.New("loopStart", "loopStart", "Start the loop with this one.", "Extra", "Extra")
End SubPublic Overrides ReadOnly Property ComponentGuid() As System.Guid
Get
Return New Guid("bdf1b60d-6757-422b-9d2d-08257996a88c")
End Get
End PropertyProtected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)
pManager.AddGenericParameter("Data", "dIn", "Data to loop", GH_ParamAccess.tree)
pManager.AddIntegerParameter("Steps", "S", "Number of loops", GH_ParamAccess.item)
pManager.AddGenericParameter("<X>", "<X>", "Please leave this one alone, don't input anything.", GH_ParamAccess.tree)
pManager.Param(2).Optional = True
End SubProtected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)
pManager.AddGenericParameter("Data", "dOut", "Data to loop", GH_ParamAccess.tree)
End SubPublic Overrides Sub CreateAttributes()
m_attributes = New loopStartAttributes(Me)
End SubProtected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
Dim numLoop As Integer
DA.GetData(1, numLoop)Dim loopDt As New Grasshopper.Kernel.Data.GH_Structure(Of IGH_Goo)
If cnt = 0 Then
Me.startData.Clear()
DA.GetDataTree(0, Me.startData)
loopDt = startData.Duplicate
DA.SetDataTree(0, loopDt)
End IfIf cnt < numLoop - 1 And cnt > 0 Then
DA.GetDataTree(2, loopDt)
DA.SetDataTree(0, loopDt)
Me.ExpireSolution(True)
Else
DA.GetDataTree(2, loopDt)
DA.SetDataTree(0, loopDt)
End Ifcnt += 1
End Sub
End Class
RECEIVER
Public Class loopEnd
Inherits GH_ComponentDim aData As New GH_Structure(Of IGH_Goo)
Friend Property anyData() As GH_Structure(Of IGH_Goo)
Get
Return aData
End Get
Set(value As GH_Structure(Of IGH_Goo))
aData = value
End Set
End PropertyPublic Sub New()
MyBase.New("loopEnd", "loopEnd", "End the loop with this one.", "Extra", "Extra")
End SubPublic Overrides ReadOnly Property ComponentGuid() As System.Guid
Get
Return New Guid("3ffa3b66-8160-4ab3-87c9-356b2c17aadd")
End Get
End PropertyProtected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)
pManager.AddGenericParameter("Data", "dIn", "Data to loop", GH_ParamAccess.tree)
End SubProtected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)
pManager.AddGenericParameter("Data", "dOut", "Data after the loop", GH_ParamAccess.tree)
End SubProtected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
Me.aData.Clear()
DA.GetDataTree(0, Me.aData)
runner()DA.SetDataTree(0, Me.aData)
End SubSub runner()
Dim doc As GH_document = Grasshopper.Instances.ActiveCanvas.Document
Dim docl As list(Of iGH_DocumentObject) = (doc.Objects)For i As Integer = 0 To docl.count - 1 Step 1
Dim comp As Object = docl(i)
If comp.NickName = "loopStart" Then
Dim compp As IGH_Param = comp.Params.input(2)
compp.VolatileData.Clear()
compp.AddVolatileDataTree(anyData)
Exit For
End If
Next
End SubEnd Class
The attached code seems to work though I'm not exactly sure it's doing what you want it to do.
--
David Rutten
david@mcneel.com
Thanks, it works (with minor changes works exactly as intended).
...also this one works as intended.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by