Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- YBN files exported to XML
- import re
- import os
- # Folder containing the .ybn.xml files
- folder_path = r"path/to/your/folder" # Change this to your folder path
- # Make sure the path is correct and contains the .ybn.xml files
- # Values to add to each coordinate
- add_x = 0 # Add to X
- add_y = 0 # Add to Y
- add_z = 0 # Add to Z
- # Function to modify the coordinates
- def modify_coordinates(match):
- prefix = match.group(1) # Part before x
- x_value = float(match.group(2)) # x value
- y_value = float(match.group(3)) # y value
- z_value = float(match.group(4)) # z value
- suffix = match.group(5) # Part after z
- # Add values to the coordinates
- new_x = x_value + add_x
- new_y = y_value + add_y
- new_z = z_value + add_z
- # Return the modified line
- return f'{prefix}x="{new_x}" y="{new_y}" z="{new_z}"{suffix}'
- # Regular expression to find the three coordinates in specific tags
- pattern = re.compile(r'(<BoxMin |<BoxMax |<BoxCenter |<SphereCenter |<GeometryCenter )x="([-\d.]+)" y="([-\d.]+)" z="([-\d.]+)"( />)')
- # Loop through all .xml files in the folder
- for filename in os.listdir(folder_path):
- if filename.endswith(".ybn.xml"):
- file_path = os.path.join(folder_path, filename)
- # Open the file and read its content
- with open(file_path, "r") as file:
- content = file.read()
- # Replace coordinates in the specified tags
- content = pattern.sub(modify_coordinates, content)
- # Save the changes
- with open(file_path, "w") as file:
- file.write(content)
- print(f"Coordinates modified in: {filename}")
- print("Process completed.")
- ---------------------------------------------------------------------------------------------------------------------------------------
- YMAP files exported to XML
- import xml.etree.ElementTree as ET
- import os
- # Folder that contains the .ymap.xml files
- folder_path = r"path/to/your/folder" # Change this to your folder path
- # Make sure the path is correct and contains the .ymap.xml files
- # Values to add or subtract from each coordinate
- # You can change these values as needed; to subtract, just use negative values like -100
- x = 0 # Add to X
- y = 0 # Add to Y
- z = 0 # Add to Z
- def modify_attribute_values(element):
- """ Modifies the x, y, z attributes if they exist. """
- for coord in ['x', 'y', 'z']:
- if coord in element.attrib:
- value = float(element.attrib[coord])
- if coord == 'x':
- element.attrib[coord] = str(value + x)
- elif coord == 'y':
- element.attrib[coord] = str(value + y)
- elif coord == 'z':
- element.attrib[coord] = str(value + z)
- def modify_node_values(element):
- """ Modifies the x, y, z nodes inside <position>. """
- for item in element.findall("Item"):
- for coord in ['x', 'y', 'z']:
- node = item.find(coord)
- if node is not None and 'value' in node.attrib:
- value = float(node.attrib['value'])
- if coord == 'x':
- node.attrib['value'] = str(value + x)
- elif coord == 'y':
- node.attrib['value'] = str(value + y)
- elif coord == 'z':
- node.attrib['value'] = str(value + z)
- # Loop through all .ymap.xml files in the folder
- for filename in os.listdir(folder_path):
- if filename.endswith(".ymap.xml"):
- file_path = os.path.join(folder_path, filename)
- # Load the XML file
- tree = ET.parse(file_path)
- root = tree.getroot()
- # Modify elements with x, y, z attributes
- for elem in root.iter():
- if elem.tag in ['streamingExtentsMin', 'streamingExtentsMax', 'entitiesExtentsMin', 'entitiesExtentsMax', 'position']:
- modify_attribute_values(elem)
- # Modify the nodes inside <position>
- for position in root.findall(".//position"):
- modify_node_values(position)
- # Save the modified XML file with declaration
- output_path = os.path.join(folder_path, filename)
- tree.write(output_path, encoding="UTF-8", xml_declaration=True)
- print(f"Modified file: {filename}")
- print("Process completed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement