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

Method execute

src/bonsai/scripts/standalone_drawer.py:18–62  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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 = []

Callers 1

Calls 15

get_linework_contextsMethod · 0.95
setup_serialiserMethod · 0.95
printFunction · 0.85
openMethod · 0.80
splitMethod · 0.80
enable_face_stylesMethod · 0.80
setFunction · 0.50
openFunction · 0.50
by_guidMethod · 0.45
by_typeMethod · 0.45
treeMethod · 0.45

Tested by

no test coverage detected