Skip to main content

ifcfactory

PyPI version Python 3.11+ License

A modular geometry system for creating BIM elements with composable geometry creation.

About This Project

ifcfactory is developed and maintained by Freie und Hansestadt Hamburg, Landesbetrieb Geoinformation und Vermessung (LGV), BIM-Leitstelle

This library is part of the Connected Urban Twins project ecosystem, providing a foundational geometry framework for automated IFC generation from urban data sources. It serves as a core dependency for BIMFabrikHH_core and other BIM automation tools.

Author: Ahmed Salem (BIM-Leitstelle, LGV Hamburg)
In cooperation with: Thomas Krijnen

Quick Install

pip install ifcfactory

Overview

ifcfactory offers a declarative, composable framework for creating complex BIM geometry. It leverages Pydantic models for strong type safety and validation, while providing seamless integration with IfcOpenShell for reliable IFC file generation.

The declarative structures in Python are automatically mapped to the most appropriate IFC mechanisms, for example:

  • Boolean(operation, children):
    • In case of: subtraction of element from element -> IfcRelVoidsElement + IfcOpeningElement
    • In case of: subtraction of profile from profile -> IfcProfileDefWithVoids
    • In case of: any item to item -> IfcBooleanResult
  • Transform(item, translation, rotation):
    • In case of: element -> Factored into ObjectPlacement
    • In case of: tesselation -> Applied to coordinates
    • Other cases: defer to shape_builder translate() and rotate() [when along "Z" axis]

Structure

ifcfactory/
├── __init__.py                 # Main public API
├── element.py                  # High-level BIM elements
├── primitives.py               # Geometric shapes (Box, Cylinder, Sphere, etc.)
├── operations.py               # Transformations and Boolean operations
└── _internal/                  # Internal implementation (not for direct user access)
    ├── __init__.py            # Internal package marker
    ├── primitives_base.py     # Base classes and helper functions
    ├── material_base.py       # Materials and styling
    ├── unit_base.py           # Unit conversion utilities (pint ↔ IFC)
    └── pset_base.py           # Property set templates

Public API

High-Level Elements

  • BIMFactoryElement: Container for complete BIM elements with IFC integration

2D Profiles

  • Rect(width, height): Rectangular profile
  • Circle(radius): Circular profile
  • Ellipse(semi_axis1, semi_axis2): Elliptical profile
  • Polygon(points, voids=[]): Arbitrary polygon from list of 2D points, with optional inner polygons as voids
  • PolylineOffset(points, offset, miter_limit=2.0): Wall footprint from a 2D centerline, offset by offset to the left and to the right. Sharp outer corners are cut off miter_limit * offset from the corner; a closed centerline gives a ring with the inner face as a void

3D Representations

  • Box(width, depth, height): Rectangular box
  • Cube(size): Cube with equal dimensions
  • Cylinder(radius, height): Circular cylinder
  • EllipticalCylinder(semi_axis1, semi_axis2, height): Elliptical cylinder
  • NgonCylinder(radius, height, segments=8): N-sided cylinder
  • Sphere(radius, detail=1): Icosphere with configurable detail
  • Extrusion(basis, depth): Extrude any 2D profile
  • SweptDisk(points, radius, arc_points=[]): Disk of radius swept along a 3D path (IfcSweptDiskSolid), e.g. a pipe or a bent rail. Each index in arc_points turns that inner point into the middle of a circular arc
  • ExtrudedNgonAsMesh(basis, height): N-sided extrusion as mesh
  • MeshRepresentation(vertices, faces): Custom mesh geometry

Operations

  • Transform(item, translation, rotation): Apply a transformation (translation and/or rotation)
  • Boolean(operation, children): Boolean operations (union, difference, intersection)
  • BooleanOperationTypes: Enum for boolean operation types

Materials & Styling

  • Style: Visual styling with colors and transparency
  • Material: Physical material properties

Property Sets

  • PropertySetTemplate: Template for creating property sets

Units

  • Dimension variables: L (length), A (area), V (volume), M (mass), T (time), E (current), K (temperature), N (force), J (energy), P (power)
  • pint_to_ifc: Mapping dictionary for unit conversion
  • ureg: Pint unit registry
  • Dim: Dimension class

Key Features

  • Type Safety: Built on Pydantic for runtime type checking and validation
  • Composable: Mix and match primitives to create complex geometry
  • Cacheable: Built elements are cached to prevent duplication
  • Unit Aware: Automatic unit conversion between pint and IFC types
  • Material Support: Visual styling and material assignment
  • Property Sets: Support for IFC property sets and quantities
  • API: Internal implementation hidden in _internal module

Complete Working Example

Here's a complete example that creates a simple building with multiple wall types:

import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.context
import ifcopenshell.api.root
import ifcopenshell.api.unit

from ifcfactory import (
    BIMFactoryElement, Box, Cube, Cylinder, Extrusion, Rect, Sphere
)


