Die Code zur automatischen Erzeungung der SVG für OFWeiche wurde funitoniert.

This commit is contained in:
2025-07-16 15:52:47 +02:00
parent 489eaac2c5
commit 352f6b89be
98 changed files with 1895 additions and 1152 deletions
@@ -1,114 +0,0 @@
import os
import json
import re
from shutil import copyfile
def process_svg_files(svg_folder, json_file_path):
"""Process SVG files with '_M_' pattern to create '_P_' versions"""
# Load JSON data file
try:
with open(json_file_path, 'r', encoding='utf-8') as f:
json_data = json.load(f)
print("JSON data loaded successfully")
except Exception as e:
print(f"Error loading JSON file: {e}")
return
# Process each SVG file in the directory
for filename in os.listdir(svg_folder):
if not filename.lower().endswith('.svg'):
continue
# Skip files that already contain '_P_' pattern
if '_P_' in filename:
print(f"Skipping already processed file: {filename}")
continue
# Only process files containing '_M_' pattern
if '_M_' not in filename:
print(f"Skipping non-target file (no '_M_' pattern): {filename}")
continue
print(f"\nProcessing target file: {filename}")
# Extract SIVASNR from filename
match = re.search(r'_M_(\d+)\.svg$', filename)
if not match:
print(f"Warning: Could not extract SIVASNR from filename: {filename}")
continue
sivasnr = match.group(1)
print(f"Extracted SIVASNR: {sivasnr}")
# Find matching item in JSON data
matched_item = next((item for item in json_data
if "Sivasnr" in item and str(item["Sivasnr"]) == sivasnr), None)
if not matched_item:
print(f"No matching SIVASNR found in JSON - skipping: {sivasnr}")
continue
profil_typ = matched_item.get("ProfilTyp", "")
if not profil_typ:
print(f"No ProfilTyp field found - skipping: {sivasnr}")
continue
print(f"Found ProfilTyp: {profil_typ}")
# Find similar item (replace M with P)
similar_profil_typ = profil_typ.replace(" MIT M", " MIT P")
print(f"Searching for similar ProfilTyp: {similar_profil_typ}")
similar_item = next((item for item in json_data
if item.get("ProfilTyp", "") == similar_profil_typ), None)
if not similar_item:
print(f"No similar item found - skipping: {similar_profil_typ}")
continue
similar_sivasnr = similar_item.get("Sivasnr")
print(f"Found similar item SIVASNR: {similar_sivasnr}")
# Create new filename
new_filename = filename.replace(f"_M_{sivasnr}", f"_P_{similar_sivasnr}")
new_filepath = os.path.join(svg_folder, new_filename)
print(f"Creating new file: {new_filename}")
try:
# Copy and modify file
copyfile(os.path.join(svg_folder, filename), new_filepath)
# Read and modify SVG content
with open(new_filepath, 'r', encoding='utf-8') as f:
svg_content = f.read()
modified_content = svg_content.replace('stroke="#ffe31b"', 'stroke="#1bff38"')
# Write modified content
with open(new_filepath, 'w', encoding='utf-8') as f:
f.write(modified_content)
# Verify replacement
if '#ffe31b' in modified_content:
print("Warning: Original color still exists in output file")
else:
print("Color replacement successful")
print(f"Successfully created modified version: {new_filename}")
except Exception as e:
print(f"Error processing file: {e}")
# Clean up if file creation failed
if os.path.exists(new_filepath):
os.remove(new_filepath)
if __name__ == "__main__":
# Configure paths (update these with your actual paths)
svg_folder =r"C:\Users\y.wang\Documents\SSG-Ruledesigner-Konfigurator\SVGs\Omniflo\Weichen\outputdir_Kopie"
json_file_path =r"C:\Users\y.wang\Documents\SSG-Ruledesigner-Konfigurator\SVGs\Omniflo\python\OFWeiche\JSON\omniflo_weichen_output.json"
process_svg_files(svg_folder, json_file_path)
print("Processing complete")
@@ -6,22 +6,22 @@
</clipPath>
</defs>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.1" >
<polyline points="234.221,411.135 234.221,423.963 " />
<polyline points="441.683,203.67 454.511,203.67 " />
<polyline points="448.097,232.966 448.097,203.67 " />
<polyline points="661.974,417.549 234.221,417.549 " />
<polyline points="529.124,346.218 529.124,341.979 " />
<polyline points="460.574,414.768 456.335,414.768 " />
<polyline points="458.454,405.088 458.454,414.768 " />
<polyline points="387.785,344.098 529.124,344.098 " />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,255,255)" stroke-width="0.1" >
<path d="M348.443,382.21 A122.175,122.175 0 0,0 412.764,317.89 " stroke-dasharray="8.988326,0.998703,1.997406,0.998703,1.997406,0.998703" />
<path d="M483.431,317.89 A122.175,122.175 0 0,0 547.751,382.21 " stroke-dasharray="8.988326,0.998703,1.997406,0.998703,1.997406,0.998703" />
<path d="M491.382,355.775 A40.3692,40.3692 0 0,0 470.129,377.028 " stroke-dasharray="2.969937,0.329993,0.659986,0.329993,0.659986,0.329993" />
<path d="M446.779,377.028 A40.3692,40.3692 0 0,0 425.526,355.775 " stroke-dasharray="2.969937,0.329993,0.659986,0.329993,0.659986,0.329993" />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.1" >
<polyline points="412.764,317.89 448.097,232.966 " />
<polyline points="348.443,382.21 263.508,417.549 " />
<polyline points="483.431,317.89 448.097,232.966 " />
<polyline points="547.751,382.21 632.686,417.549 " />
<polyline points="661.974,411.135 661.974,423.963 " />
<polyline points="238.933,433.903 238.933,417.549 " />
<polyline points="657.261,433.903 657.261,417.549 " />
<polyline points="470.129,377.028 458.454,405.088 " />
<polyline points="491.382,355.775 519.447,344.098 " />
<polyline points="446.779,377.028 458.454,405.088 " />
<polyline points="425.526,355.775 397.462,344.098 " />
<polyline points="387.785,346.218 387.785,341.979 " />
<polyline points="527.567,338.694 527.567,344.098 " />
<polyline points="389.342,338.694 389.342,344.098 " />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

