Ok, so I have this scripted set of objects set up in it’s own blend file, grouped for use by other blender files, and I would like to append the group, instantiate it multiple times and have a sane way to reference the new data instances in a sane way.
My issue is this: when I create new instances of this group in the dependent file, every datablock in the instance is copied and given a new data.00x name. I want to write the scripts in a way that is ‘instancing aware’, possibly relying on a more general relationship between the resources.
In this particular case, I have a plane and camera it uses to set up an in game render surface. I would like to be able to instantiate the group, and not end up having to manually manipulate the names of the texture image and the camera object in the logic of the plane for every new instance of the group to ‘know’ how to reference these ‘siblings’.
I know you can use parenting (though I do not want any transformations inherited between these objects), and I know you can find other group members programatically, what I do not know is how to find specific group members, or to find linked data like the texture image just from a reference to some object that uses it. I can’t just do scene.objects[‘the_camera_who_has_a_dynamically_generated_name.1234’], if you get my meaning.
I come from a mostly programming background and I pretty reliant on things like modularity and encapsulation. So also, if you think I am approaching this in a weird way feel free to correct me. This is my first post, and I am pretty new to blender over all (been playing around with it for a couple weeks), so you aren’t going to hurt my feelings or anything if you sniff out my noobness and suggest a more blender-friendly way to skin this cat.
Here is the code I am using now:
import bge
from bge import texture
from bge import logic
# names of data blocks I will need to reference for this to work
# but they change per group instance:
camName = 'SecurityCam'
texName = 'IMScreenTex'
# this is just roughly copy and pasted from the video texture section in the scripting API
cont = logic.getCurrentController()
scene = logic.getCurrentScene()
obj = cont.owner
cam = scene.objects[camName]
if not hasattr(logic, 'video'):
matID = texture.materialID(obj, texName)
logic.video = texture.Texture(obj,matID)
logic.video.source = texture.ImageRender(scene,cam)
logic.video.refresh(True)
Solution
I am not sure I really explained what I was doing all that well, but in the end I came to the conclusion that a BPY script is better suited to this sort of duplication than packaging it as a library group. Yeah, I’m new.