[READ-ONLY] Mirror of https://github.com/probablykasper/2dcam. After Effects 2d camera
after-effects camera extendscript script
0

Configure Feed

Select the types of activity you want to include in your feed.

Stopped using resource strings

Kasper (Mar 9, 2020, 11:33 PM +0100) e5d1f73d 9eee19b9

+163 -85
+163 -85
2dcam.jsx
··· 5 5 camera: "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\x1A\x00\x00\x00\x1A\b\x06\x00\x00\x00\u00A9JL\u00CE\x00\x00\x01\u0082iCCPsRGB IEC61966-2.1\x00\x00(\u0091u\u0091\u00CBKBA\x14\u0087?5)\u00CA0(\u00A2E\x0B\tkea\x05Q\x04AJX !f\u00D0k\u00A37\x1F\u0081\u00DA\u00E5^#\u00A4m\u00D0V(\u0088\u00DA\u00F4Z\u00D4_P\u00DB\u00A0u\x10\x14E\x10\u00ADZ\u00B4.jSr;7\x05%\u00F2\fg\u00CE7\u00BF\u0099s\u00989\x03\u00D6HZ\u00C9\u00E8u^\u00C8dsZ8\u00E0s\u00CD\u00CD/\u00B8\u00EA_\u00B0\u00D1@;vF\u00A3\u008A\u00AE\u008E\u0087BAj\u00DA\u00E7=\x163\u00DE\u00F6\u009A\u00B5j\u009F\u00FB\u00D7\u009A\u0096\u00E3\u00BA\x02\u0096\x06\u00E11E\u00D5r\u00C2\u0093\u00C2\u00C1\u00F5\u009Cj\u00F2\u008Ep\u009B\u0092\u008A.\x0B\u009F\t{4\u00B9\u00A0\u00F0\u009D\u00A9\u00C7J\u00FCjr\u00B2\u00C4\u00DF&k\u0091\u00B0\x1F\u00AC-\u00C2\u00AEd\x15\u00C7\u00AAXIi\x19ay9\u00EELzM)\u00DF\u00C7|\u0089#\u009E\u009D\u009D\u0091\u00D8%\u00DE\u0089N\u0098\x00>\\L1\u0081\u009F!\u00FA\x19\u0091y\u0088^\x06\u00E8\u0093\x155\u00F2\u00BD\u00BF\u00F9\u00D3\u00ACJ\u00AE\"\u00B3J\x1E\u008D\x15\u0092\u00A4\u00C8\u00E1\x11uM\u00AA\u00C7%&D\u008F\u00CBH\u00937\u00FB\u00FF\u00B7\u00AFzbp\u00A0T\u00DD\u00E1\x03\u00FB\u00B3a\u00BCwC\u00FD6\x14\x0B\u0086\u00F1ud\x18\u00C5c\u00B0=\u00C1e\u00B6\u0092\u00BFz\b\u00C3\x1F\u00A2\x17*\u009A\u00FB\x00\u009C\u009Bp~U\u00D1b\u00BBp\u00B1\x05\x1D\u008FjT\u008B\u00FEJ6qk\"\x01o\u00A7\u00D0<\x0F\u00AD7\u00D0\u00B8X\u00EAYy\u009F\u0093\x07\u0088l\u00C8W]\u00C3\u00DE>\u00F4\u00C8y\u00E7\u00D2\x0FHkg\u00D8X\u00BD\u00A4\u00BC\x00\x00\x00\tpHYs\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\u009A\u009C\x18\x00\x00\x00\u0081IDATH\u0089\u00ED\u0094;\x12\u00C3 \f\x05\u00F52\u00E3\x1B\u0085>\u0097\u00F2\u00F9 '\u00DB4\u00A10\u00B6\x07\f1i\u00B4\u00A5\x10Z\r\x1F\u00999\u00CE_\x00\x02\u0090\x18#\x01\u00A1&J\u00C0\n,\u009D\u008D.\u00DF\u00FD\u00B1\u0096H\u00AF\u00A4\u0090Q\u00C4^@\u00DA\u0088F$e\u009D,\u00C8gz\u008B\u00E8\u00E8\u00AE\u00CD\u00CC\u0094\x13$\u00E9\x17\u00A2\u00A3\u00B8$=F\u008B\u00B7\u00E2\u00A2\x16\u00DE\u00A7+S\u009F\u00F7\u00AC\x0F;m\x04\x05 ^\x1A\u00A1{\"\u00F0\u00ECi\u00D4q\u00EE\u00E1\x03?\u009D8B\u00C4\u00BC<\u00F7\x00\x00\x00\x00IEND\u00AEB`\u0082", 6 6 } 7 7 8 - res = 'group{ \ 9 - orientation:"row",\ 10 - newCamButton: IconButton{ \ 11 - properties: {style:"toolbutton"}, \ 12 - preferredSize: [30, 30], \ 13 - helpTip: "New 2dCam\\nAlt+click: New 2dCam and output comp", \ 14 - }, \ 15 - newOutputButton: IconButton{ \ 16 - properties: {style:"toolbutton"}, \ 17 - preferredSize: [30, 30], \ 18 - helpTip: "New 2dCam output comp\\nAlt+click: Apply 2dCam output to the selected layer" \ 19 - }, \ 20 - }'; 21 - win.grp = win.add(res); 8 + Object.prototype.addc = function(name, options) { 9 + options = options || {}; 10 + var bounds = options.bounds; 11 + var properties = options.properties; 22 12 23 - win.grp.newCamButton.image = ScriptUI.newImage(icons.camera); 24 - // win.grp.newCamButton.image = ScriptUI.newImage('./icons/camera.png'); 25 - win.grp.newOutputButton.image = ScriptUI.newImage(icons.screen); 26 - // win.grp.newOutputButton.image = ScriptUI.newImage('./icons/screen.png'); 13 + var noArg2 = false; 14 + var arg2 = options.text; 15 + if (name == 'dropdownlist' || name == 'listbox' || name == 'treeview') { 16 + arg2 = options.items; 17 + } else if (name == 'iconbutton' || name == 'image') { 18 + arg2 = options.icon; 19 + } else if (name == 'flashplayer') { 20 + arg2 = options.movieToLoad; 21 + } else if (name == 'group') { 22 + noArg2 = true; 23 + } 24 + 25 + if (noArg2) { 26 + newElement = this.add(name, bounds, properties); 27 + } else if (name == 'progressbar' || name == 'scrollbar' || name == 'slider') { 28 + newElement = this.add(name, bounds, options.value, options.minvalue, options.maxvalue, properties); 29 + } else { 30 + newElement = this.add(name, bounds, arg2, properties); 31 + } 32 + 33 + // set options 34 + for (key in options) { 35 + if (!options.hasOwnProperty(key)) continue; 36 + newElement[key] = options[key]; 37 + } 38 + 39 + return newElement; 40 + } 41 + 42 + var rootGroup = win.addc('group', { 43 + orientation: 'row', 44 + }); 45 + var newCamButton = rootGroup.addc('iconbutton', { 46 + properties: {style: 'toolbutton'}, 47 + icon: icons.camera, 48 + // icon: './icons/camera.png', 49 + preferredSize: [30,30], 50 + helpTip: 'New 2dCam\nAlt+click: New 2dCam and output comp', 51 + }); 52 + var newOutputButton = rootGroup.addc('iconbutton', { 53 + properties: {style: 'toolbutton'}, 54 + icon: icons.screen, 55 + // icon: './icons/screen.png', 56 + preferredSize: [30,30], 57 + helpTip: 'New 2dCam output comp\nAlt+click: Apply 2dCam output to the selected layer', 58 + }); 59 + 60 + var nameFieldWidthChars = 20; 27 61 28 62 function newCamDialog(currentComp, alt, ok) { 29 63 var dialog = new Window("dialog", "New 2dCam", undefined, { resizeable: false }); 30 64 31 - var width = currentComp.width; 32 - var height = currentComp.height; 33 - res = 'group{ \ 34 - orientation:"column", \ 35 - panelGroup: Panel{ \ 36 - orientation:"column", \ 37 - alignChildren:"left", \ 38 - nameGroup: Group{orientation:"row", \ 39 - nameText: StaticText{text:"Name:", justify:"right", preferredSize: [40, 20]}, \ 40 - name: EditText{text:"2dCam", characters:15}, \ 41 - }, \ 42 - widthGroup: Group{ \ 43 - orientation:"row", \ 44 - widthText: StaticText{text:"Width:", justify:"right", preferredSize: [40, 20]},\ 45 - width: EditText{text:"'+width+'", characters:6}, \ 46 - }, \ 47 - heightGroup: Group{ \ 48 - orientation:"row", \ 49 - heightText: StaticText{text:"Height:", justify:"right", preferredSize: [40, 20]}, \ 50 - height: EditText{text:"'+height+'", characters:6}, \ 51 - }, \ 52 - createOutputComp: Checkbox{text:"Create output comp", alignment:"center", value:'+alt+'}, \ 53 - }, \ 54 - buttonsGroup: Group{ \ 55 - orientation:"row", \ 56 - cancelButton: Button{text:"Cancel"}, \ 57 - okButton: Button{text:"OK"}, \ 58 - }, \ 59 - }'; 65 + var defaultWidth = currentComp.width; 66 + var defaultHeight = currentComp.height; 60 67 61 - dialog.grp = dialog.add(res); 62 - dialog.grp.panelGroup.nameGroup.name.active = true; 68 + var dialogRootGroup = dialog.addc('group', { 69 + orientation: 'column', 70 + }); 71 + var nameGroup = dialogRootGroup.addc('group', { 72 + orientation: 'row', 73 + }); 74 + var nameText = nameGroup.addc('statictext', { 75 + text: 'Name:', 76 + justify: 'right', 77 + // preferredSize: [40, 20], 78 + }); 79 + var name = nameGroup.addc('edittext', { 80 + text: '2dCam', 81 + active: true, 82 + characters: nameFieldWidthChars, 83 + }); 84 + var panelGroup = dialogRootGroup.addc('panel', { 85 + // text: 'Options', 86 + minimumSize: [200, 20], 87 + orientation: 'column', 88 + alignChildren: 'left', 89 + }); 90 + var widthGroup = panelGroup.addc('group', { 91 + orientation: 'row', 92 + }); 93 + var widthText = widthGroup.addc('statictext', { 94 + text: 'Width:', 95 + justify: 'right', 96 + preferredSize: [40, 20], 97 + }); 98 + var width = widthGroup.addc('edittext', { 99 + text: defaultWidth, 100 + characters: 6, 101 + }); 102 + var heightGroup = panelGroup.addc('group', { 103 + orientation: 'row', 104 + }); 105 + var heightText = heightGroup.addc('statictext', { 106 + text: 'Height:', 107 + justify: 'right', 108 + preferredSize: [40, 20], 109 + }); 110 + var height = heightGroup.addc('edittext', { 111 + text: defaultHeight, 112 + characters: 6, 113 + }); 114 + var createOutputComp = panelGroup.addc('checkbox', { 115 + text: 'Create output comp', 116 + alignment: 'center', 117 + value: alt, 118 + }); 119 + var buttonsGroup = dialogRootGroup.addc('group', { 120 + orientation: 'row', 121 + }); 122 + var cancelButton = buttonsGroup.addc('button', { 123 + text: 'Cancel', 124 + }); 125 + var okButton = buttonsGroup.addc('button', { 126 + text: 'OK', 127 + }); 63 128 64 - dialog.grp.buttonsGroup.cancelButton.onClick = function() { 129 + cancelButton.onClick = function() { 65 130 dialog.close(); 66 131 } 67 - dialog.grp.buttonsGroup.okButton.onClick = function() { 132 + okButton.onClick = function() { 68 133 var options = { 69 - name: dialog.grp.panelGroup.nameGroup.name.text, 70 - width: dialog.grp.panelGroup.widthGroup.width.text, 71 - height: dialog.grp.panelGroup.heightGroup.height.text, 72 - createOutputComp: dialog.grp.panelGroup.createOutputComp, 134 + name: name.text, 135 + width: width.text, 136 + height: height.text, 137 + createOutputComp: createOutputComp.value, 73 138 }; 74 139 dialog.close(); 75 140 ok(options); ··· 116 181 } 117 182 118 183 // New 2dCam 119 - win.grp.newCamButton.onClick = function() { 184 + newCamButton.onClick = function() { 120 185 var currentComp = app.project.activeItem; 121 186 if (!currentComp) return alert('Please select a comp'); 122 187 ··· 157 222 }); 158 223 } 159 224 160 - function newOutputDialog(ok) { 225 + function newOutputDialog(nonCompLayersSelected, ok) { 161 226 var dialog = new Window("dialog", "New 2dCam", undefined, { resizeable: false }); 162 227 163 - var width = currentComp.width; 164 - var height = currentComp.height; 165 - res = 'group{ \ 166 - orientation:"column", \ 167 - nameGroup: Group{orientation:"row", \ 168 - nameText: StaticText{text:"Name:", justify:"right", preferredSize: [40, 20]}, \ 169 - name: EditText{text:"2dCam", characters:15}, \ 170 - }, \ 171 - buttonsGroup: Group{ \ 172 - orientation:"row", \ 173 - cancelButton: Button{text:"Cancel"}, \ 174 - okButton: Button{text:"OK"}, \ 175 - }, \ 176 - }'; 177 - 178 - dialog.grp = dialog.add(res); 179 - dialog.grp.nameGroup.name.active = true; 228 + var dialogRootGroup = dialog.addc('group', { 229 + orientation: 'column', 230 + }); 231 + var nameGroup = dialogRootGroup.addc('group', { 232 + orientation: 'row', 233 + }); 234 + var nameText = nameGroup.addc('statictext', { 235 + text: 'Name:', 236 + justify: 'right', 237 + preferredSize: [40, 20], 238 + }); 239 + var name = nameGroup.addc('edittext', { 240 + text: '2dCam', 241 + active: true, 242 + characters: nameFieldWidthChars, 243 + }); 244 + var note = dialogRootGroup.addc('statictext', { 245 + text: ' ', 246 + alignment: 'center', 247 + properties: { multiline: true }, 248 + }); 249 + note.graphics.foregroundColor = note.graphics.newPen(note.graphics.PenType.SOLID_COLOR, [1, 0.5, 0.1, 1], 1); 250 + if (nonCompLayersSelected) { 251 + note.text = 'Note: Non-comp layers have been selected, and will be skipped' 252 + } 253 + var buttonsGroup = dialogRootGroup.addc('group', { 254 + orientation: 'row', 255 + }); 256 + var cancelButton = buttonsGroup.addc('button', { 257 + text: 'Cancel', 258 + }); 259 + var okButton = buttonsGroup.addc('button', { 260 + text: 'OK', 261 + }); 180 262 181 - dialog.grp.buttonsGroup.cancelButton.onClick = function() { 263 + cancelButton.onClick = function() { 182 264 dialog.close(); 183 265 } 184 - dialog.grp.buttonsGroup.okButton.onClick = function() { 185 - var name = dialog.grp.nameGroup.name.text; 266 + okButton.onClick = function() { 267 + var finalName = name.text; 186 268 dialog.close(); 187 - ok(dialog.grp.nameGroup.name.text); 269 + ok(finalName); 188 270 } 189 271 190 272 dialog.layout.layout(true); ··· 193 275 } 194 276 195 277 // New output 196 - win.grp.newOutputButton.onClick = function() { 278 + newOutputButton.onClick = function() { 197 279 if (!ScriptUI.environment.keyboardState.altKey) { 198 280 // new output comp 199 281 200 282 var currentComp = app.project.activeItem; 201 283 if (!currentComp) return alert('Please select a comp'); 202 - newOutputDialog(function(name) { 284 + newOutputDialog(false, function(name) { 203 285 app.beginUndoGroup('New 2dCam Output Comp'); 204 286 newOutputComp(name, currentComp); 205 287 app.endUndoGroup(); ··· 231 313 if (!compLayersSelected) { 232 314 return alert('Please select one or more comp layers'); 233 315 } 234 - // if (nonCompLayersSelected) { 235 - // proceed = confirm('Non-comp layers have been selected, and will be skipped. Proceed?'); 236 - // if (!proceed) return; 237 - // } 238 316 239 - newOutputDialog(function(name) { 317 + newOutputDialog(nonCompLayersSelected, function(name) { 240 318 app.beginUndoGroup('Apply 2dCam Output'); 241 319 for (var i = 0; i < outputLayers.length; i++) { 242 320 applyOutputToLayer(name, outputLayers[i]);