Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General
Moderators: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators
by lukasz » Mon Oct 10, 2011 8:56 pm
for some reason I cannot get the index of the selected layer. having a brain fart.
trying to turn off visibility of selected layer then turn on visibility next layer and have next layer also be active layer.
- Code: Select all
var currentLayer = app.activeDocument.activeLayer.length;
var activelayer = app.activeDocument.activeLayer;
activelayer.visible = false;
var nextLayer = currentLayer-1;
nextLayer.visible = true;
app.activeDocument.activeLayer = nextLayer;
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
by txuku » Tue Oct 11, 2011 9:32 am
Bonjour lukasz
I think this corresponds to what you seek :
- Code: Select all
var doc = app.activeDocument;
var currentLayer = doc.activeLayer;
for(i=0; i < doc.layers.length; )
{
if(doc.layers[i]==currentLayer)
{
a=i;
//alert(a);
i = doc.layers.length;
}
else{ i++; }
}
currentLayer.visible = false;
try
{
var nextLayer = doc.layers[a-1];
}
catch(e)
{
var nextLayer = doc.layers[doc.layers.length-1];
}
nextLayer.visible = true;
doc.activeLayer = nextLayer;
-
txuku
-
- Posts: 314
- Joined: Tue Apr 15, 2008 2:15 pm
- Location: France - Pays Basque
by lukasz » Tue Oct 11, 2011 3:40 pm
that worked perfect. one more issue though.
documentation says index is method of layers, but I can't seem to select via the index. any idea whats going on?
- Code: Select all
var newActivelayer = doc.layers.index(1);
Last edited by
lukasz on Tue Oct 11, 2011 5:56 pm, edited 1 time in total.
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
by larsen67 » Tue Oct 11, 2011 5:45 pm
Not like that…
- Code: Select all
app.activeDocument.activeLayer = app.activeDocument.layers[1];
Index inside of a square bracket pair…
-
larsen67
-
- Posts: 429
- Joined: Sat Apr 25, 2009 3:01 pm
- Location: Pickmere, Cheshire UK
by lukasz » Wed Oct 12, 2011 1:01 pm
doh, ok works get thanks!
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
by lukasz » Wed Oct 12, 2011 2:01 pm
still a little hiccup. doesnt seem to want to select next layer, however it does make it visible? which seems weird because it makes it visible after it selects the layer in the code, or should? but in the document the next layer is not selected.
- Code: Select all
#target illustrator
var activelayer = app.activeDocument.activeLayer;
activelayer.visible = false;
for(i=0; i < doc.layers.length; )
{
if(doc.layers[i]==activelayer)
{
var a = i;
alert(a);
var i = doc.layers.length;
var b = a+1;
}
else{ i++; }
}
app.activeDocument.activeLayer = app.activeDocument.layers[b];
var activelayer = app.activeDocument.activeLayer;
activelayer.visible = true;
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
by larsen67 » Wed Oct 12, 2011 3:06 pm
#target illustrator
Sorry but you can't expect the syntax of Photoshop to work with Illustrator… While there are common objects like app & doc little else will work… In PS layers can exist inside a doc or layer set… In Illustrator they can exist anywhere… other layers, groups, etc… this needs to be scripted as per the Illustrator DOM…
-
larsen67
-
- Posts: 429
- Joined: Sat Apr 25, 2009 3:01 pm
- Location: Pickmere, Cheshire UK
by lukasz » Wed Oct 12, 2011 3:51 pm
hmmm, interesting. I understand not all of it will work. but usually the core dom is the same, they do handle layers differently though. i will look into that.
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
by Mike Hale » Wed Oct 12, 2011 5:03 pm
lukasz wrote:but usually the core dom is the same
It has been my experience that the core javascript is the same, but the DOM's for each Adobe app have little if anything in common.
-
Mike Hale
- Site Admin
-
- Posts: 4067
- Joined: Fri Sep 30, 2005 10:52 pm
- Location: USA
-
by larsen67 » Wed Oct 12, 2011 9:07 pm
Try getting the name of your active layer… You will see it's the one you wanted it's just a lazy UI that does not redraw as you would expect… Even app.redraw() will not refresh this for you…
-
larsen67
-
- Posts: 429
- Joined: Sat Apr 25, 2009 3:01 pm
- Location: Pickmere, Cheshire UK
by lukasz » Mon Oct 17, 2011 1:20 pm
larsen67 wrote:Try getting the name of your active layer… You will see it's the one you wanted it's just a lazy UI that does not redraw as you would expect… Even app.redraw() will not refresh this for you…
not sure I understand what you're saying?
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
by lukasz » Mon Oct 17, 2011 3:44 pm
still not sure what you meant by lazy UI hah, but decided to add the redraw(); method and it seems to fix it? really strange. why do you have to apply this in order to set an active layer? seems like the UI would do it sometimes, and other times it didn't. but now it is consistant. it's the worst when I am doing several things in succession, if it is only selecting active layer and that is all script does, it seems to work fine. very strange.
-
lukasz
-
- Posts: 100
- Joined: Fri Oct 16, 2009 10:32 am
Return to Photoshop Scripting - General Discussion
Who is online
Users browsing this forum: Google [Bot] and 2 guests