Esempio n. 1
0
def export_object(self, context):
    epath = context.scene.jarch_save_path_export #export path
    error = True
    if "//" in epath:
        epath = bpy.path.abspath(epath)
    if path.exists(epath):
        error = False    
        
    #if path exists
    if error == False:
        ob = context.object
        epath += "\\" + (ob.name).replace(".", "_") + ".jarch"
        root = ET.Element("object")
        
        t = datetime.now()
        date_string = "{}/{}/{} at {}:{}:{} in {}".format(t.month, t.day, t.year, t.hour, t.minute, t.second, tzname[0])
        root.attrib = {"Date_Created":date_string, "Mesh_Name":ob.data.name, "Object_Name":ob.name}                       
    
        #create XML tree
        properties = ET.SubElement(root, "properties")        
            
        #properties
        props = ["mat", "if_tin", "if_wood", "if_vinyl", "is_cut", "cut_name", "object_add", "from_dims", "angle_off", "is_slope", "over_height", "over_width", "board_width", 
                "batten_width", "board_space", "slope", "is_width_vary", "width_vary", "is_cutout", "num_cutouts", "is_length_vary", "length_vary", "max_boards", 
                "res", "is_screws", "bevel_width", "x_offset", "b_width", "b_height", "b_ran_offset", "b_offset", "b_gap", "m_depth", "b_vary", "is_bevel", 
                "bump_type", "color_style", "mat_color2", "mat_color3", "color_sharp", "mortar_color", "mortar_bump", "brick_bump", "color_scale", "bump_scale", 
                "is_corner", "is_invert", "is_soldier", "is_left", "is_right", "av_width", "av_height", "s_random", "b_random", "s_mortar", "s_mat", "is_material", 
                "mat_color", "is_preview", "im_scale", "col_image", "is_bump", "norm_image", "bump_amo", "unwrap", "is_rotate", "random_uv", "nc1", "nc2", "nc3", 
                "nc4", "nc5", "nc6", "f_object_add", "f_cut_name", "f_is_cut", "f_mat", "f_if_wood", "f_if_tile", "f_over_width", "f_over_length", "f_b_width", 
                "f_b_length", "f_b_length2", "f_is_length_vary", "f_length_vary", "f_max_boards", "f_thickness", "f_is_width_vary", "f_width_vary", "f_num_boards", "f_space_l", 
                "f_space_w", "f_spacing", "f_is_bevel", "f_res", "f_bevel_amo", "f_is_ran_height", "f_ran_height", "f_t_width", "f_t_length", "f_grout_depth", 
                "f_is_offset", "f_offset", "f_is_random_offset", "f_offset_vary", "f_t_width2", "f_is_material", "f_is_preview", "f_im_scale", "f_col_image", 
                "f_is_bump", "f_norm_image", "f_bump_amo", "f_unwrap", "f_mortar_color", "f_mortar_bump", "f_is_rotate", "f_random_uv", "s_object_add", "s_style", 
                "s_overhang", "s_num_steps", "s_num_steps2", "s_tread_width", "s_riser_height", "s_over_front", "s_over_sides", "s_width", "s_is_riser", 
                "s_num_land", "s_is_close", "s_is_set_in", "s_is_landing", "s_is_light", "s_num_steps0", "s_tread_width0", "s_riser_height0", "s_landing_depth0", 
                "s_landing_rot0", "s_over_front0", "s_over_sides0", "s_overhang0", "s_is_back0", "s_num_steps1", "s_landing_rot1", "s_tread_width1", 
                "s_riser_height1", "s_landing_depth1", "s_over_front1", "s_over_sides1", "s_overhang1", "s_is_back1", "s_w_rot", "s_num_rot", "s_rot", 
                "s_pole_dia", "s_pole_res", "s_tread_res", "s_is_material", "s_is_preview", "s_im_scale", "s_col_image", "s_is_bump", "s_norm_image", 
                "s_bump_amo", "s_is_rotate", "s_im_scale2", "s_col_image2", "s_is_bump2", "s_norm_image2", "s_bump_amo2", "s_is_rotate2", "s_unwrap", 
                "s_random_uv", "dims"]                
                
        for prop in props:
            #determine type
            val = eval("ob." + prop)
            if type(val) is int:
                t = "int"
            elif type(val) is float:
                t = "float"
            elif type(val) is str:
                t = "str"
            elif type(val) is Color:
                t = "Color"
                val = tuple(val)
            elif type(val) is bool:
                t = "bool"
                    
            ET.SubElement(properties, "prop", {"value":str(val), "name":prop, "type":t})
            
        #save file
        tree = ET.ElementTree(root)
        error2 = True
        try:
            tree.write(epath)
            error2 = False
        except (PermissionError, FileNotFoundError):
           self.report({"ERROR"}, "Permission Denied At That Location")
           
        #make text pretty
        if error2 == False:
            pretty_file = pretty_parse(epath)
            pretty_text = pretty_file.toprettyxml()
            file = open(epath, "w")
            file.write(pretty_text)
            file.close()
