extendscript after effects if else statement how do i fix this up - extendscript

this is my code the else statement is not firing well.
just test it if you can type in any effect and name it. I am trying to get the else statement to work check=false so that I can add my other action code to it.
var effectNameCollection = app.effects;
var check = false;
for (var i = 0; i < effectNameCollection.length; i++) {
var name = effectNameCollection[i].displayName;
if (name == "Color Matcher") {
check = true;
alert ("INSTALLED");
}else{
alert ("not installed");
}
}

I'm not entirely sure what your question is. But I will happily lend some advice. First of all, you likely don't want to have your alert code to be inside of the the for-loop. The way you have it now, it will fire an alert on every loop. I have 428 effects installed on my After-Effects, so that is a lot of alerts!
var effectNameCollection = app.effects;
var check = false;
for (var i = 0; i < effectNameCollection.length; i++) {
var name = effectNameCollection[i].displayName;
$.writeln(name);
if (name == "Color Matcher") {
check = true;
}
}
var chckAlert = check ? "INSTALLED" : "not installed";
alert(chckAlert);
The code above will log all of your installed effects to the terminal using $.writeln (extendscript's version of a console.log) and then will alert you if an effect with the name of 'Color Matcher' is installed.
The line:
var chckAlert = check ? "INSTALLED" : "not installed";
is just a condensed version of an if-else statement and is equivalent to:
var chckAlert = '';
if (check) {
chckAlert = "INSTALLED";
} else {
chckAlert = "not installed";`
}

Related

Unable to delete Mutiple Comp from listbox with Extendscript

I can't perform multiple delette from my listbox although I made the listbox mutiselect Why ??
I need your help . You can see the full Script down there.
(function(){
$.win = new Window("palette");
var win = $.win;
win.orientation = "column";
win.alignChildren = ["center", "top"];
win.spacing = 10;
win.margins = 16;
var listbox1 = win.add("listbox", undefined, undefined, { name: "listbox1", multiselect: true, columnTitles: "Max", showHeaders: true });
listbox1.preferredSize.width = 136;
listbox1.preferredSize.height = 208;
var button1 = win.add("button", undefined, undefined, { name: "button1" });
button1.text = "Search";
var button2 = win.add("button", undefined, undefined, { name: "button2" });
button2.text = "Delete";
win.show();
var myNewArray = [];
button1.onClick = function Search() {
var compsArray = new Array();
var myProj = app.project;
myNewArray = [];
listbox1.removeAll();
for (var i = 1; i <= myProj.numItems; i++) {
if (myProj.item(i) instanceof CompItem) {
myNewArray = compsArray[compsArray.length] = myProj.item(i);
listbox1.add("item", myNewArray.name);
}
}
}
button2.onClick = function deletecomps() {
for (var s = 1; s <= app.project.numItems; s ++) {
if ((app.project.item(s) instanceof CompItem) && (app.project.item(s).name.match(listbox1.selection))) {
myComp = app.project.item(s);
break;
}
}
app.project.item(s).remove ();
}
})();
You can see an image to clarify the script in AE
Your problem is that listbox1.selection in line 34
if ((app.project.item(s) instanceof CompItem) && (app.project.item(s).name.match(listbox1.selection))) {
is an array, and you're trying to match it to a string returned by app.project.item(s).name which is never going to match.
Also, what are you trying to achieve with the lines
myComp = app.project.item(s);
break;
Here's the onClick function, but it works. It loops through the selection, and looks for a matching project item, based on the text of the listbox matching the comp's name. This is dangerous, because identical comp names would create false positives. I strongly suggest you don't use this technique in production code, because it will definitely cause problems for your users.
Also I'd turn the part wherre you populate the list into a separate function, and call it after you click delete, so that the list is refreshed, because at the moment the list stays the same, even after the comp is deleted.
button2.onClick = function deletecomps() {
for (var b= 0; b < listbox1.selection.length; b++){
for (var s = 1; s <= app.project.numItems; s ++) {
if ((app.project.item(s) instanceof CompItem) && (app.project.item(s).name.match(listbox1.selection[b].text))) {
app.project.item(s).remove ();
}
}
}
}

Else Statement Does Not Stop Looping NodeJS

I have been working on this code to read through a PDF file and grab the keywords of company names and display them. It all works fine except for one part where the else if statement outputs one line (which is what I want) but the else statement that comes last, which is supposed to output "Not Found" loops 20 times where I only want it to display the output only once instead of 20 times.
I have tried numerous ways by going through the internet to change my code, most recommended that forEach is not a proper way to do things and that I should use for instead but when I do, I just can't seem to get it right.
l.forEach(function(element) {
var j = element['fullTextAnnotation']['text'];
var sd = 'SDN. BHD.';
var bd = 'BHD.';
var et = 'Enterprise';
var inc = 'Incorporated';
var regtoken = new natural.RegexpTokenizer({pattern:/\n/});
var f = regtoken.tokenize(jsondata);
for(o = 0 ; o < f.length; o++){
var arrayline1 = natural.LevenshteinDistance(sd,f[o],{search:true});
var arrayline2 = natural.LevenshteinDistance(bd,f[o],{search:true});
var arrayline3 = natural.LevenshteinDistance(et,f[o],{search:true});
var arrayline4 = natural.LevenshteinDistance(inc,f[o],{search:true});
var arrayline5 = natural.LevenshteinDistance(nf,f[o],{search:false});
var onedata1 = arrayline1['substring'];
var onedata2 = arrayline2['substring'];
var onedata3 = arrayline3['substring'];
var onedata4 = arrayline4['substring'];
var onedata5 = arrayline5['substring'];
if (onedata1 === sd)
{
tokends = f[o];
break;
} else if(onedata3 === et)
{
tokends = f[o];
break;
} else if(onedata2 === bd)
{
tokends = f[o];
console.log(tokends);
break;
} else if(onedata4 === inc)
{
tokends = f[o];
console.log(tokends);
break;
} else{
console.log("Not Found");
return false;
}
}
});
I wish to get only one "Not Found" output for the else statement rather than it looping it for 20 times over. Hopefully I could get some insight to this problem. Thank you.
You are actually using the .forEach Array's method which actually take a function in parameter.
The keywork return breaks actually the loop of the current function executed.
For example :
const data = ['Toto', 'Tata', 'Titi'];
data.forEach(function(element) {
console.log(element);
if (element === 'Tata') {
return false;
}
});
// Will print everything :
// Print Toto
// Print Tata
// Print Titi
for (let element of data) {
console.log(element);
if (element === 'Tata') {
return false;
}
}
// Will print :
// Print Toto
// Print Tata

How to return scrollbar in Sharepoint 2010

I want to fix scrollbar in popUp window,but unfortunately fix it in my other pages!
Please,tell me- how to return scrollbars in Sharepoint 2010.
When i want to fix scrolls- use :
function FixRibbonAndWorkspaceDimensions() {
ULSxSy:;
g_frl = true;
var elmRibbon = GetCachedElement("s4-ribbonrow");
var elmWorkspace = GetCachedElement("s4-workspace");
var elmTitleArea = GetCachedElement("s4-titlerow");
var elmBodyTable = GetCachedElement("s4-bodyContainer");
if (!elmRibbon || !elmWorkspace || !elmBodyTable) { return; }
if (!g_setWidthInited) {
var setWidth = true;
if (elmWorkspace.className.indexOf("s4-nosetwidth") > -1)
setWidth = false;
g_setWidth = setWidth;
g_setWidthInited = true;
}
else { var setWidth = g_setWidth; }
var baseRibbonHeight = RibbonIsMinimized() ? 44 : 135;
var ribbonHeight = baseRibbonHeight + g_wpadderHeight;
if (GetCurrentEltStyle(elmRibbon, "visibility") == "hidden") { ribbonHeight = 0; }
// Override default resizing behavior
// -- adds padding to the top of the "s4-workspace" <div> if the ribbon exists and has content
// -- allows the ribbon to be positioned using CSS instead of JavaScript (more accessible)
// -- checks to see if the page is inside a "no-ribbon" dialog
var elmRibbonContainer = GetCachedElement("RibbonContainer");
if (elmRibbonContainer != null) {
if (elmRibbonContainer.children.length > 0 && document.getElementsByTagName("html")[0].className.indexOf('ms-dialog-nr') == -1) {
elmWorkspace.style.paddingTop = ribbonHeight + 'px';
}
}
}
i think ,that i have to write

Dropdown field - first item should be blank - For more than one field (Sharepoint)

I was looking for a solution to the problem of getting a blank default when using a lookup in a field in Sharepoint. Kit Menke's solution to "Dropdown field - first item should be blank" question works perfectly for my first field with a lookup. But I can't make it work if have more that one field in the same list where I need to insert a blank for each lookup field (works only for the first field). I tried adding a new "Web Part" and applying the same code to the second field, but doesn't work. Any ideas? Thanks in advance
Follow-up to my answer here: Dropdown field - first item should be blank
Version 2.0 allows you to add the names of your dropdowns to dropdownNames in the MyCustomExecuteFunction function. As with the first one, this will work only with required single select lookup fields. Also, in order to edit the page again and update your Content Editor Web Part you may have to choose a value for your dropdowns otherwise you get the dreaded An unexpected error has occurred.. Good luck! :D
<script type="text/javascript">
function GetDropdownByTitle(title) {
var dropdowns = document.getElementsByTagName('select');
for (var i = 0; i < dropdowns.length; i++) {
if (dropdowns[i].title === title) {
return dropdowns[i];
}
}
return null;
}
function GetOKButtons() {
var inputs = document.getElementsByTagName('input');
var len = inputs.length;
var okButtons = [];
for (var i = 0; i < len; i++) {
if (inputs[i].type && inputs[i].type.toLowerCase() === 'button' &&
inputs[i].id && inputs[i].id.indexOf('diidIOSaveItem') >= 0) {
okButtons.push(inputs[i]);
}
}
return okButtons;
}
function AddValueToDropdown(oDropdown, text, value, optionnumber){
var options = oDropdown.options;
var option = document.createElement('OPTION');
option.appendChild(document.createTextNode(text));
option.setAttribute('value',value);
if (typeof(optionnumber) == 'number' && options[optionnumber]) {
oDropdown.insertBefore(option,options[optionnumber]);
}
else {
oDropdown.appendChild(option);
}
oDropdown.options.selectedIndex = 0;
}
function WrapClickEvent(element, newFunction) {
var clickFunc = element.onclick;
element.onclick = function(event){
if (newFunction()) {
clickFunc();
}
};
}
function MyCustomExecuteFunction() {
// **** ADD YOUR REQUIRED SINGLE SELECT FIELDS HERE ***
var dropdownNames = [
'Large Lookup Field',
'My Dropdown Field'
];
var dropdownElements = [];
for (var d = 0; d < dropdownNames.length; d++) {
// find the dropdown
var dropdown = GetDropdownByTitle(dropdownNames[d]);
// comment this IF block out if you don't want an error displayed
// when the dropdown can't be found
if (null === dropdown) {
alert('Unable to get dropdown named ' + dropdownNames[d]);
continue;
}
AddValueToDropdown(dropdown, '', '', 0);
// collect all of our dropdowns
dropdownElements.push(dropdown);
}
// add a custom validate function to the page
var funcValidate = function() {
var isValid = true;
var message = "";
for (var d = 0; d < dropdownElements.length; d++) {
if (0 === dropdownElements[d].selectedIndex) {
// require a selection other than the first item (our blank value)
if (isValid) {
isValid = false;
} else {
message += "\n"; // already had one error so we need another line
}
message += "Please choose a value for " + dropdownNames[d] + ".";
}
}
if (!isValid) {
alert(message);
}
return isValid;
};
var okButtons = GetOKButtons();
for (var b = 0; b < okButtons.length; b++) {
WrapClickEvent(okButtons[b], funcValidate);
}
}
_spBodyOnLoadFunctionNames.push("MyCustomExecuteFunction");
</script>
How about prepending a null option to the select menu of sharepoint.Like,
$('#idOfSelectMenu').prepend('<option value="" selected>(None)</option>');
I used this approach and append this code only in the NewForm.aspx because in EditForm.aspx it will override the selected option.

Sharepoint Blog Category view - Pagination issue

Folks, I am facing a rather strange issue. In my Sharepoint Blog, I am not able to view more than 10 posts when I click on the Category filter page.
The page only shows the latest 10 posts and when I click on the pagination for the next 10, it simply says that "There are no posts in this category." I tried searching online and some one had a solution to it too, but that is with the Query String (URL) Filter which is not available in MOSS2007 Standard edition...
How can I get around this? Any help would be greatly appreciated...
I found the solution on the net for the Sharepoint Blog Category Pagination issue... and it works for me. Thanks to this blog
All you need to do is copy paste the following script. Go to the blog/category/Category.aspx and add a Content Editior Web Part. Then go to Source Editor and Copy Paste the following CODE.
You can also make sure to HIDE the Webpart so that its not visible / annoying to others by ticking Hidden under Layout option.
<script language ="javascript" type = "text/javascript" >
function changeLink(){
JSRequest.EnsureSetup();
var Category = JSRequest.QueryString["Name"];
var parent;
var child;
for (var counter =0; counter < 100; counter++){
var elementId = 'bottomPagingCellWPQ'+ counter;
if (document.getElementById(elementId)){
parent = document.getElementById(elementId);
child = parent.childNodes[0].childNodes[0].childNodes[0];
if (child.childNodes.length > 0){
for (var y = 0; y < child.childNodes.length; y++ ){
if(child.childNodes[y].childNodes){
if(child.childNodes[y].childNodes[0].tagName){
theAnchorTag = child.childNodes[y].childNodes[0];
for( var x = 0; x < theAnchorTag.attributes.length; x++ ){
if( theAnchorTag.attributes[x].nodeName.toLowerCase() == 'onclick' ){
var str = theAnchorTag.attributes[x].nodeValue;
str = str.replace( '?', '?Name=' + Category + '\\u0026');
theAnchorTag.attributes[x].nodeValue = str;
onclk = theAnchorTag.attributes[x].nodeValue;
theAnchorTag.onclick = new Function(onclk);
}
}
}
}
}
}
break;
}
}
}
addLoadEvent(changeLink);
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else{
window.onload = function(){
if (oldonload) {oldonload();}
func();}
}
}
</script>

Resources