For the avoidance of doubt --- here's a base-class free version...
Please implement something like this... 😄
<span class="syntaxdefault"></span><span class="syntaxcomment">### pass a 'face' as the first argument<br />### and a second optional argument to convert the image texture into a PNG format<br />### it returns the new material, or 'nil' if the face is incorrect<br />### or if there's no face.material.texture...<br /></span><span class="syntaxdefault">def material_make_unique</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> png</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil unless face<br /> return nil unless face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil unless mat</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material<br /> return nil unless txt</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">mat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">texture<br /> iwi</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">txt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">width<br /> ihi</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">txt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">height<br /> </span><span class="syntaxcomment">### later we use ### texture.size=[w, h]<br /></span><span class="syntaxdefault"> tads</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">txt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">attribute_dictionaries<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> nam</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">mat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">display_name<br /> alp</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">mat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">alpha<br /> col</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">mat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">color<br /> mads</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">mat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">attribute_dictionaries<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> mats</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">materials<br /> namp</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nam</span><span class="syntaxkeyword">+</span><span class="syntaxstring">"1"<br /></span><span class="syntaxdefault"> namp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">next</span><span class="syntaxkeyword">!</span><span class="syntaxdefault"> while mats</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">namp</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> num</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">namp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(/^</span><span class="syntaxcomment">#{nam}/,"")<br /></span><span class="syntaxdefault"> nmat</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">mats</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">namp</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> tw</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">create_texture_writer<br /> tmp</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ENV</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"TEMP"</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment">### it's a PC == 'TEMP' or 'TMP'<br /></span><span class="syntaxdefault"> tmp</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ENV</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"TMPDIR"</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> unless tmp </span><span class="syntaxcomment">### it's a MAC<br /></span><span class="syntaxdefault"> tna</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">txt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">filename</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">".*"</span><span class="syntaxkeyword">)+</span><span class="syntaxdefault">num</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">extname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">txt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">filename</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> tna</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tna</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">".*"</span><span class="syntaxkeyword">)+</span><span class="syntaxstring">".png"</span><span class="syntaxdefault"> if png<br /> pth</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tmp</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> tna</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"\\"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"/"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> tw</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">load</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> true</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> tw</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> true</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> pth</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> nmat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">alpha</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">alp<br /> nmat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">color</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">col<br /> mads</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each_pair</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">k</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> nmat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">set_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">name</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> k</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> v</span><span class="syntaxkeyword">)}}</span><span class="syntaxdefault"> if mads<br /> nmat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">texture</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">pth<br /> ntxt</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nmat</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">texture<br /> ntxt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">size</span><span class="syntaxkeyword">=[</span><span class="syntaxdefault">iwi</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> ihi</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> tads</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each_pair</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">k</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> ntxt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">set_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">name</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> k</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> v</span><span class="syntaxkeyword">)}}</span><span class="syntaxdefault"> if tads<br /> return nmat<br />end<br /></span>