# Material Transparency

**URL:** <https://forums.sketchup.com/t/material-transparency/55368>\
**Category:** Ruby API\
**Tags:** transparent, materials, ruby, transparency, material\
**Created:** [November 16, 2017, 12:36pm UTC](https://forums.sketchup.com/t/material-transparency/55368 "2017-11-16T12:36:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![matteo.vilardo](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@matteo.vilardo](https://forums.sketchup.com/u/matteo.vilardo)\
**Post date:** [November 16, 2017, 12:36pm UTC](https://forums.sketchup.com/t/material-transparency/55368/1 "2017-11-16T12:36:45Z")

</div>

Hi guys, i want to check if one material use transparency or not.I have alredy used material.use\_alpha? and material.color.alpha \> 0 but not works , maybe i am doing something wrong or i dont understand how theese works

This is my code, i hope in your help

```ruby
if(material.use_alpha? == false || material.color.alpha > 0)
      UI.messagebox " NO material is NOT transparent"
elsif(material.use_alpha? == true || material.color.alpha == 0)
      UI.messagebox " OH material is transparent"
end

```

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [November 16, 2017, 1:58pm UTC](https://forums.sketchup.com/t/material-transparency/55368/2 "2017-11-16T13:58:24Z")

</div>

edit:

`material.use_alpha? || material.color.alpha > 0` are both true

unless it’s the ‘default color’, it either has it or not…

so you can simply test for that…

```ruby
material = Sketchup.active_model.materials.current
if !material.nil? && material.use_alpha?
 UI.messagebox " OH material is transparent"
else
 UI.messagebox " NO material is NOT transparent"
end

```

john

---

<div class="post-metadata">

**Author:** ![matteo.vilardo](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@matteo.vilardo](https://forums.sketchup.com/u/matteo.vilardo)\
**Post date:** [November 16, 2017, 4:08pm UTC](https://forums.sketchup.com/t/material-transparency/55368/3 "2017-11-16T16:08:51Z")

</div>

Thank you, it works. you saved me a lot of time, can i ask you how to get material’s tiling and offset

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [November 17, 2017, 11:18am UTC](https://forums.sketchup.com/t/material-transparency/55368/4 "2017-11-17T11:18:21Z")

</div>

> [@matteo.vilardo](#):
>
> you saved me a lot of time, can i ask you how to get material’s tiling and offset

You can obtain the UV data either via [`Sketchup::UVHelper`](http://ruby.sketchup.com/Sketchup/UVHelper.html) or [`Geom::PolygonMesh`](http://ruby.sketchup.com/Geom/PolygonMesh.html).

---

<div class="post-metadata">

**Author:** ![matteo.vilardo](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@matteo.vilardo](https://forums.sketchup.com/u/matteo.vilardo)\
**Post date:** [November 17, 2017, 12:24pm UTC](https://forums.sketchup.com/t/material-transparency/55368/5 "2017-11-17T12:24:58Z")

</div>

Thank you but,i dont need to retrieve the mesh’s uvs but, i need to get the texture’s width and height.

![Cattura](https://global.discourse-cdn.com/sketchup/original/3X/7/f/7ffcb5f351e5e0690c3a6909621b593d9195c998.jpg)

The problem is that the measue unit is variable from model to model

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [November 17, 2017, 12:38pm UTC](https://forums.sketchup.com/t/material-transparency/55368/6 "2017-11-17T12:38:27Z")

</div>

```ruby
material = Sketchup.active_model.materials.current
if !material.nil? && material.respond_to?(:texture)
 p [material.texture.width, material.texture.image_width, material.texture.height, material.texture.image_height] 
else
 p " NO material has no texture"
end

```

width, height are in inches and image\_width, image\_height are in pixels…

john

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [November 17, 2017, 1:54pm UTC](https://forums.sketchup.com/t/material-transparency/55368/7 "2017-11-17T13:54:45Z")

</div>

> [@matteo.vilardo](#):
>
> i need to get the texture’s width and height.

From [`Sketchup::Texture`](http://ruby.sketchup.com/Sketchup/Texture.html) - using the `width` and `height` properties.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [February 17, 2018, 5:54am UTC](https://forums.sketchup.com/t/material-transparency/55368/8 "2018-02-17T05:54:58Z")

</div>

Closed on February 17, 2018, 5:54am UTC

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
