Skip to content

Commit

Permalink
Add watcher sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pearswj committed Mar 13, 2023
1 parent 928e5ce commit 3e0a866
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
38 changes: 38 additions & 0 deletions grasshopper/cs/GrasshopperWatcherExample/AssemblyPriority.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Grasshopper;

namespace GrasshopperWatcherExample
{
public class AssemblyPriority : Grasshopper.Kernel.GH_AssemblyPriority
{
public override Grasshopper.Kernel.GH_LoadingInstruction PriorityLoad()
{
// https://developer.rhino3d.com/api/grasshopper/html/M_Grasshopper_Kernel_GH_AssemblyPriority_PriorityLoad.htm

Instances.CanvasCreated += Instances_CanvasCreated;

return Grasshopper.Kernel.GH_LoadingInstruction.Proceed;
}

private void Instances_CanvasCreated(Grasshopper.GUI.Canvas.GH_Canvas canvas)
{
Instances.ActiveCanvas.Document_ObjectsAdded += ActiveCanvas_Document_ObjectsAdded;

Instances.CanvasCreated -= Instances_CanvasCreated;
}

private void ActiveCanvas_Document_ObjectsAdded(Grasshopper.Kernel.GH_Document sender, Grasshopper.Kernel.GH_DocObjectEventArgs e)
{
foreach (var obj in e.Objects)
{
var msg = $"{obj.InstanceGuid}: {obj.Category} / {obj.SubCategory} / {obj.Name} ({obj.ComponentGuid})";
Rhino.RhinoApp.WriteLine(msg);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<Version>1.0</Version>
<Title>GrasshopperWatcherExample</Title>
<Description>Description of GrasshopperWatcherExample</Description>
<TargetExt>.gha</TargetExt>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grasshopper" Version="7.13.21348.13001" IncludeAssets="compile;build" />
</ItemGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug' AND $([MSBuild]::IsOSPlatform(Windows))">
<StartProgram>C:\Program Files\Rhino 7\System\Rhino.exe</StartProgram>
<StartArguments></StartArguments>
<StartAction>Program</StartAction>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrasshopperWatcherExample", "GrasshopperWatcherExample.csproj", "{0F025773-CB69-42E4-B342-A1E1FF06CAC1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0F025773-CB69-42E4-B342-A1E1FF06CAC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F025773-CB69-42E4-B342-A1E1FF06CAC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F025773-CB69-42E4-B342-A1E1FF06CAC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F025773-CB69-42E4-B342-A1E1FF06CAC1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {38B02F4D-FCA6-4864-A877-2D61982D7DF2}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Grasshopper;
using Grasshopper.Kernel;
using System;
using System.Drawing;

namespace GrasshopperWatcherExample
{
public class GrasshopperWatcherExampleInfo : GH_AssemblyInfo
{
public override string Name => "GrasshopperWatcherExample";

//Return a 24x24 pixel bitmap to represent this GHA library.
public override Bitmap Icon => null;

//Return a short string describing the purpose of this GHA library.
public override string Description => "";

public override Guid Id => new Guid("0c77fef1-bd0e-4332-baf9-f9b5b4122c4c");

//Return a string identifying you or your company.
public override string AuthorName => "";

//Return a string representing your preferred contact details.
public override string AuthorContact => "";
}
}

0 comments on commit 3e0a866

Please sign in to comment.