feat(pdf): demonstrate creating and writing a pdf file

This commit is contained in:
Chuck Driesler
2025-02-26 20:27:04 +00:00
parent 669c1372c3
commit ce05ec6862
3 changed files with 697 additions and 547 deletions
+28
View File
@@ -1,6 +1,10 @@
from collections import defaultdict
from pydantic import Field
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus.tables import Table
from reportlab.lib.pagesizes import letter
from speckle_automate import (
AutomateBase,
AutomationContext,
@@ -467,6 +471,30 @@ def automate_function(
# Process results
_process_automation_results(automate_context, results)
# Generate PDF
file_name = "report.pdf"
doc = SimpleDocTemplate(file_name, pagesize=letter)
pdf_data = [
["Element ID", "Material", "Embodied Carbon"]
]
for element in RevitCarbonAnalyzer._iterate_elements(model_root):
if hasattr(element, "properties"):
element_properties = element["properties"]
element_id = element_properties["elementId"]
if "Embodied Carbon Calculation" in element_properties:
for key, value in element_properties["Embodied Carbon Calculation"].items():
pdf_data.append([
element_id,
key,
"{:0.2f} {}".format(value["embodied carbon"]["value"], value["embodied carbon"]["units"])
])
table = Table(pdf_data)
doc.build([table])
automate_context.store_file_result(file_name)
# Calculate success percentage (successful / (successful + errors))
total_processed = (
len(results["processed_elements"])
Generated
+656 -535
View File
File diff suppressed because it is too large Load Diff
+9 -8
View File
@@ -1,28 +1,29 @@
[tool.poetry]
name = "speckle-automate-py"
version = "0.1.0"
description = "Example function for Speckle Automate using specklepy"
authors = ["Gergő Jedlicska <gergo@jedlicska.com>"]
readme = "README.md"
description = "Example function for Speckle Automate using specklepy"
name = "speckle-automate-py"
package-mode = false
readme = "README.md"
version = "0.1.0"
[tool.poetry.dependencies]
python = "^3.11"
specklepy = "^2.21.0"
pylint = "^3.3.4"
python = "^3.11"
reportlab = "^4.3.1"
specklepy = "^2.21.0"
structlog = "^25.1.0"
[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
mypy = "^1.3.0"
ruff = "^0.0.271"
pydantic-settings = "^2.3.0"
pytest = "^7.4.2"
ruff = "^0.0.271"
# specklepy = { path = "../specklepy", develop = true }
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core"]
[tool.ruff]
select = [