hi,
I am trying to create an object to serve as a manager that operates on other objects.
an analogy will be something a particle emitter, that has an array of particles, and each tick update positions. This is my class
class NewtonWorld(bpy.types.Object):
"""create an interface to the newton workd"""
def __init__(self, object):
#print ("create manager one once")
self.name = 'newton_world'
self.world = newton.ndWorld()
def SetIterations (self, iterations):
self.world.SetSolverIterations(iterations)
ndWorld is a cpp class. and I tested in plain vanilla python.
So far it works until I am trying to call a function from a subclass of a blender object.
here is the operator that try that
class NewtonWorldSetProperty(bpy.types.Operator):
"""newton world set engine properties"""
bl_label = 'newton world set property'
bl_idname = 'view3d.newton_world_set_property'
bl_description = "newton world set property"
def findWorld(self):
col = bpy.data.collections.get("Collection")
if col:
for obj in col.objects:
if obj.name == 'newton_world':
print ("esta es una pura mierda 0")
return obj
return None
def execute(self, context):
scene = context.scene
world = self.findWorld()
propertyGroup = scene.newton_world_properties
world.SetIterations(propertyGroup.solverIterations)
return {'FINISHED'}
but I get this error.
location: <unknown location>:-1
Error: Python: Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender 2.93\2.93/scripts/addons/newtonPy\newtonWorld.py", line 107, in execute
world.SetIterations(propertyGroup.solverIterations)
AttributeError: 'Object' object has no attribute 'SetIterations'
location: <unknown location>:-1
normally in Cpp I would have to do a cast to teh subclass but in python that is no part of the language .
the object is part of the scene so it is of Type Object(ID),
however that object is a subclass of type Object(ID) class NewtonWorld(bpy.types.Object):
so how do people subclass from an Object and add extra information?
notice that the error has nothing to do with the CPP class, the erro is that the class does no recognize any member of any variable
another way to go around this is by adding a custom data to the superclass Object(ID),
but it seems this is not possible since the are only few types allowed (int, float, string and that sort of things)
is there any way to store a pointer to a cpp class generated by swig with and Object(ID)?
also notice that Python is a dynamically cast language, what I am doing works out of the box in vanilla python, but somehow it does not in Blender python.