def create_basic_ifc_setup(project_name: str):
    """Create basic IFC model setup using IfcOpenShell API"""
    # Create IFC model
    ifc_model = ifcopenshell.file(schema="IFC4")

    # Create project
    project_entity = ifcopenshell.api.root.create_entity(ifc_model, ifc_class="IfcProject", name=project_name)

    # Create units (meters)
    ifcopenshell.api.unit.assign_unit(ifc_model, length={"is_metric": True, "raw": "METERS"})

    # Create contexts
    model_context = ifcopenshell.api.context.add_context(ifc_model, context_type="Model")
    ifcopenshell.api.context.add_context(
            ifc_model, context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model_context
    )

    # Create site
    site_entity = ifcopenshell.api.root.create_entity(ifc_model, ifc_class="IfcSite", name="Default Site")
    ifcopenshell.api.aggregate.assign_object(ifc_model, relating_object=project_entity, products=[site_entity])

    # Create building
    building_entity = ifcopenshell.api.root.create_entity(ifc_model, ifc_class="IfcBuilding", name="Default Building")
    ifcopenshell.api.aggregate.assign_object(ifc_model, relating_object=site_entity, products=[building_entity])

    return ifc_model, project_entity, site_entity, building_entity


# Create IFC model and setup
model, proj, site, building = create_basic_ifc_setup("Example Building")

# Create complete project structure using BIMFactoryElement
BIMFactoryElement(
        inst=building,
        children=[
                # Box wall positioned at origin
                BIMFactoryElement(type="IfcWall", name="Box Wall", children=[Box(width=5.0, depth=0.3, height=3.0)]),
                # Cube wall
                BIMFactoryElement(type="IfcWall", name="Cube Wall", children=[Cube(size=4.0)]),
                # Cylinder wall
                BIMFactoryElement(type="IfcWall", name="Cylinder Wall", children=[Cylinder(radius=1.5, height=4.0)]),
                # Extruded slab
                BIMFactoryElement(
                        type="IfcSlab",
                        name="Extruded Slab",
                        children=[Extrusion(basis=Rect(width=5.0, height=2.5), depth=0.3)],
                ),
                # Sphere element
                BIMFactoryElement(
                        type="IfcBuildingElementProxy",
                        name="Sphere Element",
                        children=[Sphere(radius=1.5, detail=2)]
                ),
        ],
).build(model)

# Save the model
model.write("example_building.ifc")
print("Saved: example_building.ifc")

This example demonstrates:

  • Setting up a proper IFC model with project hierarchy
  • Creating various geometric primitives (Box, Cube, Cylinder, Sphere)
  • Using profile-based extrusions (Rect → Extrusion)
  • Organizing elements in a hierarchical BIM structure
  • Saving the result as an IFC file

For more comprehensive examples, see the sections below which demonstrate all features including transformations, boolean operations, materials, and property sets.

Other examples

Additional examples are available in the GitHub repository. All examples generate IFC files and include validation using ifcopenshell.validate.

Example 1 - Complete Building

Example 1

Example 2 - Profile Extrusions

Example 2

Example 3 - Advanced Primitives

Example 3

Example 4 - Styled Elements

Example 4

Example 5 - Transformations

Example 5

Example 6 - Boolean Operations

Example 6

Example 7 - Property Sets

Example 7

Example 8 - Type Objects

Example 8

Example 9 - IFC Building Model

Example 9

Example 10 - IfcOpenHouse

Example 10

License

This project is licensed under the GNU Lesser General Public License v2.1 (LGPL-2.1).

Copyright (C) 2025 Freie und Hansestadt Hamburg, Landesbetrieb Geoinformation und Vermessung BIM-Leitstelle, Ahmed Salem

Metadata

Release files for ifcfactory 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ifcfactory 0.4.0
File Size Uploaded Provenance Actions
ifcfactory-0.4.0.tar.gz 33.5 kB With provenance Details for ifcfactory-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ifcfactory 0.4.0
File Interpreter ABI Platform Actions
ifcfactory-0.4.0-py3-none-any.whl Python 3 none any Details for ifcfactory-0.4.0-py3-none-any.whl

Total release size: 72.7 kB

Release files / ifcfactory-0.4.0.tar.gz

Download URL ifcfactory-0.4.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2635787a34bb0dbbeb5a08a8d6bfef105a3b86f4be9c4e47b7f6faf6113ce6c
BLAKE2b-256 checksum
How to use checksums
592a40456af7a8e0318ca2ffd824c18522ba26c6226ff5701dc875a795d2a5eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / ifcfactory-0.4.0-py3-none-any.whl

Download URL ifcfactory-0.4.0-py3-none-any.whl
Size 39.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2723bbc956fef8d8bb35665c93be8783f4d34bba4c907d280ab73749b4702e66
BLAKE2b-256 checksum
How to use checksums
1ac1fe0dcb61c50c8143ac63f02a668b6027bc29f53c27aac430d8efdd2903c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for ifcfactory 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ifcfactory-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page