algorithmic modeling for Rhino
In defintion I have a stored state (Solution -> Save State) and I want to be able to load that state at the end of a bunch of C# code in a scripting component.
I found this in the SDK:
IGH_StateAwareObject.LoadState("Begin");
But this asks for an object reference...
Any suggestions?
Tags:
Restoring states should happen via:
GH_Document.StateServer.RestoreState(index, restored_objects, missing_objects)
However you cannot call this during a solution, since changing a state requires a new solution. You'll need to schedule a new solution using GH_Document.ScheduleSolution(delay, callback) (probably using a delay of 1 ms) and then you can reinstate your state from the callback. Do note that calling RestoreState() always causes a new solution to run, so you might still run into problems this way. You may need to completely rewrite the logic and leave out the solution bit. This is what the RestoreState function looks like:
Public Function RestoreState(ByVal index As Int32, _
<Out()> ByRef restored_objects As Int32, _
<Out()> ByRef missing_objects As Int32) As Boolean
Dim state As GH_State = Me(index)
For i As Int32 = 0 To state.StateCount - 1
Dim id As Guid = state.StateData.Keys(i)
Dim data As String = state.StateData.Values(i)
Dim obj As IGH_DocumentObject = m_owner.FindObject(id, False)
If (obj Is Nothing) Then
missing_objects += 1
Continue For
End If
If (Not TypeOf obj Is IGH_StateAwareObject) Then
missing_objects += 1
Continue For
End If
Dim sa_obj As IGH_StateAwareObject = DirectCast(obj, IGH_StateAwareObject)
sa_obj.LoadState(data)
restored_objects += 1
Next
m_owner.NewSolution(False) 'Leave this out.
Return True
End Function
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I added an overload to RestoreState that now allows you to prevent the new solution, but this won't solve your immediate problem since you still cannot restore states while you're inside a solution.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
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
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by