From 32750e8e7c0224333942a8893e372aecb35a0743 Mon Sep 17 00:00:00 2001 From: mistangl Date: Tue, 3 Jun 2025 16:53:04 +0200 Subject: [PATCH] =?UTF-8?q?einfache=20Scan=20Funktion=20f=C3=BCr=20alle=20?= =?UTF-8?q?Layer=20gebaut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/getpositions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/getpositions.py b/lib/getpositions.py index 467e677..801ec30 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -230,6 +230,16 @@ def get_rack_positions(msp): # print_polyline(e) return ret +def scan(dxf_source:ezdxf.document.Drawing): + layer_names_inside = dxf_source.layers.entries.keys() + alle_block_defs = set(dxf_source.blocks.block_names()) + used_block_names = set(insert.dxf.name for insert in dxf_source.modelspace().query("INSERT")) + ret = dict() + ret['all_layers'] = layer_names_inside + ret['used_blocks'] = used_block_names + ret['all_blocks'] = alle_block_defs + return ret + def to_json(d, pretty: bool = True) -> str: return json.dumps(d, indent=2 if pretty else None, ensure_ascii=False, default=str) #ensure_ascii false für darstellung von "ue" @@ -265,6 +275,7 @@ if __name__ == '__main__': parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks') 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') + parser.add_argument('-n', '--scan', action='store_true', help='print all layer of racs, distributes and equiment not empty') args = parser.parse_args() @@ -272,13 +283,19 @@ if __name__ == '__main__': out_dir = os.environ.get('PROJECT_DATA') work_dir = os.environ.get('PROJECT_WORK') config_dir = os.environ.get("PROJECT_CFG") - filename = args.filename + filename = args.filename (dxf_path, dexists) = check_file_in_work(work_dir, filename) + doc = get_dxf_file(dxf_path) # type: ignore msp = doc.modelspace() + if args.scan: + res = scan(doc) + print(to_json(res)) + sys.exit() + res_pos = dict() res_dist = dict() res_rac = dict()