0
$\begingroup$

This is the code I wrote for rotating the .fbx model I imported from Rhino.

bl_info = {
    "name": "Reture Z axls",
    "category": "Object",
}

import bpy


class ObjectRotateX(bpy.types.Operator):
    """My Object Rotate Script"""
    bl_idname = "object.rotate_x"
    bl_label = "Rotate X by 90"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):

        scene = context.scene
        for obj in scene.objects:
            obj.rotation_euler = (0,0,0)


        return {'FINISHED'}


def register():
    bpy.utils.register_class(ObjectRotateX)


def unregister():
    bpy.utils.unregister_class(ObjectRotateX)


if __name__ == "__main__":
    register()

The problem is that it will rotate everything in the scene including the camera. I wonder if there is better way to do this? Also is there anyway I can rotate each object seperately?
Thank you!

$\endgroup$

3 Answers 3

1
$\begingroup$

This sounds like a task that should be performed by the import FBX addon. The addon does include some options for rotation.

The first set of options allow you to define which axis is up and which is forward, if those two don't resolve the placement you may also need to try turning off the last option Use Pre/Post Rotation

enter image description here

$\endgroup$
0
$\begingroup$

I believe that it would be easier done if you knew the names of the objects that you wished to ignore.

I tried exporting the default scene to FBX, and then re-imported the same FBX after deleting everything.

The FBX file seemed to maintain the object names, so adding an if statement to iterate through the 'bpy.data.objects.items()[index][0]' to check for the known name, seems like an easy enough solution. I'm just not sure if the export for Rhino exports the names. I know you can set a name on any object within Rhino though (via the properties panel).

eg: If I wanted to ignore my default named 'Camera' object

for i in bpy.data.objects.items():
     if i[0] == 'Camera':
         print ("ignored Camera Object")
     else:
         print(i[0])

OUTPUT:
ignored Camera Object
Cube
Lamp

I hope that is helpful. RRiggs

$\endgroup$
1
  • 3
    $\begingroup$ A reasonable idea, but relying on the name 'Camera' is limiting. A better way would be for obj in bpy.data.objects: if obj.type=='CAMERA':... $\endgroup$
    – sambler
    Feb 11, 2016 at 10:17
0
$\begingroup$

There are two answers.

The simplest answer is to modify your for loop to only operate on the model you imported.

for obj in scene.objects
    if obj is 'Model_id' #some identifier that you know or can find
        obj.rotation_euler = (0,0,0)
    else
        #don't

The more correct way is to select the object you want, instead of operating on the whole scene context.

#unselect everything...
bpy.ops.object.select_all(action='DESELECT')

#then select just the object you want...
bpy.data.objects['Cube'].select = True

#AND make it active...
bpy.context.scene.objects.active = bpy.data.objects['Sphere.017']

You can also query which object is active

bpy.context.scene.objects.active

to see if that's the one you want to operate on.

ANOTHER answer is to delete everything first, then import and rotate the way you are already ;-)

Hope that helps!

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .