Skip to content

How to get a scene for each selected element using python in cadwork? #127

@lucas-ita

Description

@lucas-ita

Based on the code from the Cadwork API documentation, I have created the code below. My intention is to obtain a scene for each selected element. However, when I select multiple elements, it currently creates a scene for each one. Unfortunately, the content of each scene includes all the elements instead of having each element in a separate scene.

import element_controller as ec
import cadwork
import scene_controller as sc

# Get the IDs of all selected elements
element_ids = ec.get_active_identifiable_element_ids()

# Check if there are selected elements
if element_ids:
    # Create an individual scene for each element
    for i in range(len(element_ids)):
        scene_name = f'Scene {i + 1}'  # Add 1 to start counting from 1
        new_scene = sc.add_scene(scene_name)

        # Check if the scene was successfully created
        if new_scene:
            # Add the corresponding element to the scene
            sc.add_elements_to_scene(scene_name, [element_ids[i]])

            # Activate the scene
            sc.activate_scene(scene_name)

else:
    print("No elements selected.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions