AddPictureFrame but Transparent

Hi there,

I have been using this method to load an image. It works well.

We would like to import the image and make it transparent - This method does not support this.

Is it possible to modify the created RenderMaterial to add transparency?

If not I suspect we should create our own Material, I see this tutorial however I am not sure how to modify to create a transparent material

any advice appreciated.

Thank you

You should be able to retrieve the object from the object table, then query for its RenderMaterial and change the transparency setting using the SetParameter method on the RenderMaterial.

Once you have retrieved the RenderMaterial

RhinoObject obj = doc.Objects.FindId(guidFromAddPictureFrame);
RenderMaterial rm = obj.RenderMaterial;
rm.BeginChange(RenderContent.ChangeContexts.Program);
rm.SetParameter("transparancy", 0.5);
rm.EndChange();

Here some more examples of how to create and manipulate RenderMaterials: https://jesterking.github.io/rhipy

They are in Python, but use the RhinoCommon SDK. It should be straightforward to translate those to C#.

Thanks Nathan, that is super helpful

I can now see this in the render panel
image

however the plane does not appear transparent.
If i move the slider it suddenly becomes transparent
Did we miss an apply / commit?

code below (fixed typo in transparA//Ency spelling)

var id = doc.Objects.AddPictureFrame(plane, tempFileName, false, image.Image.Width * settings.XScale, image.Image.Height * settings.YScale, true, true);
var o = doc.Objects.Find(id);

o.RenderMaterial.BeginChange(RenderContent.ChangeContexts.Program);
o.RenderMaterial.SetParameter("transparency", 0.9);
o.RenderMaterial.SetParameter("alpha-transparency", true);
o.RenderMaterial.EndChange();
o.CommitChanges();

As far as I can tell those are the changes needed.

I am not sure if it makes a difference but maybe do:

RenderMaterial rm = o.RenderMaterial;
// .. set parameters bracketed by Begin/EndChange
o.RenderMaterial = rm;
o.CommitChanges();

That ought to be enough.

1 Like

Yeah that works! thank you

I am not sure why making the assignment helps but it does!

complete solution:

var o = doc.Objects.Find(id);
var material = o.RenderMaterial;
material.BeginChange(RenderContent.ChangeContexts.Program);
material.SetParameter("transparency", 0.5);
material.EndChange();
o.RenderMaterial = material;
o.CommitChanges();

Assigning the render material explicitly ensures the object attributes get properly flagged for update so that the call to CommitChanges actually does something.

Your first method never sets the RenderMaterial property on the object, only gets from it. Just having the material changed is not enough clearly (:

A bit finnicky, but that is how it is designed.

I should add an example to my literate page that explains this clearly.

1 Like

That makes sense, yeah an example would be great