5
$\begingroup$

I have a scene in which I want to render some of the same objects in two separate Render Layers, with different modifiers in each Render Layer. I know how to link modifiers using Ctrl+L > Modifiers, all I want to know if there is a feature, add-on, or the possibility of adding a feature, like the change all Materials option, just for modifiers.

In very simple terms, how can you animate the linking of Modifiers? (change the link parent)

$\endgroup$
3
$\begingroup$

here is a code that keeps a specific group of objects related to another object modifiers this is how it works :

  • add the selected objects to a group named 'linked objects'
  • rename the active object 'source object'
  • whenever the function is called it copies the modifiers parameters from the 'source object' to the rest objects in the group and if the modifier is not present it creates a new one
  • the function is appended to the scene_update_pre() handler to be called automatically

Note : - before you run the script make sure to select your objects and the active object is going to be the source object thus it will be renamed ( you can make a dummy object as the source to keep the names) - you can add/remove other objects later to/from the group because the update is related to the group not specific objects

import bpy

bpy.context.active_object.name = 'source_object'
linked_objects = bpy.data.groups.new('Linked_objects')
selected_objects = [obj for obj in bpy.context.selected_objects 
                            if obj.type == bpy.context.active_object.type]
for obj in selected_objects:        
      linked_objects.objects.link(obj)


def link_modifiers(context):

    linked_objects = bpy.data.groups['Linked_objects'].objects
    source_object = bpy.context.scene.objects['source_object']

    for obj in linked_objects:
        for mSrc in source_object.modifiers:
            mDst = obj.modifiers.get(mSrc.name, None)
            if not mDst:
                mDst = obj.modifiers.new(mSrc.name, mSrc.type)

            # collect names of writeable properties
            properties = [p.identifier for p in mSrc.bl_rna.properties
                          if not p.is_readonly]

            # copy those properties
            for prop in properties:
                setattr(mDst, prop, getattr(mSrc, prop))

bpy.app.handlers.scene_update_pre.append(link_modifiers)

the code for copying the modifiers is from this answer by Adhi so thanks Adhi

the code needs more tweaking especially the handler choice I'm new to this so any advice would be appreciated

Animation Render test with two modifiers with drivers applied only to the source object "the orange cube": render result

$\endgroup$
  • $\begingroup$ Looks like this has a lot of potential! How does it respond to render layer rendering during i.e. rendering an animation? $\endgroup$ – VRM Feb 16 '15 at 23:10
  • $\begingroup$ I'm not sure yet :) , but i think that the 'scene_update_pre' get called alot so it will be always updated ' i guess' $\endgroup$ – Chebhou Feb 16 '15 at 23:11
  • 1
    $\begingroup$ Let me know of any updates then, would be glad to find a solution that definitely works. $\endgroup$ – VRM Feb 16 '15 at 23:40
  • $\begingroup$ Very cool! There appears to be some delay though in the link, I saw the orange one go first, then a frame or two later the others would change. Is that the case? $\endgroup$ – VRM Feb 24 '15 at 15:02
  • $\begingroup$ @NoviceInDisguise yes i've noticed that ,so i have to ask about the force update the script with every frame change ? do you have any suggestions ? $\endgroup$ – Chebhou Feb 24 '15 at 15:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.