Thank you for the quick help Eric, it works great!

On Tue, Nov 13, 2012 at 9:44 AM, Eric Thivierge <ethivie...@gmail.com>wrote:

> You need to see if there are any image clips on the material. On the
> material object you can use the .ImageClips which returns the collection of
> image clips connected to the material. Then test the collection to see if
> there are any in it using the Property "Count".
>
> # Python
> oMatLib = Application.Selection(0).Library # Material Library
> oMat =Application.Selection(0) # Material
> collImageClips = oMat.ImageClips # Collection of image clips
>
> if collImageClips.Count > 0:
>     oClipName = collImageClips(0).Name # Pick first image clip found
>     oMat.Name = oClipName.Name.replace("_tif", "_Sh")
> else:
>     # code to create new diffuse texture and connect it
>
> You should be able to convert to jscript rather painlessly.
>
>
> --------------------------------------------
> Eric Thivierge
> http://www.ethivierge.com
>
>
>
> On Tue, Nov 13, 2012 at 7:28 PM, Christian Gotzinger <
> cgo...@googlemail.com> wrote:
>
>> Hi list,
>>
>> Beginner stuff here. I want to test whether an object's material has a
>> texture. If it has a texture, the material should be named like the texture
>> source. If the material has no texture, a diffuse texture should be applied.
>>
>> This is what I have:
>> var MyMatLibrary = Application.Selection(0).Material.Library;
>> var MyMatName = Application.Selection(0).Material.Name;
>> var MyTextureName = Application.Selection(0).
>> Material.CurrentImageClip.Source.Name;
>>
>> MyTextureName = MyTextureName.replace("_tif","_Sh");
>>
>> SetValue(MyMatLibrary+"."+MyMatName+".Name", MyTextureName, null);
>>
>> It renames the material correctly. However, if the material has no
>> texture, line 3 throws an error. How can I test for a texture without the
>> script throwing an error?
>>
>
>

Reply via email to