2
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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
$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – user32399 Jan 9 '17 at 21:53
  • $\begingroup$ @bunnybot5555, I update the answere, I hope this help you $\endgroup$ – yhoyo Jan 9 '17 at 22:38
  • $\begingroup$ 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. $\endgroup$ – Shuangjun Liu May 14 '18 at 16:00
  • $\begingroup$ @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. $\endgroup$ – batFINGER May 14 '18 at 16:19
  • $\begingroup$ 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 $\endgroup$ – Ray Mairlot May 14 '18 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy