RD_CONF für SVG zu bearbeiten
This commit is contained in:
+5
-2
@@ -23,6 +23,7 @@
|
||||
The script is designed to process SVG measurement data, perform geometric validations, and produce an enhanced dataset while providing thorough feedback about the processing results. '''
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
|
||||
def safe_float(value, default=0.0):
|
||||
"""Safely convert value to float, return default if conversion fails"""
|
||||
@@ -145,7 +146,9 @@ def process_json_file(input_file, output_file):
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
input_filename = "1_SVGErfassung_updated_new_input.json" # Replace with your input filename
|
||||
output_filename = "1_SVGErfassung_updated_new_output.json" # Replace with desired output filename
|
||||
|
||||
json_path=os.environ.get("JSON_PATH","JSON")
|
||||
input_filename = os.path.join(json_path,"1_SVGErfassung_updated_new_input.json") # Replace with your input filename
|
||||
output_filename = os.path.join(json_path,"1_SVGErfassung_updated_new_output.json") # Replace with desired output filename
|
||||
|
||||
process_json_file(input_filename, output_filename)
|
||||
+6
-4
@@ -13,6 +13,7 @@
|
||||
Maintains aspect ratio while standardizing dimensions '''
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
|
||||
def process_json_item(item):
|
||||
# Ensure all numeric fields are floats
|
||||
@@ -144,7 +145,7 @@ def process_json_file(input_file, output_file):
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(processed_data, f, indent=4, ensure_ascii=False)
|
||||
|
||||
print(f"Processing complete. Results saved to {output_file}")
|
||||
print(f"Processing for calculations to standardize the dimensions and add connection points completed. Results saved to {output_file}")
|
||||
|
||||
# Print error reports
|
||||
if error_reports:
|
||||
@@ -168,8 +169,9 @@ def process_json_file(input_file, output_file):
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
input_filename = "1_SVGErfassung_updated_new_output.json"
|
||||
output_filename = "2_calculated_px_cps_output.json"
|
||||
json_path=os.environ.get("JSON_PATH","JSON")
|
||||
input_filename = os.path.join(json_path,"1_SVGErfassung_updated_new_output.json")
|
||||
output_filename =os.path.join(json_path,"2_calculated_px_cps_output.json")
|
||||
|
||||
process_json_file(input_filename, output_filename)
|
||||
process_json_file(input_filename, output_filename)
|
||||
|
||||
@@ -30,13 +30,21 @@ def process_files(json_file_path, txt_files_dir):
|
||||
# Create Sivasnr to JSON data mapping
|
||||
sivasnr_mapping = {item["Sivasnr"]: item for item in json_data}
|
||||
|
||||
# Initialize counters
|
||||
total_files = 0
|
||||
processed_files = 0
|
||||
skipped_files = 0
|
||||
|
||||
# Prepare report content
|
||||
report_content = []
|
||||
report_content.append(f"Modification Report - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
report_content.append(f"JSON Reference File: {json_file_path}")
|
||||
report_content.append(f"TXT Files Directory: {txt_files_dir}")
|
||||
report_content.append("="*50 + "\n")
|
||||
|
||||
# Process all TXT files
|
||||
for txt_file_path in glob.glob(os.path.join(txt_files_dir, '*.txt')):
|
||||
total_files += 1
|
||||
# Extract Sivasnr from filename
|
||||
sivasnr = os.path.splitext(os.path.basename(txt_file_path))[0]
|
||||
|
||||
@@ -50,7 +58,7 @@ def process_files(json_file_path, txt_files_dir):
|
||||
|
||||
# Prepare entry for this file
|
||||
file_entry = []
|
||||
file_entry.append(f"\nProcessing file: {txt_file_path}")
|
||||
file_entry.append(f"\nProcessing file: {os.path.basename(txt_file_path)}")
|
||||
file_entry.append("="*50)
|
||||
|
||||
# Record old values
|
||||
@@ -107,7 +115,8 @@ def process_files(json_file_path, txt_files_dir):
|
||||
file_entry.append(f" y: {change['y'][0]} → {change['y'][1]}")
|
||||
file_entry.append(f" direction: {change['direction'][0]} → {change['direction'][1]}")
|
||||
|
||||
file_entry.append(f"\nFile {txt_file_path} processed successfully")
|
||||
processed_files += 1
|
||||
file_entry.append(f"\nFile processed successfully")
|
||||
file_entry.append("="*50)
|
||||
|
||||
# Add this file's entry to main report
|
||||
@@ -116,19 +125,41 @@ def process_files(json_file_path, txt_files_dir):
|
||||
# Also print to console
|
||||
print("\n" + "\n".join(file_entry))
|
||||
else:
|
||||
print(f"\nSkipping file {txt_file_path} (no matching JSON data found)")
|
||||
skipped_files += 1
|
||||
|
||||
# Write the report file if any changes were made
|
||||
if len(report_content) > 2: # More than just the header
|
||||
with open(log_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write("\n".join(report_content))
|
||||
print(f"\nModification report saved to: {log_file_path}")
|
||||
else:
|
||||
print("\nNo files were modified - no report generated")
|
||||
# Add processing statistics to report
|
||||
report_content.append("\n" + "="*50)
|
||||
report_content.append("Processing Statistics:")
|
||||
report_content.append(f"Total TXT files found: {total_files}")
|
||||
report_content.append(f"Total JSON records available: {len(json_data)}")
|
||||
report_content.append(f"Successfully processed: {processed_files}")
|
||||
report_content.append(f"Skipped files: {skipped_files}")
|
||||
if total_files > 0:
|
||||
success_rate = (processed_files / len(json_data)) * 100
|
||||
report_content.append(f"Success rate: {success_rate:.2f}%")
|
||||
report_content.append("="*50)
|
||||
|
||||
# Print statistics to console
|
||||
print("\n" + "="*50)
|
||||
print("Processing Statistics:")
|
||||
print(f"Total TXT files found: {total_files}")
|
||||
print(f"Total JSON records available: {len(json_data)}")
|
||||
print(f"Successfully processed: {processed_files}")
|
||||
print(f"Skipped files: {skipped_files}")
|
||||
if total_files > 0:
|
||||
success_rate = (processed_files / len(json_data)) * 100
|
||||
print(f"Success rate: {success_rate:.2f}%")
|
||||
print("="*50 + "\n")
|
||||
|
||||
# Write the report file
|
||||
with open(log_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write("\n".join(report_content))
|
||||
print(f"Modification report saved to: {log_file_path}")
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
json_file_path = "2_calculated_px_cps_output.json"
|
||||
txt_files_dir = "C:/Program Files/RuleDesigner/RDConfigurator Fusion/WebApi/Editor2D/SSG/shapes/props"
|
||||
json_path = os.environ.get("JSON_PATH", "JSON")
|
||||
json_file_path = os.path.join(json_path, "2_calculated_px_cps_output.json")
|
||||
txt_files_dir = os.environ.get("PROPS_PATH", "props")
|
||||
process_files(json_file_path, txt_files_dir)
|
||||
print("\nAll files processed!")
|
||||
print("\nProcessing complete!")
|
||||
@@ -84,9 +84,9 @@ def main():
|
||||
"""
|
||||
Main processing function
|
||||
"""
|
||||
# Configure paths
|
||||
json_file_path = r"C:\Users\y.wang\Documents\SSG-Ruledesigner-Konfigurator\SVGs\Omniflo\python\OFBogen\1_SVGErfassung_updated_new_input.json"
|
||||
svg_folder_path = r"C:\Program Files\RuleDesigner\RDConfigurator Fusion\WebApi\Editor2D\SSG\shapes\svg"
|
||||
json_path=os.environ.get("JSON_PATH","JSON")
|
||||
json_file_path = os.path.join(json_path,"1_SVGErfassung_updated_new_output.json")
|
||||
svg_folder_path = os.environ.get("XML_PATH","svg")
|
||||
|
||||
try:
|
||||
# Read and parse JSON file
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
@echo off
|
||||
|
||||
set OFBogen_PATH=%~dp0
|
||||
|
||||
set XML_PATH=C:\Program Files\RuleDesigner\RDConfigurator Fusion\WebApi\Editor2D\SSG\shapes\svg
|
||||
|
||||
set JSON_PATH=%OFBogen_PATH%JSON
|
||||
|
||||
python 4_OFBogen_SVG_XML_Modifier_Script.py
|
||||
|
||||
|
||||
pause
|
||||
@@ -0,0 +1,12 @@
|
||||
@echo off
|
||||
|
||||
set OFBogen_PATH=%~dp0
|
||||
set PROPS_PATH=C:\Program Files\RuleDesigner\RDConfigurator Fusion\WebApi\Editor2D\SSG\shapes\props
|
||||
|
||||
set JSON_PATH=%OFBogen_PATH%JSON
|
||||
|
||||
python 1_calculate_ture_width_and_height_dimensions_with_profile_width.py
|
||||
python 2_calculations_to_standardize_the_dimensions_and_add_connection_points.py
|
||||
python 3_update_dimensions_and_connection_points_in_props.py
|
||||
|
||||
pause
|
||||
Reference in New Issue
Block a user