How to create a transparent plane and make it clickable?

Hello again,

I I did shorten the code very much to ask this question.
How can I make the planes transparent and clickable and add a function to that plane when clicked?

selected_object = Sketchup.active_model.selection[0]
bounding_box = selected_object.bounds
center = bounding_box.center
largest_side = [bounding_box.width, bounding_box.height, bounding_box.depth].max


plane_size_percentage = 100
plane_size = largest_side * plane_size_percentage / 100.0

plane_transparency = 50
transparency = plane_transparency  / 100.0

# Draw the x plane
x_plane = Sketchup.active_model.entities.add_face(
  [center.x - plane_size / 2, center.y - plane_size / 2, center.z],
  [center.x + plane_size / 2, center.y - plane_size / 2, center.z],
  [center.x + plane_size / 2, center.y + plane_size / 2, center.z],
  [center.x - plane_size / 2, center.y + plane_size / 2, center.z]
)
x_plane.back_material = x_plane.material = Sketchup::Color.new(255, 0, 0, 255 * transparency)

# Draw the y plane
y_plane = Sketchup.active_model.entities.add_face(
  [center.x, center.y - plane_size / 2, center.z - plane_size / 2],
  [center.x, center.y + plane_size / 2, center.z - plane_size / 2],
  [center.x, center.y + plane_size / 2, center.z + plane_size / 2],
  [center.x, center.y - plane_size / 2, center.z + plane_size / 2]
)
y_plane.back_material = y_plane.material = Sketchup::Color.new(0, 255, 0, 255 * transparency)

# Draw the z plane
z_plane = Sketchup.active_model.entities.add_face(
  [center.x - plane_size / 2, center.y, center.z - plane_size / 2],
  [center.x + plane_size / 2, center.y, center.z - plane_size / 2],
  [center.x + plane_size / 2, center.y, center.z + plane_size / 2],
  [center.x - plane_size / 2, center.y, center.z + plane_size / 2]
)
z_plane.back_material = z_plane.material = Sketchup::Color.new(0, 0, 255, 255 * transparency)


x_plane.material.alpha = 255 * transparency
y_plane.material.alpha = 255 * transparency
z_plane.material.alpha = 255 * transparency


x_plane.back_material.alpha = 255 * transparency
y_plane.back_material.alpha = 255 * transparency
z_plane.back_material.alpha = 255 * transparency

#Also see no difference using this line.
Sketchup.active_model.rendering_options["EdgeTransparency"] = transparency

Any suggestions? I guess I don not understand the ruby documentation well or have a wrong impression about those functions and calls.

Thank you.

I remember - sometimes long ago when I tried - that assigning a color as material somehow does not apply transparency…

However set the alpha of material should work, if you make it properly

The #alpha= method is used to set the opacity of the material.

The value must be between 0.0 and 1.0. A value of 0.0 means that the material is completely transparent. A value of 1.0 means that the Material is completely opaque.

so e.g. :

x_plane.material.alpha = 255 * transparency

should be replaced by:

x_plane.material.alpha = transparency

__

I’m not sure what you mean, but normaly you should implement a Tool interface than the user can interact with the model.

Then The PickHelper class is used to pick entities that reside under the current cursor location, similar to native Select tool.
OR
The InputPoint class is used to pick 3d points and/or entities that reside under the current cursor location, similar to native Line tool and other drawing tools.

Unlike PickHelper, InputPoint uses inference, i.e. “snaps” to vertices and other entities when the cursor is close to them.

__

BTW
Sketchup::RenderingOptions object dos not contain rendering information key: EdgeTransparency


BTW 2.

Istened drawing “physical” faces, You may consider:

The View #draw method is used to do basic drawing. This method can only be called from within the Tool#draw method of a tool that you implement in Ruby.