Created
January 16, 2025 05:12
-
-
Save BananaHemic/4d6a3a4968ab63681ef4ba6abf91e1b8 to your computer and use it in GitHub Desktop.
Remove construction lines from dxf files exported from Fusion360
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ezdxf | |
import sys | |
import os | |
# Removes all construction lines from a dxf file exported from Fusion360 | |
# You may need to run: | |
# pip install ezdxf | |
# Usage is: | |
# python remove_fusion_construction.py my_file.dxf | |
# The result will be saved in my_file_trim.dxf | |
def modify_dxf(input_file): | |
try: | |
# Derive the output file name | |
base_name, ext = os.path.splitext(input_file) | |
output_file = f"{base_name}_trim{ext}" | |
# Read the DXF file | |
doc = ezdxf.readfile(input_file) | |
msp = doc.modelspace() | |
# Delete all points | |
points_to_remove = [entity for entity in msp.query('POINT')] | |
for point in points_to_remove: | |
msp.delete_entity(point) | |
# Delete all entities on layer "1" | |
entities_on_layer_1 = [entity for entity in msp if entity.dxf.layer == "1"] | |
for entity in entities_on_layer_1: | |
msp.delete_entity(entity) | |
# Save the modified DXF to a new file | |
doc.saveas(output_file) | |
print(f"Successfully modified the DXF file. Saved as '{output_file}'.") | |
except IOError: | |
print("Could not read or write the file. Please check the file paths.") | |
except ezdxf.DXFStructureError as e: | |
print(f"Invalid DXF file structure: {e}") | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("Usage: python remove_fusion_construction.py <input_dxf_file>") | |
sys.exit(1) | |
input_dxf = sys.argv[1] | |
if not os.path.isfile(input_dxf): | |
print(f"Error: The file '{input_dxf}' does not exist.") | |
sys.exit(1) | |
modify_dxf(input_dxf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment