Copy link to clipboard
Copied
I have been having a persistent issue that I have only just been able to reproduce with simple enough code to post. What I am finding is that check marks in list items do not show up if there was a dialog box immediately preceding them (I am running Mac OS and have not tested on Windows yet)
file = File.openDialog();
var w = new Window('dialog', undefined, undefined, {
resizeable: true
});
var myList = w.add ('listbox');
myList.preferredSize = [300, 400];
var item;
for (var i = 0; i < 200; i ++) {
item = myList.add('Item', i);
item.checked = true;
}
w.onResizing = w.onResize = function() {
this.layout.resize();
}
w.show ();
If I click in the list box, scroll or resize the window the items redraw and the check boxes all of a sudden appear!
If anybody can think of some ideas to fix this I would appreciate the help.
Copy link to clipboard
Copied
Hi McShaman,
Probably will not help you but maybe some new horizon will be uncovered for you.
I tried to make one script with icons in list box and everything works fine to CC 2014 then I started to looking for answers for the same question as you.
So one of most fitting answer I found was
"Refresh" listbox to show array images
but it was on the time before CC 2015. When CC 2015 been published my script with icons start works...but on windows platform only, but didnt give up and then found this: Re: UI panel and document CS4
it rendering ikons on every platform and every version. maybe it will help you somehow.
I know you can think you have checkboxes not icons/images.
It doesn't matter. I thought maybe colorful icons rendering is much more time taking and made tests with checkboxes instead and had exactly the same result - the same as you have.
My conclusion is all graphics (think checkbox is graphic as well) should be rendered somehow with ScriptUIGraphics, but I dont know how. Whatever I tried to do gave me the same result.
What I did was make listbox with another column where displaying texts "ok" and "x" as a condition in your case it could correspond to checked and unchecked.
cheers
pav
Copy link to clipboard
Copied
Works fine on Windows (Windows 10 and CC2015). Maybe if you rattle the list box a bit you might solve that. See http://www.kahrel.plus.com/indesign/scriptui.html, p. 43.
Copy link to clipboard
Copied
peter,
if you'll have a time and will be interested with this issue I think if you'll defined window as a palette then you'll get exactly the same behaviour on win, cant check it now but think it will works (not works )
btw. many thanks for your's scriptui publication...it giving a lot of light and saving lot of time. it was mine primary book as well as your's extendscript book for all my experiences in InDesign scripting.
Copy link to clipboard
Copied
As I said, pav, it works fine on Windows, palette or dialog.
Glad to hear that those titles are of some use!
P.
Copy link to clipboard
Copied
Im stuck on this as well now
Im never was a coder and just wanted to slicken my amount of work here and there, so I became a tiny bit able to puzzle code snippets together, alter strings, and sometimes even get a slick script afterwards. After Loic flashed out a sample helping me out nearly a year ago, im still not able to get the script done by myself, because its too good to understand with my little background.
The first versions were watching the onChange event and refreshed the window with getLinks after that, causing the script to be very slow on our 500+links-docs. So I bypassed this solution by adding a onDoubleClick to my listbox-items, which sets the checked-status. Everything fell in place, i was quite happy finally getting this finished…
But then I came to this:
The first screenshot shows the listbox, when I take my time and scroll it slow.
The next screenshots are the exact state, only difference I used the mousewheel to scroll down/up quickly, nothing unusual.
Were still on CC2018 because of our DAM(N)-Plugin, but I also tested this in current CC2019. While doing this I noticed an bug in CC18 (I cant use the mousewheel to get to the top, i always end up listitem[0] being not scrolled to, unless I use the scrollbar), but that one is gone in CC19.
With this window behaving so clunky, I cant roll out that script to my colleagues.
Has anyone any ideas to get this script on track and kind of usable?
Heres what Ive got so far, dont be mean – it doesnt win a beauty contest.
What you need to populate the list is an open document with ~10 images which are flipped. To make the list show something, you have to click on "Gespiegelte Bilder" (=Mirrored Images). If someone can fix that "Cumulus-Check" (radio1) is selected by default upon use with the list showing, would be great also.
#targetengine 'session13'
var ProgrammName = "Image Checker"; myVersion = "0.3.190314"
var maxlinks, currentlinks,mySel,FilterFlag;
app.scriptPreferences.enableRedraw = true;
FilterFlag = 1; ZoomFactor = 8;
function sortByKey(array, key) {
return array.sort(function(b, a) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
//Main routine
var main = function() {
var doc = app.properties.activeDocument,dlg, linksData, n,
callback;
if ( !doc ) return;
this.dlg = this.dlg || ui();
this.dlg.show();
}
//Retrieve doc links
function getLinks(){
const uris = [
"srvmar16\.zentrale\.ad\.local",
"192\.168\.96\.116"];
var ls, n = 0, l, o = {}, lid,
doc = app.properties.activeDocument, reg;
if ( !doc ) return o;
reg = new RegExp( "("+uris.join("|")+")", "i" );
ls = doc.links.everyItem().getElements();
maxlinks = ls.length;
currentlinks = ls.length;
n = ls.length; maxlinks = n;
sortByKey(ls, "name");
while ( n-- ) {
l = ls
; if (FilterFlag == 1)
{if (reg.test(l.filePath) ) continue; }
else
{if (l.parent.flip == Flip.NONE) continue;}
try {
Ort = l.parent.parentPage.name;
} catch(err) {Ort = "MF"};
lid = l.id;
o[lid] = {name:l.name, id:lid, container:l.parent.parent,onPage:Ort};
}
currentlinks = o.__count__;
return o;
}
//UI build function
var ui = function (){
var u,
w = new Window('palette', ProgrammName+"["+$.engineName+"]"),
grp0 = w.add('group'),
panel0 = grp0.add('panel', [0,0,200,70], "Überprüfen", {borderStyle:'black'}),
grp9 = panel0.add('group'),
//t_0 = grp9.add('statictext', undefined, "Überprüfen:"),
grp1 = grp9.add('group'),
radio1 = grp1.add('radiobutton', undefined, "Cumulus-Check"), radio2 = grp1.add ('radiobutton', undefined, "Gespiegelte Bilder"),
panel1 = grp0.add('panel', [0,0,320,70], "Optionen", {borderStyle:'black'}),
rower = panel1.add('group'),
checkboxgrp1 = rower.add('group'),
check1 = checkboxgrp1.add ("checkbox", undefined, "Zoomen"),
check2 = checkboxgrp1.add ("checkbox", undefined, "Suffix ignorieren"),
checkboxgrp2 = rower.add('group'),
check3 = checkboxgrp2.add ("checkbox", undefined, "Kopie ignorieren"),
check4 = checkboxgrp2.add ("checkbox", undefined, "<Platzhalter>"),
ls = w.add('listbox',undefined,undefined,{selection: mySel, numberOfColumns: 2, showHeaders: true, columnTitles: ["Seite", "Name"]}),
grp = w.add('group'),
pbar = grp.add ('progressbar', undefined, 0, maxlinks),
t1 = grp.add ('statictext', undefined, "999/999 ➜ 100 %"),
bgrp = w.add('group'),
btn1 = bgrp.add('button',u,"Refresh"),
btn2 = bgrp.add('button',u,"Schließen"),
linkItem, listItem,
updateLinksList = function() {
var data, linkData, listItem;
ls.removeAll();
data = getLinks();
if (FilterFlag == 1) {radio1.value = true;} else {radio2.value = true;}
t1.text = ""+currentlinks+ "/"+maxlinks+" ➜ "+Math.round((100 - (((100 / maxlinks) * currentlinks))))+" %";
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
w.update();
if ( !data.__count__ ) return;
currentlinks = ( data.__count__ );
for ( prop in data ) {
linkData = data[prop];
listItem = ls.add('item', linkData.onPage);
listItem.checked = false;
listItem.subItems[0].text = linkData.name;
listItem.data = linkData;
};
}, ev = app.eventListeners.itemByName ( "onSelectionChanged" );
w.alignChildren = ["fill","fill"];
grp1.orientation = "column";
checkboxgrp1.orientation = "column";
checkboxgrp1.alignChildren = "left";
checkboxgrp2.orientation = "column";
checkboxgrp2.alignChildren = "left";
grp1.alignChildren = ["fill","fill"];
grp0.alignChildren = "top";
grp9.alignChildren = "top";
panel0.alignChildren = "left";
rower.alignChildren = ["row","top"];
grp1.borderStyle = "white";
grp.alignChildren = ["fill","fill"];
bgrp.alignChildren = ["fill","fill"];
ls.preferredSize = [300,200];
ls.maximumSize.height = 300;
pbar.preferredSize = [400,2];
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
t1.characters = 16;
t1.justify = "right";
radio1.value = true;
check1.value = true;
check2.value = true;
check3.value = false;
check3.value = false;
btn2.onClick = function(){w.close(0)};
btn1.onClick = function(){alert("work in progress "+FilterFlag)
updateLinksList();
w.update()
};
radio1.onClick = function(){
FilterFlag = 1;
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
updateLinksList();
w.update()
};
radio2.onClick = function() {
FilterFlag = 2;
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
updateLinksList();
w.update()
};
ls.onDoubleClick = function() {
if (ls.items[ls.selection.index].checked == true) {ls.items[ls.selection.index].checked = undefined;} else {ls.items[ls.selection.index].checked = true;}
};
ls.onChange = function() {
if ( !ls.selection ) return;
mySel = ls.selection;
t1.text = ""+currentlinks+ "/"+maxlinks+" ➜ "+Math.round((100 - (((100 / maxlinks) * currentlinks))))+" %";
if (check1.value == true)
{zoomObject ( ls.selection.data.container , ZoomFactor,)} else
{zoomObject ( ls.selection.data.container , 0,)};
if (check3.value == false)
{
if (check2.value == true) {SetClipboard ( ls.selection.data.name.replace ( /\.[a-z]+$/i, '') );} else {SetClipboard ( ls.selection.data.name)};
}
}
w.onShow = function(){
//updateLinksList();
}
if ( !ev.isValid ) {
app.eventListeners.add("afterSelectionChanged",function(evt){
//updateLinksList();
t1.text = ""+currentlinks+ "/"+maxlinks+" ➜ "+Math.round((100 - (((100 / maxlinks) * currentlinks))))+" %";
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
});
}
return w;
};
//Created by Dave Saunders > http://jsid.blogspot.fr/2006/01/zoom-in-on-object.html
function zoomObject(theObj, theRatio) {
try {
var objBounds = theObj.geometricBounds;
} catch (e) {
throw "Objekt hat keine Abmessungen."
}
var ObjHeight = objBounds[2] - objBounds[0];
var ObjWidth = objBounds[3] - objBounds[1];
var myWindow = app.activeWindow;
var pageBounds = myWindow.activePage.bounds;
var PgeHeight = pageBounds[2] - pageBounds[0];
var PgeWidth = pageBounds[3] - pageBounds[1];
var hRatio = PgeHeight/ObjHeight;
var wRatio = PgeWidth/ObjWidth;
var zoomRatio = Math.min(hRatio, wRatio);
var OldZoomVal;
app.select(theObj); // to make active the page that holds theObj
if (theRatio != 0) {
myWindow.zoom(ZoomOptions.fitPage);
myWindow.zoomPercentage = myWindow.zoomPercentage * theRatio; // * zoomRatio;
} else {
OldZoomVal = myWindow.zoomPercentage;
myWindow.zoom(ZoomOptions.fitPage);
myWindow.zoomPercentage = OldZoomVal;
} }
//See here for reference :
//https://forums.adobe.com/thread/2203330
function SetClipboard(clip){
var clipboard;
if(File.fs == "Macintosh"){
app.doScript ('tell application "Finder" to set the clipboard to "'+clip+'"',ScriptLanguage.APPLESCRIPT_LANGUAGE);
} else {
app.doScript ( 'Dim theObject\r Set theObject = CreateObject (\"htmlfile\")\r Call theObject.ParentWindow.ClipboardData.SetData(\"text\",\"'+clip+'\")', ScriptLanguage.visualBasic );
}
return;
}
main();