Change material/opacity of vcGeometryFeature

Hi,

I want to change the Opacity of vcGeometryFeatures through the python API. However, there is no way to reach the material for the geometry. Did i import it in the wrong way or is this simply impossible for geometryFeatures?

I imported a step file of a factory including several different buildings. At the moment i want to change the opacity of some buildings to make them transparent in certain cases. In the future i will also want to change colour of the different buildings through the script.

Thanks in advance,

Anton

One workaround seem to be to extract the geometry feature as a component and then set the color for that specific component. But it doesn’t seem possible to extract the component through the API? Atleast i couldnt find it in the help for Python API.

Edit: Apparently geometries doesnt inherit the components material. So this doesn’t work either.

vcGeometryFeature likes its counterpart, Geometry feature, does not have a Material property. You can, however, manipulate the material of the geometry sets in the feature’s vcGeometryContainer.

The attached component has a script that shows how to do the following with Python API:

  • Access and set the material of sets
  • Update the feature and render the result
  • Create a new material using system material as template
  • Modify opacity of new material
  • Register the new material with main application
Here is the script
from vcScript import *

comp = getComponent()
geo_feat = comp.getFeature(“Geometry_0”)
geo_cont = geo_feat.Geometry

app = getApplication()
pink = app.findMaterial(“pink”)
for set in geo_cont.GeometrySets:
set.Material = pink
geo_feat.rebuild()
app.render()

#create new material and change its opacity
#not a good idea to modify system materials
#just create a new one in GUI or via Python
yellow = app.findMaterial(“yellow”)
my_mat = app.findMaterial(“banana”)
if not my_mat:
my_mat = app.createMaterial(“banana”)
my_mat.Ambient = yellow.Ambient
my_mat.ColorMask = yellow.ColorMask
my_mat.Diffuse = yellow.Diffuse
my_mat.Specular = yellow.Specular
my_mat.Shininess = yellow.Shininess
my_mat.Opacity = yellow.Opacity
my_mat.OpacityType = yellow.OpacityType
if yellow.Texture:
my_mat.Texture = yellow.Texture
my_mat.TextureMapping = yellow.TextureMapping
my_mat.LineWidth = yellow.LineWidth
my_mat.LineStippling = yellow.LineStippling
my_mat.StipplingPattern = yellow.StipplingPattern
my_mat.StipplingScale = yellow.StipplingScale
my_mat.RenderOrder = yellow.RenderOrder
my_mat.DepthComparison = yellow.DepthComparison
app.addMaterial(my_mat)

my_mat.Opacity = 0.5
my_mat.OpacityType = VC_MATERIAL_TRANSPARENCY_CONSTANT
for set in geo_cont.GeometrySets:
set.Material = my_mat
geo_feat.rebuild()
app.render()


ConveyorGeometry.vcmx (115 KB)

1 Like

Alright, thanks! I’ll have a closer look at it this afternoon.

For some quick visualization purposes it’s sometimes easier to use NodeMaterial. You can set the whole component or the whole hierarchy tree to inherit the node material. This is very fast because it doesn’t require geometry rebuilding. It is also easy to go back to original materials. You simply set NodeMaterial to None and the feature, geometry set and component materials will be rendered again.

comp.NodeMaterial = my_mat
comp.MaterialInheritance = VC_MATERIAL_FORCE_INHERIT
# reset back like this
comp.NodeMaterial = None

 

1 Like