Unless anyone else posts to this thread, this might be my last post here because the forum prevents more than three posts in a row from one person.
I am stuck with this Python error message from the Bake component:
Runtime error (ArgumentTypeException): expected Material, got NativeRenderMaterial
line 24, in script
This is line 24:
Mat = Rhino.DocObjects.Material(rM)
‘rM’ is coming from a new, second output on the mMaterial component, because I wasn’t able to use ‘GH_Material’ (now the ‘dM’ output for Custom Preview) any better than ‘NativeRenderMaterial’ (the ‘rM’ output). mMaterial looks like this internally:
var renderMaterial = Rhino.Render.RenderMaterial.CreateBasicMaterial(material); rM = renderMaterial; dM = new GH_Material(renderMaterial);
‘NativeRenderMaterial’ is nowhere to be found in the Rhino docs:
In all my searching I found many examples of people suffering the same pain, going back ten years!
And this in R6 from @DavidRutten ~3 years ago:
Among many, many code fragments I’ve examined, this one looked promising but it fails instantly when copy/pasted into a Python component:
Runtime error (NotSupportedException): This type of object is not supported in Grasshopper, so this Python script cannot create it. You might want to use ‘scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc’ to use the Rhino doc, instead? If you do, remember to restore it: ‘scriptcontext.doc = ghdoc’.
line 18, in AddMaterial, “”
line 38, in script
Here is that code:
import Rhino import scriptcontext import System.Drawing def AddMaterial(): # materials are stored in the document's material table index = scriptcontext.doc.Materials.Add() mat = scriptcontext.doc.Materials[index] mat.DiffuseColor = System.Drawing.Color.Chocolate mat.SpecularColor = System.Drawing.Color.CadetBlue mat.CommitChanges() # set up object attributes to say they use a specific material sp = Rhino.Geometry.Sphere(Rhino.Geometry.Plane.WorldXY, 5) attr = Rhino.DocObjects.ObjectAttributes() attr.MaterialIndex = index attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject scriptcontext.doc.Objects.AddSphere(sp, attr) # add a sphere without the material attributes set sp.Center = Rhino.Geometry.Point3d(10, 10, 0) scriptcontext.doc.Objects.AddSphere(sp) scriptcontext.doc.Views.Redraw(); if __name__=="__main__": AddMaterial()
Please HELP? I’m not asking for the moon here. Many, many people want the same thing. The forum is littered with variations of this request, evidence that many are squandering time like I am, hacking at partial solutions because GH is missing some basic functionality:
This is broken code:
mMaterial__bake_to_layer_2020Jan16a.gh (18.5 KB)