Bookmarks 2025

Literally no idea what I did in re-writing this, but this is working now:

def get_main_menu_custom_ui_actions():

def create_project_bookmark(selection):
    import os
    import json
    import flame

    try:
        from PySide6.QtWidgets import QInputDialog, QLineEdit
    except ImportError:
        from PySide2.QtWidgets import QInputDialog, QLineEdit

    # -----------------------------------
    # BOOKMARK NAME
    # -----------------------------------

    bookmark_name, ok = QInputDialog.getText(
        None,
        "Create Bookmark",
        "Enter short bookmark name:",
        QLineEdit.Normal,
        ""
    )

    if not ok or not bookmark_name.strip():
        return

    bookmark_name = bookmark_name.strip()

    # -----------------------------------
    # BOOKMARK PATH
    # -----------------------------------

    bookmark_path, ok = QInputDialog.getText(
        None,
        "Create Bookmark",
        "Enter full file path:",
        QLineEdit.Normal,
        ""
    )

    if not ok or not bookmark_path.strip():
        return

    bookmark_path = bookmark_path.strip()

    # -----------------------------------
    # CURRENT PROJECT
    # -----------------------------------

    project_name = flame.project.current_project.project_name

    bookmarks_file = (
        "/var/opt/Autodesk/flame/projects/{}/setups/status/cf_bookmarks.json"
        .format(project_name)
    )

    if not os.path.exists(bookmarks_file):
        flame.messages.show_in_dialog(
            "Error",
            "Could not find:\n{}".format(bookmarks_file),
            "error",
            ["OK"]
        )
        return

    # -----------------------------------
    # LOAD JSON
    # -----------------------------------

    with open(bookmarks_file, "r") as f:
        data = json.load(f)

    sections = data.get("DlBookmark", {}).get("Sections", [])

    # -----------------------------------
    # FIND PROJECTS SECTION
    # -----------------------------------

    project_section = None

    for section in sections:
        if section.get("Section") == "Project":
            project_section = section
            break

    if project_section is None:
        flame.messages.show_in_dialog(
            "Error",
            "Project section not found.",
            "error",
            ["OK"]
        )
        return

    # -----------------------------------
    # ADD TO BOOKMARKS ARRAY
    # -----------------------------------

    bookmarks = project_section.get("Bookmarks")

    if bookmarks is None:
        bookmarks = []
        project_section["Bookmarks"] = bookmarks

    bookmarks.append({
        "Bookmark": bookmark_name,
        "Path": bookmark_path,
        "Visibility": "Global"
    })

    # -----------------------------------
    # SAVE JSON
    # -----------------------------------

    with open(bookmarks_file, "w") as f:
        json.dump(data, f, indent=4)

    # -----------------------------------
    # MESSAGE
    # -----------------------------------

    flame.messages.show_in_dialog(
        "Bookmark Created",
        "Bookmark: {}\nPath:\n{}".format(
            bookmark_name,
            bookmark_path
        ),
        "info",
        ["OK"]
    )

return [
    {
        "name": "BOOKMARK TOOLS",
        "actions": [
            {
                "name": "Create Project Bookmark",
                "caption": "Create Project Bookmark",
                "execute": create_project_bookmark,
            }
        ]
    }
]