2

How would I create a new texture for a particle system? I tried bpy.ops.texture.new() but that wouldn't create any type of texture.

1 Answers1

1

after run:

import bpy
bpy.ops.texture.new()

you can see the "new" texture from:

enter image description here

/// update

*///////////////**

you can change the current texture to the "new one" with a simple code.. in this case my material name is 'Material', and after that you can change anything, for example I apply the new texture and change the type from CLOUDS :

import bpy

D = bpy.data
ob = bpy.context.active_object

bpy.ops.texture.new()
text =bpy.data.textures[len(bpy.data.textures)-1]
mat = bpy.data.materials['Material']
slots = mat.texture_slots
for slot in slots:
    try:
        slot.texture = text
        bpy.data.textures[text.name].type = 'CLOUDS'
    except:
        print("empty slot")

ACTUALLY , you have some better options to add textures, as texture slot add:

mat = bpy.data.materials['Material']
tex = bpy.data.textures.new("SomeName", 'IMAGE')
slot = mat.texture_slots.add()
slot.texture = tex
yhoyo
  • 2,285
  • 13
  • 32
  • Sorry but I have a few mores questions. How would I use this texture in a script and how would I specify which type of texture it is? –  Jan 09 '17 at 21:53
  • @bunnybot5555, I update the answere, I hope this help you – yhoyo Jan 09 '17 at 22:38
  • When I do the operation tex = bpy.data.textures.new("SomeName", 'IMAGE') What I get is > TypeError: Calling operator "bpy.ops.texture.new" error, expected a

    string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN') Can you help in this? Thanks.

    – Shuangjun Liu May 14 '18 at 16:00
  • @ShuangjunLiu There is a difference between bpy.ops.textures.new() operator (the call to create the error message above) and bpy.data.textures.new(...) your stated script. – batFINGER May 14 '18 at 16:19
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Ray Mairlot May 14 '18 at 16:26