ModifyTextureMapping question

I finally figured out my problem with the Rhino.DocObjects.RhinoObject.GetTextureMapping() function. I thought I would post it here in case anyone else is stuck.

First, I was not familiar with this practice of passing an object to a function and the function modifies or ‘fills in’ that object. This is required for the transform part.

Secondly, for some reason, you have to use a ‘Strong Box’ version of the transform object. I have no idea what this really means, but, thanks to some other post I found out it is something to do with VB and/or CLR.

So here is a working (at least here) way to get the mapping object and the transform that is applied to keep the mapping lined up with the geometric object:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import clr

guid = rs.GetObject("select texture mapped object")

rObject = rs.coercerhinoobject(guid)
#Rhino.Geometry.Transform object to be 'filled in' by the GetTextureMapping function
#Also the mystery 'StrongBox' version, otherwise you get an error...
mapXform = clr.StrongBox[Rhino.Geometry.Transform]()

print "this is the Rhino.Render.TextureMapping object:"
print rObject.GetTextureMapping(1, mapXform)
print "this is the 'filled in' 'localXform':"
print mapXform
2 Likes