algorithmic modeling for Rhino
If you want to stop the timer on the canvas, you'll need to find it first. The following will work:
Private Sub RunScript(ByVal max As Integer, ByRef A As Object)
m_counter += 1
A = m_counter
If (m_counter >= max) Then
'We need to disable the timer that is associated with this VB component.
'First, find the document that contains this VB component
Dim ghdoc As GH_Document = owner.OnPingDocument()
If (ghdoc Is Nothing) Then Return
'Then, iterate over all objects in the document to find all timers.
For Each docobj As IGH_DocumentObject In ghdoc.Objects
'Try to cast the object to a GH_Timer
Dim timer As Special.GH_Timer = TryCast(docobj, Special.GH_Timer)
If (timer Is Nothing) Then Continue For
'If the cast was successful, then see if this component is
'part of the timer target list.
If (timer.Targets.Contains(owner.InstanceGuid)) Then
'If it is, lock the timer.
timer.Locked = True
End If
Next
End If
End Sub
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hello David,
Sorry I tried to adapt your code to stop timer in C#, however, I kept receiving this message:
1. Error (CS0246): The type or namespace name 'Special' could not be found (are you missing a using directive or an assembly reference?)line 76 >>> which is the line I make it BOLD below. The following code is what I changed.
Would you please let me know how to make this code work in C#? Thank you very much!
private void RunScript(object pause)
{
GH_Document ghdoc = owner.OnPingDocument();
if ((ghdoc == null))
return;
foreach (IGH_DocumentObject docobj in ghdoc.Objects) {
Special.GH_Timer timer = docobj as Special.GH_Timer;
if ((timer == null))
continue;
if ((timer.Targets.Contains(owner.InstanceGuid))) {
timer.Locked = pause;
}
}
}
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
bool pause = false;
}
VB and C# treat namespaces in a somewhat different way. You can't go wrong with a fully qualified name though. Just use Grasshopper.Kernel.Special.GH_Timer
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