algorithmic modeling for Rhino
Hello all,
I'm trying to add a wire between two components, let's call them myA and myB (type GH_Component) at a certain output and input location, but only if grasshopper will allow it... hence a quick datatype check as shown in the conditional:
if (myA.Params.Input[0].GetType() == myB.Params.Output[0].GetType())
{
myA.Params.Input[0].AddSource(myB.Params.Output[0]);
}
Problem is that this simple approach doesn't allow for grasshopper's in built casting, for example I'd still like to accept integers into a floating point source if possible.
Pretty sure I need to use IsAssignableFrom() in some way with the IGH_Goo but struggling to get anything to work :(
Any help much appreciated.
Thanks,
John.
Tags:
Are you writing you custom data type in gha or a custom VB component? What I did in writting a custom VB class in the VB component, I would write my own GetType function.
eg:
Public Class apple
Public Sub New()
'blah
End Sub
Public Function CheckType() As String
Return "apple"
End Function
End Class
A = New Apple
From another VB component,
You could do
If (x.CheckType = "apple") Then
'Do Something
End If
Of course if you are expecting other data type coming in, that does not implement the CheckType function, you can enclose the statement with TRY and CATCH
Hi John,
no luck. There's nothing you can do to test whether a conversion will work except doing the conversion.
For example, imagine you plug a Curve parameter into a Line parameter. It will work if the curve parameter contains linear curves, but you cannot rely on that.
Casting is provided at 3 levels, first there's the GH_Convert class which defines a boatload of possible conversions to and from all kinds of types. Then, both the data in A and B will be asked whether they can convert to and from each other.
If the A parameter contains data, you can try and convert it into B's type, see if it works. Or maybe just convert a small sampling. If A does not contain data, you're out of luck.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks for the responses David & Victor,
I'm not going to have any data at all at the stage I am wiring up so I guess I'm out of luck! However, the background on why it's not going to be possible has prevented me heading towards a dead end. Ta.
As a temporary fix, I have made some simple rule tables that I am now using to get a decent result - it's not perfect but should work for simple cases.
I may try and create my own components that have a specific and singular data type I/O - this may work best so I can be sure of what can be connected to what.
Thanks again,
John.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by