Ejemplo n.º 1
0
    def execute(self, context):

        # if paths are still initializing report that to user and don't execute import
        if operators.world.SCSPathsInitialization.is_running():

            self.report({
                'INFO'
            }, "Can't import yet, paths initialization is still in progress! Try again in few moments."
                        )

            # there is no way to keep current operator alive if we want to abort import sequence.
            # That's why we call another import operator, which will end up with
            # printing out above info and taking us back to import screen with file browser.
            bpy.ops.import_mesh.pim('INVOKE_DEFAULT')

            return {'FINISHED'}

        if not _has_view3d_space(context.screen):
            message = "Cannot import SCS Models, no 3D viewport found! Make sure you have at least one 3D view visible."
            self.report({'ERROR'}, message)
            lprint("E " + message)
            return {'FINISHED'}

        paths = [
            os.path.join(self.directory, name.name) for name in self.files
        ]
        if not paths:
            paths.append(self.path)

        failed_files = []
        for filepath in paths:

            result = False
            if filepath.endswith(".pim") or filepath.endswith(".pim.ef"):

                # check extension for DEF format and properly assign it to name suffix
                ef_format_suffix = ""
                if filepath.endswith(".ef"):
                    ef_format_suffix = ".ef"
                    filepath = filepath[:-len(ef_format_suffix)]

                filepath = filepath[:-4]

                try:

                    _get_scs_globals().import_in_progress = True
                    result = _pix_import.load(context,
                                              filepath,
                                              name_suffix=ef_format_suffix)
                    _get_scs_globals().import_in_progress = False

                except Exception as e:

                    _get_scs_globals().import_in_progress = False
                    context.window.cursor_modal_restore()

                    trace_str = traceback.format_exc().replace("\n", "\n\t   ")
                    lprint("E Unexpected %r accured during import:\n\t   %s",
                           (type(e).__name__, trace_str))

            if result is False:
                failed_files.append(str(filepath).replace("\\", "/"))

        if len(failed_files) > 0:
            err_message = "E Following files failed to load:"

            for _ in failed_files:
                err_message += "\n\t   -> %r\n"

            lprint(err_message,
                   tuple(failed_files),
                   report_warnings=1,
                   report_errors=1)

        return {'FINISHED'}
Ejemplo n.º 2
0
    def execute(self, context):

        from io_scs_tools.internals.containers.config import AsyncPathsInit

        # if paths are still initializing report that to user and don't execute import
        if AsyncPathsInit.is_running():

            self.report({'INFO'}, "Can't import yet, paths initialization is still in progress! Try again in few moments.")

            # revoke to add new fileselect dialog otherwise this operator will finish
            return self.invoke(context, None)

        if not _has_view3d_space(context.screen):
            message = "Cannot import SCS Models, no 3D viewport found! Make sure you have at least one 3D view visible."
            self.report({'ERROR'}, message)
            lprint("E " + message)
            return {'FINISHED'}

        paths = [os.path.join(self.directory, name.name) for name in self.files]
        if not paths:
            paths.append(self.path)

        failed_files = []
        for filepath in paths:

            result = False
            if filepath.endswith(".pim") or filepath.endswith(".pim.ef"):

                # check extension for DEF format and properly assign it to name suffix
                ef_format_suffix = ""
                if filepath.endswith(".ef"):
                    ef_format_suffix = ".ef"
                    filepath = filepath[:-len(ef_format_suffix)]

                filepath = filepath[:-4]

                try:

                    _get_scs_globals().import_in_progress = True
                    result = _pix_import.load(context, filepath, name_suffix=ef_format_suffix)
                    _get_scs_globals().import_in_progress = False

                except Exception as e:

                    _get_scs_globals().import_in_progress = False
                    context.window.cursor_modal_restore()

                    trace_str = traceback.format_exc().replace("\n", "\n\t   ")
                    lprint("E Unexpected %r accured during import:\n\t   %s", (type(e).__name__, trace_str))

            if result is False:
                failed_files.append(str(filepath).replace("\\", "/"))

        if len(failed_files) > 0:
            err_message = "E Following files failed to load:"

            for _ in failed_files:
                err_message += "\n\t   -> %r\n"

            lprint(err_message, tuple(failed_files), report_warnings=1, report_errors=1)

        return {'FINISHED'}