I am trying to use Rhinocommon to get an png pictureFrame, but when it is done the png is shown with alpha channel unused(background not transparent).
And I have also tried to modify the alpha transparency of the material associated with the pictureFrame object. However it seems that that trick does not work.
Here is how my code organizes:
Guid picId = myDoc.Objects.AddPictureFrame(plane, filepath, false, _width, _height,false, false);
RhinoObject picobj = myDoc.Objects.FindId(picId);
int picMtrl = picobj.Attributes.MaterialIndex;
myDoc.Materials[picMtrl].AlphaTransparency = true;
picobj.GetMaterial(true).AlphaTransparency = true;
myDoc.Views.Redraw();
RhinoApp.WriteLine("alpha set done{0}, {1}", picMtrl, picobj.GetMaterial(false).AlphaTransparency);
The problem is that even I have set the alpha transparency value to “true”, the following output of this value is still “false”. So I am quite cofused and looking for some help. Thanks a lot.
dale
(Dale Fugier)
February 12, 2020, 3:56pm
2
@andy - is this something you can help with?
Hi @dale , me again
Any luck on this issue? I have same problem and dont know how to make it work
I set AlphaTransparency to true and it will be changed to true in material but nothing happens
index = rs.ObjectMaterialIndex(obj guid)
material = scriptcontext.doc.Materials[index]
Hallo, I know it’s an old topic… but dit somebody solved it?
Greetings Nils
Gijs
(Gijs de Zwart)
January 11, 2024, 3:42pm
6
hi @n.feierabend I just tried the script that Dale made, but changing the AlphaTransparency through a script does not work.
RH-79648 Changing AlphaTransparency through a script doesn’t work
Hallo back, I found two workarounds:
Nr. 1 is a modification of the code here: Rhino - Add Texture
import scriptcontext as sc
import Rhino
import rhinoscriptsyntax as rs
import System
def addPicture(strg_path):
sc.doc = Rhino.RhinoDoc.ActiveDoc
# Create a Rhino material object.
rhino_material = Rhino.DocObjects.Material();
# Create Texture object.
texture = Rhino.DocObjects.Texture()
texture.FileName = strg_path
# Apply texture object to Rhino material object
rhino_material.SetTexture(texture, Rhino.DocObjects.TextureType.Bitmap)
rhino_material.AlphaTransparency = True # SET ALPHA!!!
# Create render material and apply rhino material via constructor
render_material = Rhino.Render.RenderMaterial.CreateBasicMaterial(rhino_material, sc.doc)
# Add render material to the active Document
sc.doc.RenderMaterials.Add(render_material)
# Add surface and apply rendermaterial
surface = Rhino.Geometry.PlaneSurface(Rhino.Geometry.Plane.WorldXY, Rhino.Geometry.Interval(0,10), Rhino.Geometry.Interval(0,10))
id = sc.doc.Objects.Add(surface )
obj = sc.doc.Objects.FindId(id)
obj.RenderMaterial = render_material;
obj.CommitChanges()
sc.doc.Views.Redraw()
addPicture(filepath)
Nr. 2 works with the Command() method. I saw a similar solution anywhere here in the forum but can’t remember where it was
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def createPictureframe3Point(strPath , point1, point2, point3):
formatedPath = chr(34) + strPath + chr(34)
cmd = "_-Pictureframe " + formatedPath + " 3Point " + str(point1) + " " + str(point2) + " " + str(point3) + " _EnterEnd"
rs.Command(cmd, True)
sc.doc = Rhino.RhinoDoc.ActiveDoc
ausgabeGuid = rs.LastCreatedObjects()
sc.doc = ghdoc
return str(ausgabeGuid[0])
createPictureframe3Point(filePath, pt_1, pt_2, pt_3)
I hope it helps!
Greetings
Nils