@@ -6,34 +6,34 @@
</clipPath>
</defs>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.1" >
<polyline points="362.45,379.299 685.686,379.299 " stroke-dasharray="4.953036,0.990607,0.990607,0.990607" />
<polyline points="643.608,362.609 395.402,362.609 " stroke-dasharray="3.803322,0.760664,0.760664,0.760664" />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,255,255)" stroke-width="0.1" >
<polyline points="610.154,355.939 608.335,355.185 " stroke-dasharray="5.943643,0.660405,1.320810,0.660405,1.320810,0.660405" />
<polyline points="453.401,380.547 454.798,381.125 " stroke-dasharray="4.563987,0.507110,1.014219,0.507110,1.014219,0.507110" />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.1" >
<polyline points="524.081,217.666 524.081,237.01 " stroke-dasharray="4.953036,0.990607,0.990607,0.990607" />
<polyline points="519.494,486.723 519.494,471.87 " stroke-dasharray="3.803322,0.760664,0.760664,0.760664" />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,255,255)" stroke-width="0.1" >
<polyline points="437.981,355.912 439.847,355.139 " stroke-dasharray="5.943643,0.660405,1.320810,0.660405,1.320810,0.660405" />
<polyline points="547.442,293.199 548.216,295.066 " stroke-dasharray="5.943643,0.660405,1.320810,0.660405,1.320810,0.660405" />
<polyline points="500.72,293.199 499.966,295.019 " stroke-dasharray="5.943643,0.660405,1.320810,0.660405,1.320810,0.660405" />
<polyline points="585.609,380.568 584.176,381.161 " stroke-dasharray="4.563987,0.507110,1.014219,0.507110,1.014219,0.507110" />
<polyline points="501.556,428.723 500.962,427.289 " stroke-dasharray="4.563987,0.507110,1.014219,0.507110,1.014219,0.507110" />
<polyline points="537.433,428.723 538.012,427.325 " stroke-dasharray="4.563987,0.507110,1.014219,0.507110,1.014219,0.507110" />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.1" >
<polyline points="528.323,217.666 519.84,217.666 " />
<polyline points="516.238,486.723 522.751,486.723 " />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,255,255)" stroke-width="0.1" >
<path d="M548.216,295.066 A111.086,111.086 0 0,0 608.335,355.185 " stroke-dasharray="5.943643,0.660405,1.320810,0.660405,1.320810,0.660405" />
<path d="M439.847,355.139 A111.086,111.086 0 0,0 499.966,295.019 " stroke-dasharray="5.943643,0.660405,1.320810,0.660405,1.320810,0.660405" />
<path d="M500.962,427.289 A85.3002,85.3002 0 0,0 454.798,381.125 " stroke-dasharray="4.563987,0.507110,1.014219,0.507110,1.014219,0.507110" />
<path d="M584.176,381.161 A85.3002,85.3002 0 0,0 538.012,427.325 " stroke-dasharray="4.563987,0.507110,1.014219,0.507110,1.014219,0.507110" />
</g>
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.1" >
<polyline points="500.72,293.199 524.081,237.01 " />
<polyline points="547.442,293.199 524.081,237.01 " />
<polyline points="362.45,375.057 362.45,383.54 " />
<polyline points="685.686,375.196 685.686,383.679 " />
<polyline points="437.981,355.912 381.73,379.299 " />
<polyline points="610.154,355.939 666.341,379.299 " />
<polyline points="365.566,390.113 365.566,379.299 " />
<polyline points="682.568,390.14 682.57,379.326 " />
<polyline points="537.433,428.723 519.494,471.87 " />
<polyline points="501.556,428.723 519.494,471.87 " />
<polyline points="643.608,365.866 643.608,359.352 " />
<polyline points="395.402,365.759 395.402,359.246 " />
<polyline points="585.609,380.568 628.803,362.609 " />
<polyline points="453.401,380.547 410.257,362.609 " />
<polyline points="641.215,354.305 641.215,362.609 " />
<polyline points="397.796,354.284 397.795,362.588 " />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB