Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35d428e7bb | |||
| 3be31ec96f | |||
| 6e0d653c72 | |||
| bcdf172982 |
@@ -29,7 +29,7 @@ jobs:
|
||||
run: |
|
||||
python main.py generate_schema ${HOME}/${{ env.FUNCTION_SCHEMA_FILE_NAME }}
|
||||
- name: Speckle Automate Function - Build and Publish
|
||||
uses: specklesystems/speckle-automate-github-composite-action@0.8.0
|
||||
uses: specklesystems/speckle-automate-github-composite-action@0.8.1
|
||||
with:
|
||||
speckle_automate_url: ${{ env.SPECKLE_AUTOMATE_URL || 'https://automate.speckle.dev' }}
|
||||
speckle_token: ${{ secrets.SPECKLE_FUNCTION_TOKEN }}
|
||||
|
||||
+5
-3
@@ -7,7 +7,9 @@ from specklepy.objects import Base
|
||||
|
||||
def flatten_base(base: Base) -> Iterable[Base]:
|
||||
"""Take a base and flatten it to an iterable of bases."""
|
||||
if hasattr(base, "elements"):
|
||||
for element in base["elements"]:
|
||||
yield from flatten_base(element)
|
||||
if hasattr(base, "elements") and base.elements is not None:
|
||||
# Check if base.elements is not only present and non-None, but also an iterable
|
||||
if isinstance(base.elements, Iterable):
|
||||
for element in base.elements:
|
||||
yield from flatten_base(element)
|
||||
yield base
|
||||
|
||||
@@ -9,6 +9,7 @@ from speckle_automate import (
|
||||
AutomationContext,
|
||||
execute_automate_function,
|
||||
)
|
||||
from specklepy.objects import Base
|
||||
|
||||
from flatten import flatten_base
|
||||
|
||||
@@ -31,6 +32,18 @@ class FunctionInputs(AutomateBase):
|
||||
),
|
||||
)
|
||||
|
||||
import json
|
||||
|
||||
def serialize_base(base: Base) -> str:
|
||||
"""Serializes a Base object to a JSON string."""
|
||||
# Assuming there is a method to convert base objects to dictionaries
|
||||
base_dict = base.to_dict() if hasattr(base, 'to_dict') else {}
|
||||
|
||||
# Use json.dumps() to convert the dictionary to a JSON string
|
||||
# Set `default=str` to handle any objects that are not directly serializable by default
|
||||
return json.dumps(base_dict, indent=4, default=str)
|
||||
|
||||
|
||||
|
||||
def automate_function(
|
||||
automate_context: AutomationContext,
|
||||
@@ -48,6 +61,10 @@ def automate_function(
|
||||
# the context provides a conveniet way, to receive the triggering version
|
||||
version_root_object = automate_context.receive_version()
|
||||
|
||||
# At the point in your code where you want to log the initial base object:
|
||||
initial_base_json = serialize_base(initial_base)
|
||||
print(f"Initial base object as JSON:\n{version_root_object}")
|
||||
|
||||
objects_with_forbidden_speckle_type = [
|
||||
b
|
||||
for b in flatten_base(version_root_object)
|
||||
|
||||
Reference in New Issue
Block a user