MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / Drawer

Class Drawer

src/bonsai/scripts/standalone_drawer.py:17–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class Drawer:
18 def execute(self):
19 if len(sys.argv) < 4:
20 print(f"Expected 3 or 4 arguments, got {len(sys.argv) - 1}. Example usage:")
21 print(
22 "python standalone_drawer.py drawing.ifc drawing_guid [drawing_element_guid1,drawing_element_guid2,drawing_element_guid3] output.svg"
23 )
24 exit(1)
25
26 ifc: ifcopenshell.file
27 ifc = ifcopenshell.open(sys.argv[1])
28 self.camera_element = ifc.by_guid(sys.argv[2])
29 # Don't use draw.main() just whilst we're prototyping and experimenting
30 # Get all representation contexts to see what we're dealing with.
31 target_view = ifcopenshell.util.element.get_psets(self.camera_element)["EPset_Drawing"]["TargetView"]
32 contexts = self.get_linework_contexts(ifc, target_view)
33 if len(sys.argv) == 6:
34 drawing_elements = set([ifc.by_guid(g) for g in sys.argv[3].split(",")])
35 else:
36 drawing_elements = set(ifc.by_type("IfcElement")) - set(ifc.by_type("IfcFeatureElement"))
37
38 self.setup_serialiser(ifc, target_view)
39
40 tree = ifcopenshell.geom.tree()
41 tree.enable_face_styles(True)
42
43 self.serialize_contexts_elements(ifc, tree, contexts, "body", drawing_elements, target_view)
44 self.serialize_contexts_elements(ifc, tree, contexts, "annotation", drawing_elements, target_view)
45
46 if self.camera_element not in drawing_elements:
47 # The camera must always be included, regardless of any include/exclude filters.
48 geom_settings = ifcopenshell.geom.settings()
49 geom_settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
50 geom_settings.set("iterator-output", ifcopenshell.ifcopenshell_wrapper.NATIVE)
51
52 # geom_settings.set_deflection_tolerance(0.0001)
53 it = ifcopenshell.geom.iterator(geom_settings, ifc, include=[self.camera_element])
54 for elem in it:
55 self.serialiser.write(elem)
56
57 self.serialiser.finalize()
58 results = self.svg_buffer.get_value()
59 print("results", results)
60
61 with open(sys.argv[-1], "w") as svg:
62 svg.write(results)
63
64 def get_linework_contexts(self, ifc, target_view) -> LineworkContexts:
65 plan_body_target_contexts = []
66 plan_body_model_contexts = []
67 model_body_target_contexts = []
68 model_body_model_contexts = []
69
70 plan_annotation_target_contexts = []
71 plan_annotation_model_contexts = []
72 model_annotation_target_contexts = []
73 model_annotation_model_contexts = []
74

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected