| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import argparse |
| | import os |
| | import sys |
| |
|
| | parser = argparse.ArgumentParser() |
| | parser.add_argument("path", nargs="+", help="Shape file to process") |
| | parser.add_argument( |
| | "--move", |
| | metavar="<group1>:<group2>", |
| | help="Move attributes from group 1 into group 2", |
| | ) |
| | parser.add_argument("--delete", metavar="prop", help="Delete the given attribute") |
| | parser.add_argument("--set", metavar="prop=value", help="Set property value") |
| | parser.add_argument( |
| | "--print", action="store_true", help="If set attributes are printed as discovered" |
| | ) |
| | parser.add_argument( |
| | "--print-all", action="store_true", help="If set Shape attributes are also printed" |
| | ) |
| | parser.add_argument( |
| | "--print-groups", |
| | action="store_true", |
| | help="If set all custom property groups are printed", |
| | ) |
| | parser.add_argument( |
| | "--save-changes", action="store_true", help="Unless specified the file is not saved" |
| | ) |
| | parser.add_argument("--freecad", help="Directory FreeCAD binaries (libFreeCAD.so) if not installed") |
| | args = parser.parse_args() |
| |
|
| | if args.freecad: |
| | sys.path.append(args.freecad) |
| |
|
| | import FreeCAD |
| | import Path |
| | import Path.Base.PropertyBag as PathPropertyBag |
| | import Path.Base.Util as PathUtil |
| |
|
| | set_var = None |
| | set_val = None |
| |
|
| | GroupMap = {} |
| | if args.move: |
| | g = args.move.split(":") |
| | if len(g) != 2: |
| | print("ERROR: {} not a valid group mapping".format(args.move)) |
| | sys.exit(1) |
| | GroupMap[g[0]] = g[1] |
| |
|
| | if args.set: |
| | s = args.set.split("=") |
| | if len(s) != 2: |
| | print("ERROR: {} not a valid group mapping".format(args.move)) |
| | sys.exit(1) |
| | set_var = s[0] |
| | set_val = s[1] |
| |
|
| | for i, fname in enumerate(args.path): |
| | |
| | doc = FreeCAD.openDocument(fname, False) |
| | print("{}:".format(doc.Name)) |
| | for o in doc.Objects: |
| | if PathPropertyBag.IsPropertyBag(o): |
| | if args.print_groups: |
| | print(" {}: {}".format(o.Label, sorted(o.CustomPropertyGroups))) |
| | else: |
| | print(" {}:".format(o.Label)) |
| | for p in o.Proxy.getCustomProperties(): |
| | grp = o.getGroupOfProperty(p) |
| | typ = o.getTypeIdOfProperty(p) |
| | ttp = PathPropertyBag.getPropertyTypeName(typ) |
| | val = PathUtil.getProperty(o, p) |
| | dsc = o.getDocumentationOfProperty(p) |
| | enm = "" |
| | enum = [] |
| | if ttp == "Enumeration": |
| | enum = o.getEnumerationsOfProperty(p) |
| | enm = "{}".format(",".join(enum)) |
| | if GroupMap.get(grp): |
| | group = GroupMap.get(grp) |
| | print("move: {}.{} -> {}".format(grp, p, group)) |
| | o.removeProperty(p) |
| | o.Proxy.addCustomProperty(typ, p, group, dsc) |
| | if enum: |
| | print("enum {}.{}: {}".format(group, p, enum)) |
| | setattr(o, p, enum) |
| | PathUtil.setProperty(o, p, val) |
| | if p == set_var: |
| | print("set {}.{} = {}".format(grp, p, set_val)) |
| | if ttp == "Enumeration" and set_val[0] == "[": |
| | enum = set_val[1:-1].split(",") |
| | setattr(o, p, enum) |
| | else: |
| | PathUtil.setProperty(o, p, set_val) |
| | if p == args.delete: |
| | print("delete {}.{}".format(grp, p)) |
| | o.removeProperty(p) |
| | if not args.print_all and grp == "Shape": |
| | continue |
| | if args.print or args.print_all: |
| | print(" {:10} {:20} {:20} {:10} {}".format(grp, p, ttp, str(val), enm)) |
| | o.Proxy.refreshCustomPropertyGroups() |
| | if args.save_changes: |
| | doc.recompute() |
| | doc.save() |
| | FreeCAD.closeDocument(doc.Name) |
| |
|
| | print("-done-") |
| |
|