Esempio n. 2
0
def export_object(self, context):
    epath = context.scene.jarch_save_path_export  #export path
    error = True
    if "//" in epath:
        epath = bpy.path.abspath(epath)
    if path.exists(epath):
        error = False

    #if path exists
    if error == False:
        ob = context.object
        epath += "\\" + (ob.name).replace(".", "_") + ".jarch"
        root = ET.Element("object")

        t = datetime.now()
        date_string = "{}/{}/{} at {}:{}:{} in {}".format(
            t.month, t.day, t.year, t.hour, t.minute, t.second, tzname[0])
        root.attrib = {
            "Date_Created": date_string,
            "Mesh_Name": ob.data.name,
            "Object_Name": ob.name
        }

        #create XML tree
        properties = ET.SubElement(root, "properties")

        #properties
        props = [
            "mat", "if_tin", "if_wood", "if_vinyl", "is_cut", "cut_name",
            "object_add", "from_dims", "angle_off", "is_slope", "over_height",
            "over_width", "board_width", "batten_width", "board_space",
            "slope", "is_width_vary", "width_vary", "is_cutout", "num_cutouts",
            "is_length_vary", "length_vary", "max_boards", "res", "is_screws",
            "bevel_width", "x_offset", "b_width", "b_height", "b_ran_offset",
            "b_offset", "b_gap", "m_depth", "b_vary", "is_bevel", "bump_type",
            "color_style", "mat_color2", "mat_color3", "color_sharp",
            "mortar_color", "mortar_bump", "brick_bump", "color_scale",
            "bump_scale", "is_corner", "is_invert", "is_soldier", "is_left",
            "is_right", "av_width", "av_height", "s_random", "b_random",
            "s_mortar", "s_mat", "is_material", "mat_color", "is_preview",
            "im_scale", "col_image", "is_bump", "norm_image", "bump_amo",
            "unwrap", "is_rotate", "random_uv", "nc1", "nc2", "nc3", "nc4",
            "nc5", "nc6", "f_object_add", "f_cut_name", "f_is_cut", "f_mat",
            "f_if_wood", "f_if_tile", "f_over_width", "f_over_length",
            "f_b_width", "f_b_length", "f_b_length2", "f_is_length_vary",
            "f_length_vary", "f_max_boards", "f_thickness", "f_is_width_vary",
            "f_width_vary", "f_num_boards", "f_space_l", "f_space_w",
            "f_spacing", "f_is_bevel", "f_res", "f_bevel_amo",
            "f_is_ran_height", "f_ran_height", "f_t_width", "f_t_length",
            "f_grout_depth", "f_is_offset", "f_offset", "f_is_random_offset",
            "f_offset_vary", "f_t_width2", "f_is_material", "f_is_preview",
            "f_im_scale", "f_col_image", "f_is_bump", "f_norm_image",
            "f_bump_amo", "f_unwrap", "f_mortar_color", "f_mortar_bump",
            "f_is_rotate", "f_random_uv", "s_object_add", "s_style",
            "s_overhang", "s_num_steps", "s_num_steps2", "s_tread_width",
            "s_riser_height", "s_over_front", "s_over_sides", "s_width",
            "s_is_riser", "s_num_land", "s_is_close", "s_is_set_in",
            "s_is_landing", "s_is_light", "s_num_steps0", "s_tread_width0",
            "s_riser_height0", "s_landing_depth0", "s_landing_rot0",
            "s_over_front0", "s_over_sides0", "s_overhang0", "s_is_back0",
            "s_num_steps1", "s_landing_rot1", "s_tread_width1",
            "s_riser_height1", "s_landing_depth1", "s_over_front1",
            "s_over_sides1", "s_overhang1", "s_is_back1", "s_w_rot",
            "s_num_rot", "s_rot", "s_pole_dia", "s_pole_res", "s_tread_res",
            "s_is_material", "s_is_preview", "s_im_scale", "s_col_image",
            "s_is_bump", "s_norm_image", "s_bump_amo", "s_is_rotate",
            "s_im_scale2", "s_col_image2", "s_is_bump2", "s_norm_image2",
            "s_bump_amo2", "s_is_rotate2", "s_unwrap", "s_random_uv", "dims"
        ]

        for prop in props:
            #determine type
            val = eval("ob." + prop)
            if type(val) is int:
                t = "int"
            elif type(val) is float:
                t = "float"
            elif type(val) is str:
                t = "str"
            elif type(val) is Color:
                t = "Color"
                val = tuple(val)
            elif type(val) is bool:
                t = "bool"

            ET.SubElement(properties, "prop", {
                "value": str(val),
                "name": prop,
                "type": t
            })

        #save file
        tree = ET.ElementTree(root)
        error2 = True
        try:
            tree.write(epath)
            error2 = False
        except (PermissionError, FileNotFoundError):
            self.report({"ERROR"}, "Permission Denied At That Location")

        #make text pretty
        if error2 == False:
            pretty_file = pretty_parse(epath)
            pretty_text = pretty_file.toprettyxml()
            file = open(epath, "w")
            file.write(pretty_text)
            file.close()
