Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

timelineObject for moving bodies

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
brad.bylls
312 Views, 7 Replies

timelineObject for moving bodies

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
7 REPLIES 7
Message 2 of 8
kandennti
in reply to: brad.bylls

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

Message 3 of 8
BrianEkins
in reply to: kandennti

@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
Message 4 of 8
brad.bylls
in reply to: BrianEkins

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
Message 5 of 8
brad.bylls
in reply to: kandennti

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
Message 6 of 8
kandennti
in reply to: brad.bylls

@brad.bylls .

 

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

1.png

Message 7 of 8
brad.bylls
in reply to: kandennti

@kandennti yes I know.

I was just getting the number.

Brad Bylls
Message 8 of 8
kandennti
in reply to: brad.bylls

@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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report