[{"_id":"remote-MoCode-Demo-1565344140295","name":"MoCode Demo","type":"expression","expressions":[{"_id":"remote-Auto-Animate-In---Out-1565346599727","code":"var min = _ slider: Minimum Value: create _;\r\nvar max = _ slider: Maximum Value: create _;\r\nvar durationIn = _ slider: IN duration: create _;\r\nvar durationOut = _ slider: OUT duration: create _;\r\nvar delay = _ slider: Delay: create _;\r\n\r\nif (time < ((outPoint - inPoint) / 2 + inPoint)) {\r\n\tease(time, inPoint + framesToTime(delay), inPoint + framesToTime(durationIn + delay), min, max);\r\n} else {\r\n\tease(time, outPoint - framesToTime(durationOut + delay), outPoint - framesToTime(delay), max, min);\r\n}","name":"Auto Animate In & Out","documentation":"Auto animate a property based on layer **inPoint** and **outPoint**. \nThis expression works only for a **1D property** and needs to be adapted for 2D and 3D properties. ","property_types":["1d"],"tags":["automation","animation","demo"],"last_update":1571340516828},{"_id":"remote-Hide-layer-if-text-is-empty-1565352885521","code":"var source_text = _ text: Text Layer: link _;\r\nif (source_text != \"\") value;\r\nelse 0;","name":"Hide layer if text is empty","documentation":"Set `opacity` to **0** if another text layer content is empty.","tags":["text","demo"],"last_update":1565352983572},{"_id":"remote-Random-Color-1565344169111","code":"require(\"color-lib\");\r\n\r\nvar color = _ color: Main Color: create _;\r\nvar seed = _ slider: Seed: create _;\r\n\r\nvar h = _ slider: Random Hue: create _ / 100;\r\nvar s = _ slider: Random Saturation: create _ / 100;\r\nvar l = _ slider: Random Luminosity: create _ / 100;\r\n\r\nrandomColor(color, h, s, l, seed);","name":"Random Color","documentation":"Apply this expression to multiple color properties to quickly randomize `hue`, `saturation` and `luminosity`. \n\nThis example uses the **\"color-lib\"** include from the Demo library thanks to `require()` method.","property_types":["color"],"tags":["color","random","demo","visual"],"last_update":1585736152328},{"_id":"remote-Syntax-Demo-1565353091358","code":"var slider = _ slider: Slider Demo: create _;\n\nvar point = _ point: Point Demo: link _;\n\nvar color = _ color: Color Demo: static _;\n\nvar angle = _ angle: Angle Demo: create _;\n\nvar checkbox = _ checkbox: Checkbox Demo: static _;\n\nvar layer = _ layer: Layer Demo: create _;\n\nvar text = _ text: Text Demo: link _;","name":"Syntax Demo","documentation":"Open Visual Mode to understand the syntax.\n\nLearn more about MoCode syntax in the documentation...","tags":["demo"],"last_update":1565353165204},{"_id":"remote-Wiggle-1565344608843","code":"var amp = _ slider: Wiggle Amplitude: create _;\nvar freq = _ slider: Wiggle Frequency: create _;\nwiggle(freq, amp);","name":"Wiggle","documentation":"Just a simple **wiggle** with `amplitude` and `frequency` controllers.","tags":["demo","visual"],"last_update":1565344736693}]},{"_id":"remote-MoCode-Demo-1565354068763","name":"MoCode Demo","type":"script","expressions":[{"_id":"remote-Duplicate-Layer-1565354418948","code":"app.beginUndoGroup(\"Duplicate Layers\");\n\n//Create a context with DAEF\nvar context = new mocode.Context(\"selected_layers\");\nvar n_duplicates = _number: Number of duplicates_;\nif (!context.error) {\n\tvar layer = context.selected_layers[0];\n\t//Use DAEF method to duplicate a layer multiple time\n\tmocode.layer.duplicateMultiple(layer, n_duplicates);\n} else {\n\talert(\"Please select a layer.\");\n}\n\napp.endUndoGroup();","name":"Duplicate Layer","documentation":"Duplicate the first selected layer multiple time. This script uses some methods of **DAEF** (**D**anim **A**fter **E**ffects **F**ramework) which is undocumented for the moment. \n\nYou can use all the methods of DAEF with MoCode. They'll be documented soon.","tags":["demo","DAEF"],"last_update":1569949297563},{"_id":"remote-Link-text-content-to-marker-1565357685837","code":"app.beginUndoGroup(\"Create markers\");\n\n//Create controllers for visual mode\nvar times = _ number - [0, Infinity]: Times in seconds _;\nvar texts = _ string - [0, Infinity]: Texts: add the same amount of texts than times _;\n\nvar target_is_comp = false;\nvar active_comp = app.project.activeItem;\n\nif (active_comp) {\n\n\t//Get the selected text layer\n\tvar text_layer = null;\n\tvar selected_layers = active_comp.selectedLayers;\n\tfor (var i = 0; i < selected_layers.length; i++) {\n\t\tif (selected_layers[i].property(\"sourceText\")) {\n\t\t\ttext_layer = selected_layers[i];\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (text_layer !== null) {\n\n\t\tif (target_is_comp === true) {\n\t\t\tvar markers = active_comp.markerProperty;\n\t\t\tvar exp_replace = \"thisComp\";\n\t\t} else {\n\t\t\tvar markers = text_layer.property(\"Marker\");\n\t\t\tvar exp_replace = \"thisLayer\";\n\t\t}\n\n\t\t//Get \"text-exp\" expression, and replace string \"[target]\" by thisComp or thisLayer, depending on user choice\n\t\tvar marker_exp = mocode.lib.getExpression(\"text-exp\", {\n\t\t\t\"_target_\": exp_replace\n\t\t});\n\t\ttext_layer.property(\"sourceText\").expression = marker_exp;\n\n\t\t//Create a marker for each added time and text\n\t\tif (times.length === 0) {\n\t\t\tvar duration = text_layer.outPoint - text_layer.inPoint;\n\t\t\ttimes = [duration / 3, 2 * duration / 3];\n\t\t}\n\t\tif (texts.length === 0) texts = [\"Subtitle1\", \"Subtitle2\"];\n\n\t\tfor (var i = 0; i < times.length; i++) {\n\t\t\tvar time = times[i];\n\t\t\tvar text = texts[i];\n\t\t\tif (text) {\n\t\t\t\tvar marker = new MarkerValue(text);\n\t\t\t\tmarkers.setValueAtTime(time, marker);\n\t\t\t} else break;\n\t\t}\n\n\t\talert(\"Your text layer has been configured. You can now add other markers manually.\");\n\n\t} else alert(\"Please select a text layer\");\n}\n\napp.endUndoGroup();","name":"Link text content to markers","documentation":"### Manipulate markers and expressions\n\nSelect a text layer and this script will create markers on it, and add an expression to `sourceText` to link text content to layer content. You have to define the same amount of texts than times.\n\n### How to get \"text-exp\" expression?\n\nTo get `sourceText` expression, `mocode.lib.getExpression(\"text-exp\")` is used with a replacement array as a second parameter, depending if user has chosen to create markers on composition or text layer.\n\n_This script is a proof of concept: a CSV import would be more suitable._","tags":["demo","text"],"related_expressions":[{"id":"text-exp","code":"var target = _target_;\r\nvar _marker = target.marker;\r\nvar txt = \"\";\r\nif (_marker.numKeys > 0){\r\n  var n = _marker.nearestKey(time).index;\r\n  if (time < _marker.key(n).time) n--;\r\n  if (n > 0) txt = _marker.key(n).comment;\r\n}\r\ntxt"}],"last_update":1604069922384},{"_id":"remote-Markers-to-Srt-1604065420752","code":"var context = new mocode.Context(\"selected_layers\");\nif (!context.error) {\n\tvar comp = context.comp;\n\tvar layer = context.selected_layers[0];\n\tvar markers = mocode.marker.getMarkers(layer);\n\tvar activeText = \"\";\n\tvar activeTime = null;\n\tvar subtitles = [];\n\tfor (var n = 1; n <= markers.numKeys; n++) {\n\t\tvar mContent = markers.keyValue(n).comment;\n\t\tvar mTime = markers.keyTime(n);\n\t\tif (mTime > comp.duration) break;\n\t\tif (activeText !== \"\") {\n\t\t\tsubtitles.push({\n\t\t\t\tcontent: activeText,\n\t\t\t\tstart: activeTime,\n\t\t\t\tend: mTime\n\t\t\t});\n\t\t}\n\t\tactiveTime = mTime;\n\t\tactiveText = mContent;\n\t}\n\tif (activeText !== \"\") {\n\t\tsubtitles.push({\n\t\t\tcontent: activeText,\n\t\t\tstart: activeTime,\n\t\t\tend: comp.duration\n\t\t});\n\t}\n\tif (subtitles.length === 0) alert(\"Please select a text layer with markers\");\n\telse {\n\t\tvar srt = \"\";\n\n\t\tfunction getTimeCodeString(t) {\n\t\t\tvar timecode = timeToCurrentFormat(t, 1 / comp.frameDuration);\n\t\t\treturn timecode.slice(0, 8) + \",\" + timecode.slice(9, 11) * (1000 / (1 / comp.frameDuration));\n\t\t}\n\n\t\tfor (var i = 0; i < subtitles.length; i++) {\n\t\t\tvar subtitle = subtitles[i];\n\t\t\tvar strIn = getTimeCodeString(subtitle.start);\n\t\t\tvar strOut = getTimeCodeString(subtitle.end);\n\t\t\tsrt += (i + 1);\n\t\t\tsrt += \"\\r\\n\";\n\t\t\tsrt += strIn;\n\t\t\tsrt += \" --> \";\n\t\t\tsrt += strOut;\n\t\t\tsrt += \"\\r\\n\";\n\t\t\tsrt += subtitle.content;\n\t\t\tsrt += \"\\r\\n\\n\";\n\t\t}\n\n\t\tvar sourceFile = app.project.file;\n\t\tif (sourceFile) sourceFile = new File(sourceFile.parent.fsName + \"/subtitle.srt\");\n\t\telse sourceFile = new File(Folder.desktop.fsName + \"/subtitle.srt\");\n\n\t\tvar file = sourceFile.saveDlg(\"Define your destination file\", \"Srt:*.srt\");\n\t\tif (file) mocode.fs.writeFile(file, srt);\n\t}\n} else alert(\"Please select a text layer\");","name":"Markers to SRT","documentation":"Read all markers in the selected text layer and export a .srt file","last_update":1604068470825},{"_id":"remote-Randomize-Position-1565354181249","code":"var z_amp = _ number: Z Random Amplitude _;\n\nif (app.project) {\n\tvar myComp = app.project.activeItem;\n\tif (myComp) {\n\t\tvar layers = myComp.selectedLayers;\n\t\tfor (var i = 0; i < layers.length; i++) {\n\t\t\tvar x = Math.random() * myComp.width;\n\t\t\tvar y = Math.random() * myComp.height;\n\t\t\tvar z = Math.random() * z_amp;\n\t\t\tlayers[i].position.setValue([x, y, z]);\n\t\t}\n\t}\n}","name":"Randomize Position","documentation":"Randomize position of selected layers inside active comp width and height. You can adjust `z_amp` with Visual Mode.","tags":["demo","random"],"last_update":1570460944196},{"_id":"remote-Select-same-properties-in-all-layers-1574151690991","code":"var context = new mocode.Context(\"selected_layers\", true);\nif (!context.error) {\n\tvar layers = context.selected_layers;\n\tvar props_array = null;\n\tvar first_layer = null;\n\tfor (var i = 0; i < layers.length; i++) {\n\t\tvar props = layers[i].selectedProperties;\n\t\tif (props.length > 0) {\n\t\t\tprops_array = props;\n\t\t\tfirst_layer = layers[i];\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (props_array) {\n\t\tvar paths = [];\n\t\tfor (var i = 0; i < props_array.length; i++) {\n\t\t\tvar path = mocode.lib.getPropertyPath(props_array[i], false);\n\t\t\tif (path) paths.push(path);\n\t\t}\n\t\tfor (var i = 0; i < layers.length; i++) {\n\t\t\tif (layers[i].index != first_layer.index) {\n\t\t\t\tmocode.layer.unselectAllProperties(layers[i]);\n\t\t\t\tfor (var n = 0; n < paths.length; n++) {\n\t\t\t\t\tvar new_prop = mocode.lib.getPropertyWithPath(paths[n], layers[i], null, false);\n\t\t\t\t\tif (new_prop) new_prop.selected = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}","name":"Select same properties in all layers","documentation":"Find all selected properties of the first selected layer, and select all these properties on the other selected layers.","last_update":1574152084347},{"_id":"remote-Syntax-Demo-1565361661580","code":"var number = _number: Number of duplications_;\r\n\r\nvar string = _string *: Suffix_;\r\n\r\nvar colors = _color - [0, Infinity]: Color Palette_;\r\n\r\nvar layers = _layer * -2: Select two layers_;\r\n\r\nvar properties = _property * -[2, 10]: Select at least two properties_;\r\n\r\nvar bool = _bool: Activate ? _;","name":"Syntax Demo","documentation":"Open Visual Mode to understand the syntax.\n\nLearn more about MoCode syntax in the documentation...","tags":["demo"],"last_update":1571846520175}]}]