0
$\begingroup$

To control my blender animation, I am using WebUi that sends a message to Ros through Rosbridge.

Before doing so, I create a Ros Subscriber in blender that listens for a signal from WebUi and creates a simple Cube in a Scene. It is not working.

Here is my complete subscriber code that I wrote in blender's text editor:

import rospy
import bpy
from std_msgs.msg import String

def callback(data):
    if data.data == "create":
        bpy.ops.mesh.primitive_cube_add()
    if data.data == "shutdown":
        rospy.signal_shutdown("server stops")

def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("chatter",String,callback)
    rospy.spin()
listener()

When bpy.ops.mesh.primitive_cube_add() is replaced by printing some messages it works, but not any command that acts upon the blender scene.

$\endgroup$
  • $\begingroup$ Blender should print some errors which would help us (and you) figure out the problem. It is most likely a context issue, so rather than use bpy.ops... create the mesh from scratch yourself. (look at the templates in blender's Text Editor, or wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/… ) $\endgroup$ – Greg Zaal Oct 7 '14 at 9:44
  • $\begingroup$ my intention is not to create a mesh only to mention as example. you can try any blender command in place of bpy.ops... thanks. $\endgroup$ – Helen Oct 7 '14 at 11:08
  • $\begingroup$ My point is that it might be the use of an operator (bpy.ops.*) which is causing the error - does it still fail with bpy.data.meshes.new(name+'Mesh') ? $\endgroup$ – Greg Zaal Oct 7 '14 at 11:20
  • $\begingroup$ the problem has nothing to do with bpy.ops.mesh.... $\endgroup$ – Helen Oct 7 '14 at 11:39

Your Answer

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

Browse other questions tagged or ask your own question.