Add simple Texture Map in Python

I am searching around for a programmatic way of adding a simple planar UV texture map to an object in Python.

My goal is to add mappings to a bunch of flat surfaces representing planks in a wood floor, and vary the mapping parameters randomly so when I associate a material to that object (usually via a layer), the material will appear random.

Any ideas/pointers on how this could be done? Is this capability available in Python?

It is in the UI, so figure there must be hooks somewhere…



Good news - I’m well on my way to making this work. Here is the code so far:

# Create a plane
new_plane_origin = [0.0, 0.0, 0.0]
new_plane_normal = [0.0, 0.0, 1.0]
new_plane = rs.PlaneFromNormal(new_plane_origin, new_plane_normal)

# Define mapping intervals
dx = r.Geometry.Interval(0.0, 3000.0)
dy = r.Geometry.Interval(0.0, 360.0)
dz = r.Geometry.Interval(0.0, 1.0)

# Create new texture mapping
new_mapping = r.Render.TextureMapping.CreatePlaneMapping(new_plane, dx, dy, dz, False)

# Create transforms to modify the mapping as needed

# Rotation
rotation_vector = r.Geometry.Vector3d(0.0, 0.0, 1.0)
rotation_center = r.Geometry.Point3d(0.0,0.0,0.0)
new_transform_rotation = r.Geometry.Transform.Rotation(math.pi/2, rotation_vector, rotation_center)

# Translation
new_transform_translation = r.Geometry.Transform.Translation(1.0, 50.0, 1.0)

# Combine Transforms into one
new_transform = r.Geometry.Transform.Multiply(new_transform_rotation, new_transform_translation)

# set the new texture mapping
rhino_object.SetTextureMapping(1, new_mapping, new_transform)