I am working on creating an event handler to give a feedback to the user based on the path of the texture file on a PBR material when they add it to the file. The following is what I came up with.
On trying with several PBR materials, I keep getting the number of paths 0. What am I missing?
P.S. I have added the event handler to the plugin and the event handler seems to work just fine.
using System.Collections.Generic;
using System.Linq;
using Rhino.Render;
using Rhino;
namespace HeroRhino.Handlers
{
public class MaterialPaths : RenderMaterial
{
private List<string> _filesToEmbed;
public override string TypeName => "WombatMaterial";
public override string TypeDescription => "WombatMaterial";
public MaterialPaths(IEnumerable<string> filesToEmbed)
{
_filesToEmbed = new List<string>(filesToEmbed);
}
public override IEnumerable<string> FilesToEmbed => _filesToEmbed;
}
public class MaterialPathHandler
{
public MaterialPathHandler()
{
RenderContent.ContentAdded += OnContentAdded;
}
private void OnContentAdded(object sender, RenderContentEventArgs e)
{
if (e.Content is RenderMaterial material)
{
MaterialPaths materialPaths = new MaterialPaths(material.FilesToEmbed);
List<string> paths = materialPaths.FilesToEmbed.ToList();
RhinoApp.WriteLine($"Paths: {paths.Count}");
RhinoApp.WriteLine($"Material Added: {material.Name}");
}
}
public void Start()
{
RenderContent.ContentAdded += OnContentAdded;
}
public void Stop()
{
RenderContent.ContentAdded -= OnContentAdded;
}
}
}