Hi, lately I been trying to create a component for implementing a Heads-Up Display(HUD) on the viewport, so I was trying to access the NearRectangle and CameraLocation, for updating the changes in the size of the viewport, but I keep getting this weird behavior, a soon as I run the script the Z-value of the camera position and the NearRect keep increasing without bound, and the Z-value hits its type size limit the objects in the viewport desappear. So I’m leaving a video showing the behavior.
Any Advice? Thanks!!!
Here’s the script:
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
namespace Timer_Simple
{
public class TimerSimpleComponent : GH_Component
{
System.Windows.Forms.Timer timer;
int counter;
int maxCounter;
int interval;
bool reset, run;
Point3d[] rectPts;
Point3d camPt;
public TimerSimpleComponent()
: base("Timer_Simple", "TimeT",
"Used to test time-based components",
"User", "Debug")
{
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("Run", "Run", "", GH_ParamAccess.item, false);
pManager.AddBooleanParameter("Reset", "Rst", "", GH_ParamAccess.item, false);
pManager.AddIntegerParameter("Max", "Max", "", GH_ParamAccess.item, 0);
pManager.AddIntegerParameter("Interval", "Int", "", GH_ParamAccess.item, 100);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddIntegerParameter("Counter", "C", "", GH_ParamAccess.item);
pManager.AddPointParameter("Points", "P", "", GH_ParamAccess.list);
pManager.AddPointParameter("CamPt", "K", "", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
//I would not leave the SolveInstance without making sure that the timer is stopped... but well
if (!DA.GetData(0, ref run)) return;
if (!DA.GetData(1, ref reset)) return;
if (!DA.GetData(2, ref maxCounter)) return;
if (!DA.GetData(3, ref interval)) return;
if (timer == null)
{
timer = new System.Windows.Forms.Timer();
timer.Tick += UpdateSolution;
}
if (reset) Reset();
if (run && !timer.Enabled)
{
timer.Interval = interval;
Start();
}
else if (!run || timer.Enabled && maxCounter != 0 && counter >= maxCounter)
{
Stop();
}
DA.SetData(0, counter);
DA.SetDataList(1,rectPts);
DA.SetData(2, camPt);
}
public void Start(){timer.Start();}
public void Stop(){timer.Stop();}
public void Reset(){counter = 0;}
public void Update()
{
rectPts = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.GetNearRect();
camPt = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.CameraLocation;
counter++;
}
public void UpdateSolution(object source, EventArgs e)
{
Update();
ExpireSolution(true);
}
protected override System.Drawing.Bitmap Icon{get{return null;}}
public override Guid ComponentGuid{get { return new Guid("47a34244-09d1-4319-9bc5-32d019229284"); }}
}
}
Timer_Simple.rar (34.9 KB)
CAMERA_SIMPLE.gh (4.8 KB)