Esempio n. 3
0
def export_material(self, context):
    mat_list = []
    et = context.scene.export_materials_type
    folder_path = ""
    folder_name = ""
    # determine what all is being exported
    if et == "1" and context.material != None:
        mat_list.append(context.material.name)
    elif et == "2":
        for i in context.object.data.materials:
            mat_list.append(i.name)
    elif et == "3":
        for i in bpy.data.materials:
            mat_list.append(i.name)
    # export materials
    for mat_name in mat_list:
        mat = bpy.data.materials[mat_name]
        epath = context.scene.save_path_export
        if mat != None:
            if epath != "":
                # try open file
                error = True
                if "//" in epath:
                    epath = bpy.path.abspath(epath)
                if path.exists(epath):
                    error = False
                # error = True
                if error == False:
                    root = ET.Element("material")
                    names = {}
                    data = []
                    m_nodes = mat.node_tree.nodes
                    m_n = []  # main nodes
                    m_l = []  # main links
                    images = []
                    for n_main in m_nodes:  # nodes
                        out, is_group, im = export_node_type(n_main)
                        m_n.append(out)
                        images.append(im)
                        if is_group == True:  # group level 1
                            g_n = []
                            g_l = []
                            for n_group in n_main.node_tree.nodes:  # nodes
                                g_out, is_group1, im1 = export_node_type(n_group)
                                g_n.append(g_out)
                                images.append(im1)

                                if is_group1 == True:  # group level 2
                                    g_n2 = []
                                    g_l2 = []
                                    for n_group2 in n_group.node_tree.nodes:  # nodes
                                        g_out2, is_group2, im2 = export_node_type(n_group2)
                                        g_n2.append(g_out2)
                                        images.append(im2)

                                        if is_group2 == True:  # group level 3
                                            g_n3 = []
                                            g_l3 = []
                                            for n_group3 in n_group2.node_tree.nodes:  # nodes
                                                g_out3, is_group3, im3 = export_node_type(n_group3)
                                                g_n3.append(g_out3)
                                                images.append(im3)

                                                if is_group3 == True:  # group level 4
                                                    g_n4 = []
                                                    g_l4 = []
                                                    for n_group4 in n_group3.node_tree.nodes:  # nodes
                                                        g_out4, is_group4, im4 = export_node_type(n_group4)
                                                        g_n4.append(g_out4)
                                                        images.append(im4)

                                                    for l_group4 in n_group3.node_tree.links:  # links
                                                        out5 = link_info(l_group4)
                                                        g_l4.append(out5)
                                                    data.append([g_n4, g_l4])
                                                    names[c_name(n_group3.node_tree.name)] = len(data) - 1

                                            for l_group3 in n_group2.node_tree.links:  # links
                                                out4 = link_info(l_group3)
                                                g_l3.append(out4)
                                            data.append([g_n3, g_l3])
                                            names[c_name(n_group2.node_tree.name)] = len(data) - 1

                                    for l_group2 in n_group.node_tree.links:  # links
                                        out3 = link_info(l_group2)
                                        g_l2.append(out3)
                                    data.append([g_n2, g_l2])
                                    names[c_name(n_group.node_tree.name)] = len(data) - 1

                            for l_group in n_main.node_tree.links:  # links
                                out2 = link_info(l_group)
                                g_l.append(out2)
                            data.append([g_n, g_l])
                            names[c_name(n_main.node_tree.name)] = len(data) - 1

                    for l_main in mat.node_tree.links:  # links
                        out = link_info(l_main)
                        m_l.append(out)
                    data.append([m_n, m_l])
                    names["main"] = len(data) - 1

                    # write data
                    # material attribs
                    t = datetime.now()
                    date_string = "{}/{}/{} at {}:{}:{} in {}".format(t.month, t.day, t.year, t.hour, t.minute, t.second, tzname[0])
                    root.attrib = {"Render_Engine": context.scene.render.engine, "Material_Name": c_name(mat.name), "Date_Created": date_string, "Number_Of_Nodes": ""}
                    n = 0
                    num_nodes = 0
                    for group in names:
                        sub_e = ET.SubElement(root, group.replace("/", "_"))
                        d = data[names[group]]
                        sub_e_nodes = ET.SubElement(sub_e, group.replace("/", "_") + "_nodes")
                        for i in d[0]:  # nodes
                            ET.SubElement(sub_e_nodes, "node" + str(n), {"name": i["name"], "bl_idname": i["bl_idname"], "label": i["label"], "color": i["color"], "parent": str(i["parent"]), "location": i["location"],
                                                                         "height": i["height"], "width": i["width"], "mute": i["mute"], "hide": i["hide"], "inputs": i["inputs"], "outputs": i["outputs"], "node_specific": i["node_specific"], "use_custom_color": i["use_custom_color"]})
                            num_nodes += 1
                        sub_e_links = ET.SubElement(sub_e, group.replace("/", "_") + "_links")
                        for i in d[1]:  # links
                            ET.SubElement(sub_e_links, "link" + str(n), {"link_info": i})
                            n += 1
                    root.attrib["Number_Of_Nodes"] = str(num_nodes)
                    # get order of groups
                    pre_order = sorted(names.items(), key=operator.itemgetter(1))
                    order = [i[0].replace("/", "_") for i in pre_order]
                    root.attrib["Group_Order"] = str(order)
                    # images
                    img_out = []
                    save_path = epath + c_name(mat.name) + ".bmat"
                    # create folder if needed
                    if (et == "2" and len(context.object.data.materials) >= 2) or (et == "3" and len(bpy.data.materials) >= 2):
                        if not path.exists(epath + c_name(mat.name)) and folder_path == "":
                            try:
                                makedirs(epath + c_name(mat.name))
                                folder_path = epath + c_name(mat.name)
                                folder_name = c_name(mat.name)
                            except PermissionError:
                                pass
                        elif folder_path == "":
                            folder_path = epath + c_name(mat.name)
                    # set save path based on folder path
                    if folder_path != "":
                        save_path = folder_path + "\\" + c_name(mat.name) + ".bmat"
                    # image file paths
                    if context.scene.image_save_type == "1":  # absolute filepaths
                        root.attrib["Path_Type"] = "Absolute"
                        for i in images:
                            for i2 in i:
                                img_out.append([i2[0], bpy.path.abspath(i2[1])])
                    else:  # relative filepaths
                        error = False
                        for i in images:
                            if i != []:
                                error = True
                        if error == True:
                            save_path = epath + c_name(mat.name) + "\\" + c_name(mat.name) + ".bmat"
                            image_path = epath + c_name(mat.name)
                            if not path.exists(epath + c_name(mat.name)) and folder_path == "":
                                try:
                                    makedirs(epath + c_name(mat.name))
                                    folder_path = epath + c_name(mat.name)
                                    folder_name = c_name(mat.name)
                                except PermissionError:
                                    error = False
                            elif folder_path != "":
                                save_path = folder_path + "\\" + c_name(mat.name) + ".bmat"
                                image_path = folder_path
                            # make sure folder_path is correct
                            if path.exists(epath + c_name(mat.name)) and folder_path == "":
                                folder_path = epath + c_name(mat.name)
                        root.attrib["Path_Type"] = "Relative"
                        if error == True:
                            for i in images:
                                for i2 in i:
                                    i3 = bpy.path.abspath(i2[1])
                                    i2_l = i3.split("\\")
                                    img_out.append([i2[0], "//" + i2_l[len(i2_l) - 1]])
                                    if path.exists(image_path):
                                        copyfile(i3, image_path + "\\" + i2_l[len(i2_l) - 1])

                    root.attrib["Images"] = str(img_out)
                    tree = ET.ElementTree(root)
                    error2 = True
                    try:
                        tree.write(save_path)
                        error2 = False
                    except (PermissionError, FileNotFoundError):
                        self.report({"ERROR"}, "Permission Denied At That Location")
                    # if no error make text pretty
                    if error2 == False:
                        pretty_file = pretty_parse(save_path)
                        pretty_text = pretty_file.toprettyxml()
                        file = open(save_path, "w+")
                        file.write(pretty_text)
                        file.close()
                # if error
                elif error == True:
                    self.report({"ERROR"}, "Export Path Is Invalid")
    # zip folder
    if folder_path != "" and context.scene.compress_folder == True:
        if path.exists(epath + "\\" + folder_name + ".zip"):  # if file is already there, delete
            remove_file(epath + "\\" + folder_name + ".zip")
        zf = zipfile.ZipFile(epath + "\\" + folder_name + ".zip", "w", zipfile.ZIP_DEFLATED)
        for dirname, subdirs, files in walk(folder_path):
            for filename in files:
                zf.write(dirname + "\\" + filename, arcname=filename)
        zf.close()
        # delete non-compressed folder
        rmtree(folder_path)
