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 =“matname1”) = ob


but i get an error

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


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

>>> C.object.mode

>>> bpy.ops.paint.vertex_color_dirt()
Dirt calculated in 0.001000

it seems to work in console

but at end of function it still gives an error

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

got this

	ob ="matname1") = ob
# = True
#	bpy.ops.object.mode
#	bpy.ops.object.mode_set(mode='VERTEX_PAINT')


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\", 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


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


read my post, your call is bad


should be


done with the dot instead of dash

i tought i copied it over but i miss it


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 ?


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!


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.:


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.

randint(…, …)

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

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

from bmesh import types as bm_types