ifcopenshell.draw - add drawing_object_type argument and descriptions

This commit is contained in:
Andrej730
2024-07-11 18:44:32 +05:00
parent 5440445cbc
commit 8579c61ab6
+30 -11
View File
@@ -26,7 +26,7 @@ import ifcopenshell
import ifcopenshell.geom import ifcopenshell.geom
from xml.dom.minidom import parseString from xml.dom.minidom import parseString
from dataclasses import dataclass, fields from dataclasses import dataclass, fields, field
from typing import Callable, Sequence from typing import Callable, Sequence
import numpy import numpy
@@ -55,7 +55,15 @@ class draw_settings:
storey_heights: str = "none" storey_heights: str = "none"
include_entities: str = "" include_entities: str = ""
exclude_entities: str = "IfcOpeningElement" exclude_entities: str = "IfcOpeningElement"
drawing_guid: str = "" drawing_guid: str = field(
default="",
metadata={
"doc": "Use a drawing with the provided GlobalId. Setting takes priority over 'drawing_object_type'."
},
)
drawing_object_type: str = field(
default="", metadata={"doc": 'Use IfcAnnotations with provided ObjectType for drawings (e.g. "DRAWING").'}
)
profile_threshold: int = -1 profile_threshold: int = -1
cells: bool = True cells: bool = True
merge_cells: bool = False merge_cells: bool = False
@@ -114,11 +122,15 @@ def main(
if settings.auto_floorplan: if settings.auto_floorplan:
sr.setSectionHeightsFromStoreys() sr.setSectionHeightsFromStoreys()
if settings.drawing_guid: # setElevationRefGuid and setElevationRef are also mutually exclusive in C-code.
sr.setElevationRefGuid(settings.drawing_guid) # Note that guid or object type are not checked anywhere to be valid,
# it's up to user to keep them valid for the provided projects.
if settings.drawing_guid or settings.drawing_object_type:
if settings.drawing_guid:
sr.setElevationRefGuid(settings.drawing_guid)
elif settings.drawing_object_type:
sr.setElevationRef(settings.drawing_object_type)
sr.setWithoutStoreys(True) sr.setWithoutStoreys(True)
# If you want to filter by IfcAnnotation ObjectType named "DRAWING"
# sr.setElevationRef("DRAWING")
# required for svgfill # required for svgfill
sr.setPolygonal(True) sr.setPolygonal(True)
@@ -421,14 +433,21 @@ if __name__ == "__main__":
) )
for field in fields(draw_settings): for field in fields(draw_settings):
name = field.name.replace("_", "-")
description = field.metadata.get("doc") or ""
description += " " if description else ""
description += f"Default: {repr(field.default)}."
if field.type == bool: if field.type == bool:
parser.add_argument("--" + field.name.replace("_", "-"), dest=field.name, action="store_true") parser.add_argument(
parser.add_argument("--no-" + field.name.replace("_", "-"), dest=field.name, action="store_false") f"--{name}",
help=description,
dest=field.name,
action="store_true",
)
parser.add_argument(f"--no-{name}", dest=field.name, action="store_false")
parser.set_defaults(**{field.name: field.default}) parser.set_defaults(**{field.name: field.default})
else: else:
parser.add_argument( parser.add_argument(f"--{name}", help=description, dest=field.name, type=field.type, default=field.default)
"--" + field.name.replace("_", "-"), dest=field.name, type=field.type, default=field.default
)
args = vars(parser.parse_args()) args = vars(parser.parse_args())