0
$\begingroup$

I am creating an FBX export script with following requirements:

1-Export object selection with its underlying hierarchy / child objects (WORKS!)

2-Do this even if they are hidden (DOESN'T WORK)

So far, from what I could find and test, the FBX exporter will not export objects that are hidden from view. How could I go around this?

For example I want to export this:

->Object MSH_Table_01 (Parent)

    ->UCX_MSH_Table_01_01 (Child, Hidden)

Without having to manually set UCX_MSH_Table_01_01 as visible.

Here's what I have so far, any help appreciated.

EDIT: My code pasted weird, but the important part is at the bottom

Thanks:

#python

#------------------------------
#Import required libraries
#------------------------------

import sys
import bpy
import os, errno
import configparser
import subprocess

#------------------------------
#Determine open scene filepath
#------------------------------

filepath = bpy.data.filepath
directory = os.path.dirname(filepath)

#-----------------------------------
#Read user settings from config file
#-----------------------------------

Config = configparser.ConfigParser()
Config.read("C:\\XXXXX\\ProjectDirectoryStructure.ini")
Config.sections()
['ProjectDirectoryStructure']

#-------------------------------------------------------
#Defining helper function  to read data from config file
#-------------------------------------------------------

def ConfigSectionMap(section):
    dict1 = {}
    options = Config.options(section)
    for option in options:
        try:
            dict1[option] = Config.get(section, option)
            if dict1[option] == -1:
                DebugPrint("skip: %s" % option)
        except:
            print("exception on %s!" % option)
            dict1[option] = None
    return dict1

#---------------------------------------------------
#Import variable(s) from ProjectDirectoryStructure.ini
#---------------------------------------------------

path_scenes = ConfigSectionMap("ProjectDirectoryStructure")['path_scenes']
path_final = ConfigSectionMap("ProjectDirectoryStructure")['path_final']

#--------------------------
#Determine export directory
#--------------------------

directory_removelength = len(path_scenes)
export_directory = directory[:-directory_removelength]
export_directory = export_directory + path_final

#-----------------------
#Export FBX in directory
#-----------------------

scene = bpy.context.scene
for ob in bpy.context.selected_objects:

    #Make Sure what we are exporting is a mesh
    if ob.type == 'MESH':
        #select underlying hierarchy
        bpy.ops.object.select_hierarchy(direction='CHILD', extend=True)
        #export the currently selected object to its own file based on its name
        bpy.ops.export_scene.fbx(
                filepath=os.path.join(export_directory, ob.name + '.fbx'),
                use_selection=True,
                )
        #unselect underlying hierarchy
        bpy.ops.object.select_hierarchy(direction='PARENT', extend=False)
    # deselect the object and move on to another if any more are left
    ob.select = False
$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.