1
$\begingroup$

I have the following code that turns a named object into smoke emitter that turns off and on at specified frames:

def addSmoke(objectName, start, end):
    some_obj = bpy.data.objects[objectName]
    startframe = start - 1  
    laserShowFrame = start + 2
    bpy.context.scene.frame_set(laserShowFrame)
    startframe = start + 1  
    endframe = end + 1
    bpy.context.view_layer.objects.active = some_obj
    some_obj.modifiers.new(name='Smoke', type='FLUID')
    some_obj.modifiers['Smoke'].fluid_type = 'FLOW'
    some_obj.modifiers['Smoke'].flow_settings.flow_type = 'SMOKE'
    some_obj.modifiers["Smoke"].flow_settings.flow_behavior = 'INFLOW'
    some_obj.modifiers["Smoke"].flow_settings.use_inflow = True
    some_obj.modifiers["Smoke"].flow_settings.surface_distance = 1
    some_obj.modifiers["Smoke"].flow_settings.temperature = 3
    some_obj.modifiers["Smoke"].flow_settings.smoke_color = (0.219997, 0.219997, 0.219997)
    some_obj.modifiers["Smoke"].flow_settings.density = 0
    some_obj.modifiers["Smoke"].flow_settings.keyframe_insert(data_path="density", frame= start)
    some_obj.modifiers["Smoke"].flow_settings.density = 0.183307
    some_obj.modifiers["Smoke"].flow_settings.keyframe_insert(data_path="density", frame= startframe)
    some_obj.modifiers["Smoke"].flow_settings.keyframe_insert(data_path="density", frame= end) 
    some_obj.modifiers["Smoke"].flow_settings.density = 0
    some_obj.modifiers["Smoke"].flow_settings.keyframe_insert(data_path="density", frame= endframe)
    bpy.context.view_layer.objects.active = None

It fails on this line:

some_obj.modifiers['Smoke'].fluid_type = 'FLOW'

telling me that it can not find the "Smoke" modifier. which is weird because I add it in the previous line.

KeyError: 'bpy_prop_collection[key]: key "Smoke" not found'

I am sure I am missing something small but I can't find it. When creating a Dpaint modifier I have to use this:

bpy.ops.dpaint.type_toggle(type='BRUSH')

Perhaps there is an equivalent for Smoke simulations. If there is I can't seem to find it.

$\endgroup$
1
  • 1
    $\begingroup$ I guess you can't name Fluid Modifiers I just run 0 instead of "Smoke" and it fixed it. $\endgroup$ Apr 21, 2021 at 17:02

0

You must log in to answer this question.

Browse other questions tagged .