Schalter von -o auf -w geändert. Nimmt Parameter json File. Prints in getpositions entfernt.
This commit is contained in:
+9
-21
@@ -56,7 +56,7 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
|
||||
ld[attrib.dxf.tag] = attrib.dxf.text
|
||||
if attrib.dxf.tag == "IO":
|
||||
id = attrib.dxf.text
|
||||
print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks
|
||||
#print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks
|
||||
pos = attrib.dxf.insert #Position aufzeichnen und bei Bedarf später mit REAL_POS überschreiben
|
||||
ld["pos"] = (round(pos.x, 1), round(pos.y, 1))
|
||||
|
||||
@@ -93,7 +93,7 @@ def create_mappings(positions:dict) -> dict:
|
||||
warnings = list()
|
||||
for sensorname,v in positions.items():
|
||||
unterverteiler_pfad = v["KENNZEICHNUNG"]
|
||||
print(unterverteiler_pfad)
|
||||
#print(unterverteiler_pfad)
|
||||
|
||||
# PFad zur Karte splitten. Dieser hat z.B. den Inhalt "=AH01+UH02-KF1FDI7"
|
||||
pattern = r"^=([A-Z]+\d+)([+\-])([A-Z]+\d+)([+\-])([A-Z0-9]+)$"
|
||||
@@ -148,7 +148,7 @@ def get_subdistributor_positions(msp, dist2sensors):
|
||||
for distname in all_distributors:
|
||||
selectstr = f'MTEXT[layer=="{layer}"]'
|
||||
for text in msp.query(selectstr):
|
||||
print(f"Text auf Layer 'Busverteiler-Kennzeichnung': {text.dxf.text}")
|
||||
#print(f"Text auf Layer 'Busverteiler-Kennzeichnung': {text.dxf.text}")
|
||||
match = re.search("-"+distname, text.dxf.text)
|
||||
if match:
|
||||
ret[distname] = (round(text.dxf.insert[0],1), round(text.dxf.insert[1],1)) #nur x und y Koordinate in Json schreiben
|
||||
@@ -181,7 +181,7 @@ def get_rack_positions(msp):
|
||||
|
||||
all_layers = list(config.items('Layer_Pritschen'))
|
||||
for (layer,v) in all_layers:
|
||||
selectstr = f'LWPOLYLINEMTEXT[layer=="{layer}"]'
|
||||
selectstr = f'LWPOLYLINE[layer=="{layer}"]'
|
||||
for e in msp.query(selectstr):
|
||||
#print_polyline(e)
|
||||
rack_key = f"Rack_{rack_counter}"
|
||||
@@ -228,10 +228,10 @@ def check_file_in_work(work_dir, filename):
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='fetches the x/y positions from a dxf file', prog='getpositions')
|
||||
parser.add_argument('-f', '--filename', action='store', required=True, default="ST_6300_Steuerungstestlayout1_neueBloecke.dwg", help='which file should be fetched', metavar='myfile.dwg')
|
||||
parser.add_argument('-f', '--filename', action='store', required=True, default="ST_6300_Steuerungstestlayout1_neueBloecke.dwg", help='which file should be fetched', metavar='myfile.dxf')
|
||||
parser.add_argument('-s', '--sensors', action='store_true', help='fetch all position of sensors, motors, actors and subdistributors')
|
||||
parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks')
|
||||
parser.add_argument('-w', '--write', action='store_true', help='write results into a json file')
|
||||
parser.add_argument('-w', '--write', action='store', help='write results into a json file')
|
||||
parser.add_argument('-c', '--console', action='store_true', help='print results to output')
|
||||
|
||||
|
||||
@@ -242,19 +242,7 @@ if __name__ == '__main__':
|
||||
config_dir = os.environ.get("PROJECT_CFG")
|
||||
filename = args.filename
|
||||
|
||||
if not os.path.exists(filename):
|
||||
dxf_path = os.path.join(work_dir, filename)
|
||||
if not os.path.exists(dxf_path):
|
||||
print(f'no such file {dxf_path}')
|
||||
raise FileExistsError
|
||||
else:
|
||||
dxf_path = filename
|
||||
if not os.path.exists(dxf_path):
|
||||
print(f'no such file {dxf_path}')
|
||||
raise FileExistsError
|
||||
|
||||
dxf_file = args.dxf
|
||||
(dxf_path, dexists) = check_file_in_work(work_dir, dxf_file)
|
||||
(dxf_path, dexists) = check_file_in_work(work_dir, filename)
|
||||
|
||||
doc = get_dxf_file(dxf_path) # type: ignore
|
||||
msp = doc.modelspace()
|
||||
@@ -292,8 +280,8 @@ if __name__ == '__main__':
|
||||
if args.console:
|
||||
print(to_json(res_rac))
|
||||
if args.write:
|
||||
basename = os.path.splitext(args.filename)[0]
|
||||
write_results(to_json(output_results), work_dir, basename+"_positions.json")
|
||||
basename = os.path.splitext(args.write)[0]
|
||||
write_results(to_json(output_results), work_dir, f"{basename}.json")
|
||||
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
Reference in New Issue
Block a user