By Ha_Loe
#353275
Thanks a billion...

I was working my way through the plugin code from the ApplyMaterial... methods. My quess was that the plugin does some initial steps to establish the scene and all. Just found out about the CurrentInstance beiing routed through today and already fixed that.

Right now the helpers are perfect for what I do and I'll definitely keep away from Init(). I hope to implement multilayer materials soon so this will get a little more complex... but wht :lol:

I wrote this little snippet in order to have the material previews update in the scen manager. Surely you will have a way less complex way to make it all work that I have not yet stumbled upon.
Code: Select all
 
private double SL;       
protected void UpdatePreview(Material mxMat)
        {
            if (SL <= 0.0)
                return;
            mxMat.MaxPreviewSL = (uint)SL;
            mxMat.PreviewScene = "emitter_02m";
            Scene.EnableRaisingEvents = true;
            Material.PFire.WaitForIdle();
            Material.SelectedMaterial = mxMat;
            mxMat.RefreshPreview(true);
            while (Material.PFire.SceneDirty)
                Material.PFire.WaitForIdle();
        }
P.S.: I see that there was some stray experimental code left in the MaterialList. ApplyMaterial is done by the MaterialBake component now. All the Rhino related stuff is passed to Grasshopper and I only provide the additional attribs. Once I found this trick, baking became a piece of cake. :wink:

P.S.: going to see what the Grasshopper forum has to say about all this :mrgreen:
By JDHill
#353278
Yes, that is not going to work. You need to refresh the previews on another thread:
Code: Select all
public static class Helpers
{
    // just add this into the existing file

    public static void RefreshPreviews(object state)
    {
        int sleep = 2000;

        if (state is int)
        {
            sleep = (int)state;
        }

        foreach (Material material in Scene.CurrentInstance.Materials)
        {
            material.SetSelected();
            material.RefreshPreview(true);
            System.Threading.Thread.Sleep(sleep);
        }
    }
}
Then, at the end of your BakeGeometry method, just queue it up, rendering each one for 3 seconds:
Code: Select all
System.Threading.ThreadPool.QueueUserWorkItem(Maxwell.Helpers.RefreshPreviews, 3000);
That's ultra-simplistic, since you could easily end up baking again while this is still working. Of course, you can pass arbitrary information to the threaded method through the state parameter.
Sketchup 2025 Released

Thank you Fernando!!!!!!!!!!!!!!!!!!!!!!!!!!! hwol[…]

I've noticed that "export all" creates l[…]

hmmm can you elaborate a bit about the the use of […]

render engines and Maxwell

Funny, I think, that when I check CG sites they ar[…]