timelineObject for moving bodies

brad.bylls
Collaborator

timelineObject for moving bodies

brad.bylls
Collaborator
Collaborator

I am grouping objects in the timeline.

However, I cannot find the last 'move' timelineObject

I would like to get the 'move' (red arrow) into the group (blue arrow)

Screenshot (31).png

 

 

 

 

The code works and moves the bodies, I just want to get the timelimeObject 'move' into the group.

This is the part of the code I am working with.

Screenshot (30).png

Brad Bylls
0 Likes
Reply
Accepted solutions (1)
530 Views
7 Replies
Replies (7)

kandennti
Mentor
Mentor

Hi @brad.bylls .

 

Perhaps it is not possible to add elements to a timeline group.

Therefore, I deleted the timeline group and re-created it.


# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        tlGroup: adsk.fusion.TimelineGroup = des.timeline.timelineGroups[-1]
        targetFeat: adsk.fusion.MoveFeature = root.features.moveFeatures[-1]

        add_group_like(tlGroup, targetFeat)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def add_group_like(
    group: adsk.fusion.TimelineGroup,
    targetFeat: adsk.fusion.MoveFeature) -> adsk.fusion.TimelineGroup:

    # backup
    backupCollapsed = group.isCollapsed 
    backupName = group.name

    # get timeline group items
    startObj: adsk.fusion.TimelineObject = group.item(0)
    endObj: adsk.fusion.TimelineObject= group.item(group.count - 1)

    # delete timeline group
    group.isCollapsed = True
    group.deleteMe(False)

    # get the index that creates the group
    indexes = [
        startObj.index,
        endObj.index,
        targetFeat.timelineObject.index
    ]
    startIdx = min(indexes)
    endIdx = max(indexes)

    # create new timeline group
    des: adsk.fusion.Design = targetFeat.parentComponent.parentDesign
    groups: adsk.fusion.TimelineGroups = des.timeline.timelineGroups
    newGroup: adsk.fusion.TimelineGroup = groups.add(startIdx, endIdx)

    # match state
    newGroup.isCollapsed = backupCollapsed
    newGroup.name = backupName

    return newGroup

 

If you run it with the attached f3d file, you will see the following.

1.png

0 Likes

BrianEkins
Mentor
Mentor

@kandennti is correct. Fusion doesn't support adding items to an existing group. The exception to this is if you expand the group and move the timeline marker to somewhere within the group, and add a new feature. The new feature will now be part of a group. However, it's not possible to move the timeline marker to the end of the group, so it's after the last feature but still within the group. The best alternative is, as kandennti suggested, and delete and re-create the group.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

brad.bylls
Collaborator
Collaborator

I am not trying to ADD to the group.

I cannot CREATE the group with the move in it.

It tells me that the move does not have a timelineObject. 

Brad Bylls
0 Likes

brad.bylls
Collaborator
Collaborator
Accepted solution

I was not trying to add to a group, I was trying to create the group with 'move' in it and couldn't get the 'timelineObject' for the moveFeats.

Turns out all I needed to do was

Screenshot (32).png

Brad Bylls
0 Likes

kandennti
Mentor
Mentor

@brad.bylls .

 

index is a read-only property and cannot be assigned to.

1.png

0 Likes

brad.bylls
Collaborator
Collaborator

@kandennti yes I know.

I was just getting the number.

Brad Bylls
0 Likes

kandennti
Mentor
Mentor

@brad.bylls .

 

I think "moveFeats" refers to the adsk.fusion.MoveFeatures object.

The corresponding adsk.fusion.MoveFeature object must be retrieved with the Item method.

0 Likes