# 打印 Ardot 节点树的紧凑结构:缩进 + 类型/名称 + 文本 + 颜色 + 几何 import json import sys path = sys.argv[1] ids = sys.argv[2].split(',') if len(sys.argv) > 2 else None maxdepth = int(sys.argv[3]) if len(sys.argv) > 3 else 8 def hexcolor(fills): if not fills: return '' f = fills[0] if f.get('type') != 'SOLID': return f.get('type', '') c = f.get('color', {}) op = f.get('opacity', 1) s = '#%02X%02X%02X' % (round(c.get('r', 0) * 255), round(c.get('g', 0) * 255), round(c.get('b', 0) * 255)) if op is not None and op < 1: s += '@%s' % round(op, 2) return s for line in open(path, encoding='utf-8').read().splitlines(): if not line.strip().startswith('{'): continue try: node = json.loads(line) except Exception: continue if 'id' not in node or 'children' not in node: continue if ids and node['id'] not in ids: continue def walk(n, depth): if depth > maxdepth: return t = n.get('type', '') name = n.get('name', '') parts = ['%s%s %s' % (' ' * depth, t, name)] ch = n.get('characters') if ch: parts.append('"%s"' % str(ch).replace('\n', '\\n')[:80]) if n.get('fontSize'): parts.append('@%s' % n['fontSize']) col = hexcolor(n.get('fills')) if col: parts.append(col) geo = [] for k in ('x', 'y', 'width', 'height'): if k in n: v = n[k] geo.append('%s=%s' % (k, round(v) if isinstance(v, (int, float)) else v)) if geo: parts.append(' '.join(geo)) if n.get('layout'): parts.append('layout=%s' % n['layout']) if n.get('cornerRadius'): parts.append('r=%s' % n['cornerRadius']) if n.get('textAlignHorizontal') and n.get('textAlignHorizontal') != 'LEFT': parts.append('align=%s' % n['textAlignHorizontal']) print(' '.join(parts)) for c in n.get('children', []) or []: if isinstance(c, dict): walk(c, depth + 1) walk(node, 0) print('=' * 70)