diff --git a/Assets/Icon_SetCamera.3dm b/Assets/Icon_SetCamera.3dm new file mode 100644 index 0000000..34cc183 Binary files /dev/null and b/Assets/Icon_SetCamera.3dm differ diff --git a/Plugin/Properties/Resources.Designer.cs b/Plugin/Properties/Resources.Designer.cs index 8b5e430..236f9ad 100644 --- a/Plugin/Properties/Resources.Designer.cs +++ b/Plugin/Properties/Resources.Designer.cs @@ -60,6 +60,16 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icon_setcamera_24 { + get { + object obj = ResourceManager.GetObject("icon_setcamera_24", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Plugin/Properties/Resources.resx b/Plugin/Properties/Resources.resx index 4bd7ccc..6096170 100644 --- a/Plugin/Properties/Resources.resx +++ b/Plugin/Properties/Resources.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\icon_setcamera_24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\logo_24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/Plugin/Resources/icon_setcamera_24.png b/Plugin/Resources/icon_setcamera_24.png new file mode 100644 index 0000000..6d3db6a Binary files /dev/null and b/Plugin/Resources/icon_setcamera_24.png differ diff --git a/Plugin/SetCameraComponent.cs b/Plugin/SetCameraComponent.cs new file mode 100644 index 0000000..781379a --- /dev/null +++ b/Plugin/SetCameraComponent.cs @@ -0,0 +1,55 @@ +using Grasshopper.Kernel; +using Rhino.Geometry; +using System; + +namespace GH_Timeline +{ + public class SetCameraComponent : GH_Component + { + public override Guid ComponentGuid => new Guid("EEE94A1F-A762-425C-B564-5F5282580951"); + protected override System.Drawing.Bitmap Icon => Properties.Resources.icon_setcamera_24; + + public SetCameraComponent() + : base("Set Camera", "Set Camera", "Sets the camera location and target", "Display", "Timeline") + { + } + + protected override void RegisterInputParams(GH_InputParamManager pManager) + { + pManager.AddPointParameter("Camera Location", "L", "The location of the camera", GH_ParamAccess.item); + pManager.AddPointParameter("Camera Target", "T", "The target of the camera", GH_ParamAccess.item); + pManager[pManager.AddTextParameter("Viewport", "V", "The name of the viewport. If none, the active viewport will be used", GH_ParamAccess.item)].Optional = true; + } + + protected override void RegisterOutputParams(GH_OutputParamManager pManager) + { + } + + protected override void SolveInstance(IGH_DataAccess DA) + { + Rhino.Display.RhinoViewport viewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; + string viewportName = viewport.Name; + + + if (DA.GetData(2, ref viewportName)) + { + Rhino.Display.RhinoView rhView = Rhino.RhinoDoc.ActiveDoc.Views.Find(viewportName, false); + if (rhView == null) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Unable to find viewport {viewportName}"); + return; + } + + viewport = rhView.ActiveViewport; + } + + Point3d camPos = default; + Point3d camTar = default; + + DA.GetData(0, ref camPos); + DA.GetData(1, ref camTar); + + viewport.SetCameraLocations(camTar, camPos); + } + } +} \ No newline at end of file