{
  "kind": "dsl",
  "metadata": {
    "title": "Render Frames At Sequence Markers",
    "descriptionMarkdown": "Exports one `.png` still image for each marker on the active sequence. The output folder is chosen first. Each file is rendered at the active sequence frame size, and the filenames include the marker index and marker start time."
  },
  "dsl": {
    "version": 0,
    "entry": "b1",
    "blocks": {
      "b1": {
        "type": "setVar",
        "inputs": {
          "name": "outputFolder",
          "value": {
            "type": "openFolderDialog",
            "inputs": {
              "cancelBehavior": "STOP",
              "initialDomain": "USER_DOCUMENTS"
            }
          }
        },
        "next": "b2"
      },
      "b2": {
        "type": "setVar",
        "inputs": {
          "name": "frameWidth",
          "value": {
            "type": "prGetSequenceProperty",
            "inputs": {
              "sequence": "::SEQ\\ACTIVE",
              "property": "FRAME_WIDTH"
            }
          }
        },
        "next": "b3"
      },
      "b3": {
        "type": "setVar",
        "inputs": {
          "name": "frameHeight",
          "value": {
            "type": "prGetSequenceProperty",
            "inputs": {
              "sequence": "::SEQ\\ACTIVE",
              "property": "FRAME_HEIGHT"
            }
          }
        },
        "next": "b4"
      },
      "b4": {
        "type": "setVar",
        "inputs": {
          "name": "totalMarkerCount",
          "value": 0
        },
        "next": "b5"
      },
      "b5": {
        "type": "setVar",
        "inputs": {
          "name": "exportedFrameCount",
          "value": 0
        },
        "next": "b6"
      },
      "b6": {
        "type": "prForEachMarker",
        "inputs": {
          "owner": "::SEQ\\ACTIVE",
          "order": "ASC",
          "markerVar": "markerRef",
          "indexVar": "i"
        },
        "body": [
          {
            "type": "setVar",
            "inputs": {
              "name": "totalMarkerCount",
              "value": {
                "type": "mathArithmetic",
                "inputs": {
                  "op": "ADD",
                  "a": {
                    "var": "totalMarkerCount"
                  },
                  "b": 1
                }
              }
            }
          },
          {
            "type": "setVar",
            "inputs": {
              "name": "markerIndexOneBased",
              "value": {
                "type": "mathArithmetic",
                "inputs": {
                  "op": "ADD",
                  "a": {
                    "var": "i"
                  },
                  "b": 1
                }
              }
            }
          },
          {
            "type": "setVar",
            "inputs": {
              "name": "markerStartSeconds",
              "value": {
                "type": "prGetMarkerProperty",
                "inputs": {
                  "marker": {
                    "var": "markerRef"
                  },
                  "property": "START_SECONDS"
                }
              }
            }
          },
          {
            "type": "setVar",
            "inputs": {
              "name": "markerStartTextRaw",
              "value": {
                "type": "prFormatTime",
                "inputs": {
                  "timeSeconds": {
                    "var": "markerStartSeconds"
                  },
                  "format": "HH_MM_SS_MS"
                }
              }
            }
          },
          {
            "type": "setVar",
            "inputs": {
              "name": "markerStartText",
              "value": {
                "type": "textReplace",
                "inputs": {
                  "text": {
                    "type": "textReplace",
                    "inputs": {
                      "text": {
                        "var": "markerStartTextRaw"
                      },
                      "from": ":",
                      "to": "_"
                    }
                  },
                  "from": ",",
                  "to": "_"
                }
              }
            }
          },
          {
            "type": "setVar",
            "inputs": {
              "name": "framePath",
              "value": {
                "type": "textJoin",
                "inputs": {
                  "items": [
                    {
                      "var": "outputFolder"
                    },
                    "/marker-",
                    {
                      "var": "markerIndexOneBased"
                    },
                    "-",
                    {
                      "var": "markerStartText"
                    },
                    ".png"
                  ]
                }
              }
            }
          },
          {
            "type": "prExportSequenceFrame",
            "inputs": {
              "sequence": "::SEQ\\ACTIVE",
              "timeSeconds": {
                "var": "markerStartSeconds"
              },
              "outputPath": {
                "var": "framePath"
              },
              "width": {
                "var": "frameWidth"
              },
              "height": {
                "var": "frameHeight"
              },
              "onError": "STOP"
            }
          },
          {
            "type": "setVar",
            "inputs": {
              "name": "exportedFrameCount",
              "value": {
                "type": "mathArithmetic",
                "inputs": {
                  "op": "ADD",
                  "a": {
                    "var": "exportedFrameCount"
                  },
                  "b": 1
                }
              }
            }
          }
        ],
        "next": "b7"
      },
      "b7": {
        "type": "if",
        "inputs": {
          "branches": [
            {
              "condition": {
                "type": "logicCompare",
                "inputs": {
                  "op": "EQ",
                  "a": {
                    "var": "totalMarkerCount"
                  },
                  "b": 0
                }
              },
              "body": [
                {
                  "type": "uiShowMessage",
                  "inputs": {
                    "message": "The active sequence has no markers, so no frames were exported."
                  }
                }
              ]
            }
          ],
          "elseBody": [
            {
              "type": "uiShowMessage",
              "inputs": {
                "message": {
                  "type": "textJoin",
                  "inputs": {
                    "items": [
                      "Exported ",
                      {
                        "var": "exportedFrameCount"
                      },
                      " frame(s) to ",
                      {
                        "var": "outputFolder"
                      },
                      "."
                    ]
                  }
                }
              }
            }
          ]
        },
        "next": null
      }
    }
  }
}
