algorithmic modeling for Rhino
Hi Giulio, David, et all
Trampoline Script (Counter) is failing to work inside a cluster, my educated guess is that its not able to listen outside the cluster so does not know to loop again.
How would i achieve this, I realise counting can now be done with timers but i find them not very unfriendly for Novice Users in the office the main code is designed for that this is part of.
Ps I have added in some Print Outs so the user knows when the Code is Finished, these work well but maybe better placed with the code.
private void RunScript(bool active, List<int> reps, List<int> intrvl, ref object C)
{
// Written by Giulio Piacentino
// giulio@mcneel.com
// 2012 January 23
// Written at Brian Harms' request posted at:
// http://www.grasshopper3d.com/forum/topics/dynamic-timer-interval
if(active)
{
ghDocument = owner.OnPingDocument();
ghDocument.SolutionEnd += documentSolutionEnd;
FindAndSetNextInterval(reps, intrvl);
}
else
{
_count = -1;
_nextInterval = 1;
Print("Run To Export");
}
C = _count++;
}
// <Custom additional code>
System.Windows.Forms.Timer trampoline = new System.Windows.Forms.Timer();
GH_Document ghDocument;
int _count;
int _nextInterval = 1;
void FindAndSetNextInterval(List<int> reps, List<int> intrvl)
{
int position = 0;
bool done = false;
for (int i = 0; i < reps.Count; i++)
{
position += reps[i];
if(_count < position)
{
_nextInterval = intrvl.Count > 0 ? intrvl[i % intrvl.Count] : 1;
done = true;
Print("Export In Progress");
break;
}
Print("Export Complete");
}
if (!done)
_nextInterval = -1;
}
void documentSolutionEnd(object sender, GH_SolutionEventArgs e)
{
ghDocument.SolutionEnd -= documentSolutionEnd;
// The trampoline gives time to stop the infinitly recursive chain from canvas,
// as well as mantains the call stack fixed in length
if(_nextInterval > 0)
{
trampoline.Interval = _nextInterval;
trampoline.Tick += trampolineTick;
trampoline.Start();
}
}
void trampolineTick(object sender, EventArgs e)
{
trampoline.Tick -= trampolineTick;
trampoline.Stop();
ghDocument.NewSolution(true);
}
Thanks Matt
Tags:
After doing more searching i have found this..
ghDocument = ghenv.Component.OnPingDocument().Owner.OwnerDocument().Objects
From this Discussion http://www.grasshopper3d.com/forum/topics/python-access-canvas-slid...
Its works fine for my python component but don't know how to edit it so it works in C #
I tried it in the trampoline code by replacing line 78 with the code above but get a error regarding it now knowing what ghenv is.
Thanks that's a great help.
I have just tried translating the new bit of code you added so it works on a python script to edit sliders but could not get it to work.
I changed all the Syntax
def RecurseUpTillHighestParentIsFound():
if(ghDoc.Owner != null and ghDoc.Owner.OwnerDocument() != null):
return RecurseUpTillHighestParentIsFound(ghDoc.Owner.OwnerDocument())
else:
return ghDoc
But Getting this error
'List[IGH_DocumentObject]' object has no attribute 'Owner'
If you want me to write it, you will have to upload a (sample) script in a definition.
Hi,
I am sorry i didn't get the previous tips,
I am kind of a beginner in scripting...
I am trying to update my slider in the canevas with a C# component inside a cluster.
I didn't manage to make it work using your lines below:
GH_Document RecurseUpTillHighestParentIsFound(GH_Document ghDoc)
{
if(ghDoc.Owner != null && ghDoc.Owner.OwnerDocument() != null)
{
return RecurseUpTillHighestParentIsFound(ghDoc.Owner.OwnerDocument());
}
else return ghDoc;
}
I would really appreciate some help :)
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