Hello,
I have made a script in which point moves in random direction, However I want to have a point at every place when it moves. Can somebody show me how it can be done?
Thanks!
if (reset)
{
Point3d wlk = new Point3d(0, 0, 0);
A = wlk;
}
else
{
Random rand = new Random();
int choice = rand.Next(4);
if(choice == 0)
{
x++;
}
else if(choice == 1)
{
x--;
}
else if(choice == 2)
{
y++;
}
else
{
y--;
}
Point3d wlk = new Point3d(x, y, 0);
A = wlk;
}
you can put a data recorder on the output nodeā¦
Also - i always see this - Use a Boolean Button, not a Toggle - you save yourself a lot of clicks in the long runā¦
And then you can get rid of the āelseā
Thank You for making it. I understood the code except the method that your created.
Is it possible for you to explain me what exactly it is doing?
Grasshopper.Kernel.Special.GH_Timer timer;
public void FindTimer(){
foreach(IGH_DocumentObject obj in GrasshopperDocument.Objects){
if(obj is Grasshopper.Kernel.Special.GH_Timer){
Grasshopper.Kernel.Special.GH_Timer tim = obj as Grasshopper.Kernel.Special.GH_Timer;
if(tim.Targets.Contains(this.Component.InstanceGuid)){
timer = tim;
return;
}
}
}
}
To mee it looks like heās looking for the Timer which is connected to this component, and assigns it to an internal variable in
public void FindTimer()
{
// Look for a Timer among all the components in the GH document
foreach(var obj in GrasshopperDocument.Objects)
{
// Check if this component is of Timer type
if(obj is Grasshopper.Kernel.Special.GH_Timer)
{
// yes, it was, make sure we treat it like a Timer type:
var tim = obj as Grasshopper.Kernel.Special.GH_Timer;
// If this particular Timer ("tim") is connected to this
// component (where this code resides), then assign that
// Timer to the timer variable, and then quit ("return").
if (tim.Targets.Contains(this.Component.InstanceGuid))
{
timer = tim;
return;
}
}
}
}
Edit: The variable named ātimerā was declared here, and thus accessible from the code in the main method āRunScriptā:
There is no official way. This part of RhinoCommon (the namespace āspecialā) isnāt published. it is reserved only for initiated top level developers belonging to the Grand Lodge Of Grasshoppers (aka as GLOGs.
Just joking.
Iād like to see also the Special namespace being publicly published.
GH1 has been organically built on the fly for several years, so it is not too tidy. But you can start to know the Grasshopper.dll using the autocomplete function of the code editor (when you put a ā.ā after the namespace, like āGrasshopper.ā), or using reflection like this:
A = GrasshopperDocument.GetType().Assembly
.GetTypes()
.Where(t => t.Namespace == "Grasshopper.Kernel.Special")
.ToList();
If you want to use the components from .NET code, you must use Rhino6ās NodeInCode function. Components (actually parameters) such as Slider, Panel, Toogleā¦ belong to the Grasshopper.Kernel.Special namespace. The (black hexagonal background) parameters are in Grasshopper.Kernel.Parameters and the data types in Grasshopper.Kernel.Types. Most of the components are in their own .dll (.gha). The graphics/interface/controls/forms part is in Grasshopper.GUI.