39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import json
|
|
import sys
|
|
|
|
|
|
def enumerate_objects(objects, parent_path=""):
|
|
for index, document_object in enumerate(objects):
|
|
object_path = str(index) if parent_path == "" else parent_path + "/" + str(index)
|
|
yield object_path, document_object
|
|
child_objects = list(document_object.OutList)
|
|
yield from enumerate_objects(child_objects, object_path)
|
|
|
|
|
|
def main():
|
|
input_path = sys.argv[1]
|
|
deleted_paths_path = sys.argv[2]
|
|
output_path = sys.argv[3]
|
|
|
|
with open(deleted_paths_path, "r", encoding="utf-8") as deleted_file:
|
|
deleted_paths = set(json.load(deleted_file))
|
|
|
|
import FreeCAD
|
|
import ImportGui
|
|
|
|
document = FreeCAD.newDocument("TrimmedStep")
|
|
ImportGui.insert(input_path, document.Name)
|
|
|
|
path_to_object = list(enumerate_objects(list(document.RootObjects)))
|
|
path_to_object.sort(key=lambda item: item[0].count("/"), reverse=True)
|
|
for object_path, document_object in path_to_object:
|
|
if object_path in deleted_paths:
|
|
document.removeObject(document_object.Name)
|
|
|
|
ImportGui.export(document.Objects, output_path)
|
|
FreeCAD.closeDocument(document.Name)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|