mercredi 26 juin 2019

Blender code: dealing with list

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import bpy
list = []
sel = bpy.context.selected_objects    
for ob in sel:
    list.append(ob) #or list+=[ob]
    print(list)
for i in list:
    print(i)
    #action:
    #bpy.context.object.data.auto_smooth_angle = 0.436332
    i.data.auto_smooth_angle = 0.43633212

Blender code: Manage texts

Managing text settings on selection
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import bpy

newfont = bpy.data.fonts.load("//FONTS/ariblk.ttf")
Sel = bpy.context.selected_objects
for obj in Sel:
    if obj.type == 'FONT':
        print(obj)
        obj.data.font = newfont
        obj.data.size = 0.5
        obj.data.space_character = 1.4

Removing text parts on selection (a bit tricky but many possibilities)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import bpy

Sel = bpy.context.selected_objects
for obj in Sel:
    if obj.type == 'FONT':
    #remove first 7 characters
        obj.data.body = obj.data.body[7:]
        
    #remove all but 7 first characters
        obj.data.body = obj.data.body[:7]
        
    #remove from 3rd character to 7 from start
        obj.data.body = obj.data.body[:3] + obj.data.body[7:]
        
    #remove first 3 and copy first 7 to the end
        obj.data.body = obj.data.body[3:] + obj.data.body[:7]
        
    #remove first 3 and copy from after first 7 to the end
        obj.data.body = obj.data.body[3:] + obj.data.body[7:]    
    

Rename texts objects by their content (first 10 characters)
1
2
3
4
5
6
import bpy
print("*****************")
print("rename text objects by content")
for ob in bpy.data.objects:
    if ob.type == 'FONT':
        ob.name = ob.data.body[:10]

Blender code: loop by index in range


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import bpy

print("*****************")
print("This Loop Trough Multi Materials")
selection = bpy.context.object
print("SELECTED OBJECT: "+selection.name)
index = -1
for num, m in enumerate(bpy.context.object.material_slots):
    num+=1    
    bpy.context.object.active_material_index = num
    print(num)
    mat = bpy.context.object.active_material
    print(mat)

Blender code: loop by index


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import bpy
print("*****************")
print("This Loop Trough Multi Materials")

selection = bpy.context.object
print("SELECTED OBJECT: "+selection.name)
index = -1
for m in selection.material_slots:
    index += 1
    bpy.context.object.active_material_index=index
    mat = bpy.context.object.active_material
    print(mat)

mercredi 19 juin 2019

Multi Elements Text Fade-in Trick

How to made a multi elements text appear one by one in the right order with one only material, while
keeping text editable.
In the text Texture Space panel:
Disable "Auto Texture Space" check box.
For each text part, add the lenght of the previous parts in Texture Space Location.
part1= 0
part2 = part1 x dimension
part3 = part1 + part2 x dimension
...
X dimensions can be found in the right panel (N)

Cumulate previous parts dimensions in Texture Space Location




This way, the elements UV mapping will be align in x value in the right order.
Then you can animate a gradiant fade in material on it.



>>> download the scene

mardi 11 juin 2019

Repeat procedural gradient

Just need a separate XYZ node / a math-modulo node / a combineXYZ node between the UV node and the gradient node. You can ajust the number of repeat by using the mapping  X scale value