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

Method create_entity

src/ifcopenshell-python/ifcopenshell/file.py:693–775  ·  view source on GitHub ↗

Create a new IFC entity in the file. You can also use dynamic methods similar to `ifc_file.createIfcWall(...)` to create IFC entities. They work exactly the same as if you would do `ifc_file.create_entity("IfcWall", ...)` but the resulting typing is not as accurate a

(self, type: str, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

691 self.history.append(transaction)
692
693 def create_entity(self, type: str, *args: Any, **kwargs: Any) -> ifcopenshell.entity_instance:
694 """Create a new IFC entity in the file.
695
696 You can also use dynamic methods similar to `ifc_file.createIfcWall(...)`
697 to create IFC entities. They work exactly the same as if you would do
698 `ifc_file.create_entity("IfcWall", ...)` but the resulting typing
699 is not as accurate as for `create_entity` due to a dynamic nature
700 of those methods.
701
702 :param type: Case insensitive name of the IFC class
703 :param args: The positional arguments of the IFC class
704 :param kwargs: The keyword arguments of the IFC class
705 :returns: An entity instance
706
707 Example:
708
709 .. code:: python
710
711 f = ifcopenshell.file()
712 f.create_entity("IfcPerson")
713 # >>> #1=IfcPerson($,$,$,$,$,$,$,$)
714 f.create_entity("IfcPerson", "Foobar")
715 # >>> #2=IfcPerson('Foobar',$,$,$,$,$,$,$)
716 f.create_entity("IfcPerson", Identification="Foobar")
717 # >>> #3=IfcPerson('Foobar',$,$,$,$,$,$,$)
718 """
719 eid = kwargs.pop("id", -1)
720
721 e = entity_instance((self.schema_identifier, type), self)
722
723 # Create pairs of {attribute index, attribute value}.
724 # Keyword arguments are mapped to their corresponding
725 # numeric index with get_argument_index().
726
727 # @todo we should probably check that values for
728 # attributes are not passed as duplicates using
729 # both regular arguments and keyword arguments.
730 kwargs_attrs = [(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
731 attrs = list(enumerate(args)) + kwargs_attrs
732
733 if len(attrs) > len(e):
734 raise ValueError(
735 "entity instance of type '%s' has only %s attributes but %s attributes were provided."
736 % (e.is_a(True), len(e), len(attrs))
737 )
738
739 # Don't store these attributes as transactions
740 # as the creation it self is already stored with
741 # it's arguments
742 if attrs:
743 transaction = self.transaction
744 self.transaction = None
745
746 try:
747 for idx, arg in attrs:
748 e[idx] = arg
749 except IndexError:
750 invalid_attrs = []

Callers 15

ensure_hirarchyMethod · 0.45
ensure_hirarchyMethod · 0.45
process_ifcMethod · 0.45
createMethod · 0.45
createMethod · 0.45
create_cost_itemMethod · 0.45
create_unitMethod · 0.45
setup_ifc_fileMethod · 0.45
_create_empty_modelMethod · 0.45
create_2pt_wallMethod · 0.45

Calls 9

entity_instanceClass · 0.90
popMethod · 0.80
disownMethod · 0.80
store_createMethod · 0.80
itemsMethod · 0.45
is_aMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
addMethod · 0.45