How to create Timeline Groups

info83PHN
Advocate

How to create Timeline Groups

info83PHN
Advocate
Advocate

Would like to have all the additions to the timeline, created by a script, contained in a Group on the timeline.

 

What's the workflow to do this ?

 

Create Group > script adds to timeline > close Group ?

or

script at the end of my process to group the last 'x' number of timeline items in to a Group ?

 

Anyone have any sample code to do this ?

 

0 Likes
Reply
Accepted solutions (1)
684 Views
4 Replies
Replies (4)

kandennti
Mentor
Mentor
Accepted solution

Hi @info83PHN .

 

We created 5 sketches and made a sample to create a timeline group.

# 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

        # create sketches
        skts = []
        for _ in range(5):
            skts.append(root.sketches.add(root.xYConstructionPlane))

        # create timeline group
        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e0f48ae5-1fb7-4d56-b0cc-6a51e8ef153a
        tl: adsk.fusion.Timeline = des.timeline
        tl.timelineGroups.add(
            skts[0].timelineObject.index,
            skts[-1].timelineObject.index
        )

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

info83PHN
Advocate
Advocate

@kandennti  Thank You for the feedback.

So I believe this gives me 2 options :

 

option 1 is - at the start of my script, create an array to hold some reference or list of all the items that my script adds to the timeline ( copy, sketch, extrude, combine, move, etc ).

At the end of the script, use timelineGroups.add to add al those items to a new timeline group.

option 2 would be, at the start of the code, to get / read the index of the last item in the timeline ( before the timeline cursor ), process the script, then read the last timeline index again, and then add the timeline items between the 2 indices to a new group.

 

0 Likes

info83PHN
Advocate
Advocate

@kandenntihuge thanks for putting me on the right track. Got it working. here's what I used :

 

# before doing the script work got the timeline market position

                TLstart = design.timeline.markerPosition

# did all the script work here

# after all the script work get the timeline marker position

                TLend = design.timeline.markerPosition
                TLend = TLend - 1

# create the timeline group

                t1: adsk.fusion.Timeline = design.timeline
                t2 = t1.timelineGroups.add( TLstart, TLend)                

# give the group a name

                t2.name = "abc"
				
				
0 Likes

kandennti
Mentor
Mentor

@info83PHN .

 

Simply use the first and last indexes of the timeline for which you want to create a group.

The only thing to note is that you cannot include a timeline group within a timeline group.

 

The current timeline marker can be retrieved with the markerPosition property.
The last index can be obtained with count, but the position of the timeline marker should not always be the last when the script is executed.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d0cede26-e905-45b4-b30d-8f244670c1f7 

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-31a17f8c-8245-4180-bff0-a6931a6c9dc2 

1 Like