how to add dirt map ?

i have an existing obket on which i added a new node mat cycles

now i need to add a dirt map

ob = bpy.data.objects.get(“matname1”)
bpy.context.scene.objects.active = ob

bpy.ops.paint_vertex_color_dirt()

but i get an error

so i guess i need to first select the paint mode but how to do that ?

thanks

It isn’t mode-dependent. replace the first _ by .

>>> C.object.mode
'OBJECT'

>>> bpy.ops.paint.vertex_color_dirt()
Dirt calculated in 0.001000
{'FINISHED'}

it seems to work in console

but at end of function it still gives an error

scriptmatlib7.blend\cyclesscriptmatlib7.py", line 11488, in Grunge1
TypeError: ‘BPyOpsSubMod’ object is not callable

got this


	
	addmat3(matname1)
	
	ob = bpy.data.objects.get("matname1")
	bpy.context.scene.objects.active = ob
#	ob.select = True
	
#	bpy.ops.object.mode
	bpy.ops.object.mode_set(mode='OBJECT')
#	bpy.ops.object.mode_set(mode='VERTEX_PAINT')
	bpy.ops.paint_vertex_color_dirt()


thanks

did another test and get the following error

ob mat name = Grunge1
ob active name = <bpy_struct, Object(“Cube.002”)>

ob1= <bpy_struct, Object(“Cube.002”)>
Traceback (most recent call last):
scriptmatlib7.blend\cyclesscriptmatlib7.py", line 11492, in Grunge1
TypeError: ‘BPyOpsSubMod’ object is not callable

i can see the viewport into vert paint mode and col is added to the object
but still bug

use this code here

bpy.ops.object.mode_set(mode=‘OBJECT’)
bpy.ops.object.mode_set(mode=‘VERTEX_PAINT’)
bpy.ops.paint_vertex_color_dirt()

may be i should not set the viewport in vert paint mode

thanks

read my post, your call is bad

bpy.ops.paint_vertex_color_dirt()

should be

bpy.ops.paint.vertex_color_dirt()

done with the dot instead of dash

i tought i copied it over but i miss it

thanks

i tried to add some random values for the paint verts

added the random module

and tried this

bpy.ops.paint.vertex_color_dirt(blur_strength=random.uniform(0.01,1.0),blur_iterations=random.randint(0,40),clean_angle=3.14159, dirt_angle=0.0, dirt_only=False)

and i get an error on the random uniform

same command in console works fine

any restriction here ?

thansk

there’s certainly never such a restriction, but there are wrong contexts and missing imports.

This works fine for me:

import bpy
import random

bpy.ops.paint.vertex_color_dirt(blur_strength=random.uniform(0.01,1.0),blur_iterations=random.randint(0,40),clean_angle=3.14159, dirt_angle=0.0, dirt_only=False)

strange i used the inport random *
and it did not recognise the uniform methods
then i change it to
from random import randint,uniform and now it seems to work fine!
there may be same name use in other part of the API and did not like it may be!

thanks

You certainly did not use this:

import random *

There are two kinds of imports in python:

import random

Imports the module random as namespace “random”. To access any of the module’s functions or classes, you use e.g.:

random.uniform(…)

Bad call:
uniform() # not defined

The other kind of import will import all functions and classes, like if they were part of the importing script:

from random import *
  • means everything from random module.

This will import everything in the local namespace, e.g.

uniform(…)
randint(…, …)

Bad call:
random.uniform() # random is unknown

http://docs.python.org/3.3/tutorial/modules.html#more-on-modules

from … import … is like #include in C/C++. Note that it may override existing functions etc., e.g. if you defined function “uniform” in your namespace already.

If necessary, you can use the “as” statement to use a new name(space):

import bmesh as B
B.new()

from bmesh import types as bm_types
print(bm_types.BMVert)