{
  "kind": "dsl",
  "metadata": {
    "title": "Render Marker Ranges With Export Preset",
    "descriptionMarkdown": "Renders one file per non-zero-duration marker on the active sequence. The workflow asks for an `.epr` export preset and an output folder first, then sets sequence in/out to each marker range and renders that range with `prRenderSequence range=IN_OUT`."
  },
  "dsl": {
    "version": 0,
    "execution": {
      "transactionMode": "SAFE_AUTO_COMMIT"
    },
    "entry": "b1",
    "blocks": {
      "b1": {
        "type": "setVar",
        "inputs": {
          "name": "presetPath",
          "value": {
            "type": "openFileDialog",
            "inputs": {
              "types": [
                "epr"
              ],
              "cancelBehavior": "STOP",
              "initialDomain": "USER_DOCUMENTS"
            }
          }
        },
        "next": "b2"
      },
      "b2": {
        "type": "setVar",
        "inputs": {
          "name": "outputFolder",
          "value": {
            "type": "openFolderDialog",
            "inputs": {
              "cancelBehavior": "STOP",
              "initialDomain": "USER_DOCUMENTS"
            }
          }
        },
        "next": "b3"
      },
      "b3": {
        "type": "setVar",
        "inputs": {
          "name": "extension",
          "value": {
            "type": "prGetExportFileExtension",
            "inputs": {
              "sequence": "::SEQ\\ACTIVE",
              "presetPath": {
                "var": "presetPath"
              }
            }
          }
        },
        "next": "b4"
      },
      "b4": {
        "type": "setVar",
        "inputs": {
          "name": "totalMarkerCount",
          "value": 0
        },
        "next": "b5"
      },
      "b5": {
        "type": "setVar",
        "inputs": {
          "name": "renderedMarkerCount",
          "value": 0
        },
        "next": "b6"
      },
      "b6": {
        "type": "setVar",
        "inputs": {
          "name": "skippedZeroDurationCount",
          "value": 0
        },
        "next": "b7"
      },
      "b7": {
        "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": "markerDurationSeconds",
              "value": {
                "type": "prGetMarkerProperty",
                "inputs": {
                  "marker": {
                    "var": "markerRef"
                  },
                  "property": "DURATION_SECONDS"
                }
              }
            }
          },
          {
            "type": "if",
            "inputs": {
              "branches": [
                {
                  "condition": {
                    "type": "logicCompare",
                    "inputs": {
                      "op": "LTE",
                      "a": {
                        "var": "markerDurationSeconds"
                      },
                      "b": 0
                    }
                  },
                  "body": [
                    {
                      "type": "setVar",
                      "inputs": {
                        "name": "skippedZeroDurationCount",
                        "value": {
                          "type": "mathArithmetic",
                          "inputs": {
                            "op": "ADD",
                            "a": {
                              "var": "skippedZeroDurationCount"
                            },
                            "b": 1
                          }
                        }
                      }
                    }
                  ]
                }
              ],
              "elseBody": [
                {
                  "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": "markerEndSeconds",
                    "value": {
                      "type": "prGetMarkerProperty",
                      "inputs": {
                        "marker": {
                          "var": "markerRef"
                        },
                        "property": "END_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": "outputPath",
                    "value": {
                      "type": "textJoin",
                      "inputs": {
                        "items": [
                          {
                            "var": "outputFolder"
                          },
                          "/marker-",
                          {
                            "var": "markerIndexOneBased"
                          },
                          "-",
                          {
                            "var": "markerStartText"
                          },
                          ".",
                          {
                            "var": "extension"
                          }
                        ]
                      }
                    }
                  }
                },
                {
                  "type": "prSetSequenceProperty",
                  "inputs": {
                    "sequence": "::SEQ\\ACTIVE",
                    "property": "IN_POINT_SECONDS",
                    "value": {
                      "var": "markerStartSeconds"
                    },
                    "onError": "STOP"
                  }
                },
                {
                  "type": "prSetSequenceProperty",
                  "inputs": {
                    "sequence": "::SEQ\\ACTIVE",
                    "property": "OUT_POINT_SECONDS",
                    "value": {
                      "var": "markerEndSeconds"
                    },
                    "onError": "STOP"
                  }
                },
                {
                  "type": "prRenderSequence",
                  "inputs": {
                    "sequence": "::SEQ\\ACTIVE",
                    "target": "IMMEDIATELY",
                    "range": "IN_OUT",
                    "outputPath": {
                      "var": "outputPath"
                    },
                    "presetPath": {
                      "var": "presetPath"
                    },
                    "waitForCompletion": true,
                    "onError": "STOP"
                  }
                },
                {
                  "type": "setVar",
                  "inputs": {
                    "name": "renderedMarkerCount",
                    "value": {
                      "type": "mathArithmetic",
                      "inputs": {
                        "op": "ADD",
                        "a": {
                          "var": "renderedMarkerCount"
                        },
                        "b": 1
                      }
                    }
                  }
                }
              ]
            }
          }
        ],
        "next": "b8"
      },
      "b8": {
        "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 nothing was rendered."
                  }
                }
              ]
            }
          ],
          "elseBody": [
            {
              "type": "uiShowMessage",
              "inputs": {
                "message": {
                  "type": "textJoin",
                  "inputs": {
                    "items": [
                      "Rendered ",
                      {
                        "var": "renderedMarkerCount"
                      },
                      " marker range(s) to ",
                      {
                        "var": "outputFolder"
                      },
                      ". Skipped ",
                      {
                        "var": "skippedZeroDurationCount"
                      },
                      " zero-duration marker(s)."
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
  }
}