Esempio n. 4
0
def export_material(self, context):
    mat_list = []
    et = context.scene.export_materials_type
    folder_path = ""
    folder_name = ""
    #determine what all is being exported
    if et == "1" and context.material != None:
        mat_list.append(context.material.name)
    elif et == "2":
        for i in context.object.data.materials:
            mat_list.append(i.name)
    elif et == "3":
        for i in bpy.data.materials:
            mat_list.append(i.name)
    #export materials
    for mat_name in mat_list:
        mat = bpy.data.materials[mat_name]
        epath = context.scene.save_path_export
        if mat != None:
            if epath != "":
                #try open file
                error = True
                if "//" in epath:
                    epath = bpy.path.abspath(epath)
                if path.exists(epath):
                    error = False
                #error = True
                if error == False:
                    root = ET.Element("material")
                    names = {}
                    data = []
                    m_nodes = mat.node_tree.nodes
                    m_n = []  #main nodes
                    m_l = []  #main links
                    images = []
                    for n_main in m_nodes:  #nodes
                        out, is_group, im = export_node_type(n_main)
                        m_n.append(out)
                        images.append(im)
                        if is_group == True:  #group level 1
                            g_n = []
                            g_l = []
                            for n_group in n_main.node_tree.nodes:  #nodes
                                g_out, is_group1, im1 = export_node_type(
                                    n_group)
                                g_n.append(g_out)
                                images.append(im1)

                                if is_group1 == True:  #group level 2
                                    g_n2 = []
                                    g_l2 = []
                                    for n_group2 in n_group.node_tree.nodes:  #nodes
                                        g_out2, is_group2, im2 = export_node_type(
                                            n_group2)
                                        g_n2.append(g_out2)
                                        images.append(im2)

                                        if is_group2 == True:  #group level 3
                                            g_n3 = []
                                            g_l3 = []
                                            for n_group3 in n_group2.node_tree.nodes:  #nodes
                                                g_out3, is_group3, im3 = export_node_type(
                                                    n_group3)
                                                g_n3.append(g_out3)
                                                images.append(im3)

                                                if is_group3 == True:  #group level 4
                                                    g_n4 = []
                                                    g_l4 = []
                                                    for n_group4 in n_group3.node_tree.nodes:  #nodes
                                                        g_out4, is_group4, im4 = export_node_type(
                                                            n_group4)
                                                        g_n4.append(g_out4)
                                                        images.append(im4)

                                                    for l_group4 in n_group3.node_tree.links:  #links
                                                        out5 = link_info(
                                                            l_group4)
                                                        g_l4.append(out5)
                                                    data.append([g_n4, g_l4])
                                                    names[c_name(
                                                        n_group3.node_tree.name
                                                    )] = len(data) - 1

                                            for l_group3 in n_group2.node_tree.links:  #links
                                                out4 = link_info(l_group3)
                                                g_l3.append(out4)
                                            data.append([g_n3, g_l3])
                                            names[c_name(n_group2.node_tree.
                                                         name)] = len(data) - 1

                                    for l_group2 in n_group.node_tree.links:  #links
                                        out3 = link_info(l_group2)
                                        g_l2.append(out3)
                                    data.append([g_n2, g_l2])
                                    names[c_name(n_group.node_tree.name
                                                 )] = len(data) - 1

                            for l_group in n_main.node_tree.links:  #links
                                out2 = link_info(l_group)
                                g_l.append(out2)
                            data.append([g_n, g_l])
                            names[c_name(
                                n_main.node_tree.name)] = len(data) - 1

                    for l_main in mat.node_tree.links:  #links
                        out = link_info(l_main)
                        m_l.append(out)
                    data.append([m_n, m_l])
                    names["main"] = len(data) - 1

                    #write data
                    #material attribs
                    t = datetime.now()
                    date_string = "{}/{}/{} at {}:{}:{} in {}".format(
                        t.month, t.day, t.year, t.hour, t.minute, t.second,
                        tzname[0])
                    root.attrib = {
                        "Render_Engine": context.scene.render.engine,
                        "Material_Name": c_name(mat.name),
                        "Date_Created": date_string,
                        "Number_Of_Nodes": ""
                    }
                    n = 0
                    num_nodes = 0
                    for group in names:
                        sub_e = ET.SubElement(root, group.replace("/", "_"))
                        d = data[names[group]]
                        sub_e_nodes = ET.SubElement(
                            sub_e,
                            group.replace("/", "_") + "_nodes")
                        for i in d[0]:  #nodes
                            ET.SubElement(
                                sub_e_nodes, "node" + str(n), {
                                    "name": i["name"],
                                    "bl_idname": i["bl_idname"],
                                    "label": i["label"],
                                    "color": i["color"],
                                    "parent": str(i["parent"]),
                                    "location": i["location"],
                                    "height": i["height"],
                                    "width": i["width"],
                                    "mute": i["mute"],
                                    "hide": i["hide"],
                                    "inputs": i["inputs"],
                                    "outputs": i["outputs"],
                                    "node_specific": i["node_specific"],
                                    "use_custom_color": i["use_custom_color"]
                                })
                            num_nodes += 1
                        sub_e_links = ET.SubElement(
                            sub_e,
                            group.replace("/", "_") + "_links")
                        for i in d[1]:  #links
                            ET.SubElement(sub_e_links, "link" + str(n),
                                          {"link_info": i})
                            n += 1
                    root.attrib["Number_Of_Nodes"] = str(num_nodes)
                    #get order of groups
                    pre_order = sorted(names.items(),
                                       key=operator.itemgetter(1))
                    order = [i[0].replace("/", "_") for i in pre_order]
                    root.attrib["Group_Order"] = str(order)
                    #images
                    img_out = []
                    save_path = epath + c_name(mat.name) + ".bmat"
                    #create folder if needed
                    if (et == "2" and len(context.object.data.materials) >= 2
                        ) or (et == "3" and len(bpy.data.materials) >= 2):
                        if not path.exists(epath + c_name(mat.name)
                                           ) and folder_path == "":
                            try:
                                makedirs(epath + c_name(mat.name))
                                folder_path = epath + c_name(mat.name)
                                folder_name = c_name(mat.name)
                            except PermissionError:
                                pass
                        elif folder_path == "":
                            folder_path = epath + c_name(mat.name)
                    #set save path based on folder path
                    if folder_path != "":
                        save_path = folder_path + "\\" + c_name(
                            mat.name) + ".bmat"
                    #image file paths
                    if context.scene.image_save_type == "1":  #absolute filepaths
                        root.attrib["Path_Type"] = "Absolute"
                        for i in images:
                            for i2 in i:
                                img_out.append(
                                    [i2[0], bpy.path.abspath(i2[1])])
                    else:  #relative filepaths
                        error = False
                        for i in images:
                            if i != []:
                                error = True
                        if error == True:
                            save_path = epath + c_name(
                                mat.name) + "\\" + c_name(mat.name) + ".bmat"
                            image_path = epath + c_name(mat.name)
                            if not path.exists(epath + c_name(mat.name)
                                               ) and folder_path == "":
                                try:
                                    makedirs(epath + c_name(mat.name))
                                    folder_path = epath + c_name(mat.name)
                                    folder_name = c_name(mat.name)
                                except PermissionError:
                                    error = False
                            elif folder_path != "":
                                save_path = folder_path + "\\" + c_name(
                                    mat.name) + ".bmat"
                                image_path = folder_path
                            #make sure folder_path is correct
                            if path.exists(epath + c_name(mat.name)
                                           ) and folder_path == "":
                                folder_path = epath + c_name(mat.name)
                        root.attrib["Path_Type"] = "Relative"
                        if error == True:
                            for i in images:
                                for i2 in i:
                                    i3 = bpy.path.abspath(i2[1])
                                    i2_l = i3.split("\\")
                                    img_out.append(
                                        [i2[0], "//" + i2_l[len(i2_l) - 1]])
                                    if path.exists(image_path):
                                        copyfile(
                                            i3, image_path + "\\" +
                                            i2_l[len(i2_l) - 1])

                    root.attrib["Images"] = str(img_out)
                    tree = ET.ElementTree(root)
                    error2 = True
                    try:
                        tree.write(save_path)
                        error2 = False
                    except (PermissionError, FileNotFoundError):
                        self.report({"ERROR"},
                                    "Permission Denied At That Location")
                    #if no error make text pretty
                    if error2 == False:
                        pretty_file = pretty_parse(save_path)
                        pretty_text = pretty_file.toprettyxml()
                        file = open(save_path, "w+")
                        file.write(pretty_text)
                        file.close()
                #if error
                elif error == True:
                    self.report({"ERROR"}, "Export Path Is Invalid")
    #zip folder
    if folder_path != "" and context.scene.compress_folder == True:
        if path.exists(epath + "\\" + folder_name +
                       ".zip"):  #if file is already there, delete
            remove_file(epath + "\\" + folder_name + ".zip")
        zf = zipfile.ZipFile(epath + "\\" + folder_name + ".zip", "w",
                             zipfile.ZIP_DEFLATED)
        for dirname, subdirs, files in walk(folder_path):
            for filename in files:
                zf.write(dirname + "\\" + filename, arcname=filename)
        zf.close()
        #delete non-compressed folder
        rmtree(folder_path)