Skip to content

PictureFrame with Transparency

Insert PNG entourage at predefined locations with transparent background.
Similar to Auto Entourage

Basic component setup:

  • dir : item, string - Folder with png's
  • loc : list, Point3d - Location for placement
  • h : item, double - Height of picture
  • w : item, double - Width of picture
  • place : item, bool - Button to place

Code

// Get png's
string[] files = System.IO.Directory.GetFiles(dir);
int i = 0;

if(place)
{
  foreach(var pt in loc){
    // Add PictureFrame
    var id = doc.Objects.AddPictureFrame(// Guid
      new Plane(pt, Vector3d.XAxis, Vector3d.ZAxis), // Plane
      files[i], // FilePath
      false, // As Mesh
      w, // Width
      h, // Height
      false, // Self-Illuminating
      false); // Embed Bitmap

    //F ind picture frame
    var obj = doc.Objects.FindId(id); // Rhino.DocObjects.RhinoObject
    var rm = obj.RenderMaterial; // Rhino.Render.RenderMaterial

    // Set Transparency
    rm.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program);
    rm.SetParameter("alpha-transparency", true);
    rm.EndChange();
    obj.CommitChanges();

    // Use all avilable png
    i++;
    if(i >= files.Length)i = 0;
  }
}
GitHub Gist

Result