CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Object Style to New Layer
Tagged: Layers, object styles
- This topic has 30 replies, 1 voice, and was last updated 3 years, 3 months ago by
lynx.
-
AuthorPosts
-
-
October 8, 2014 at 3:24 pm #70933
Aaron Troia
ParticipantI was wondering if there was a way to move only text boxes with a specific object style to a new layer through out a document, without, of course, doing it all by hand. Or maybe someone already has a script out there that does that and I’m just not running across it.
-
November 5, 2014 at 8:49 pm #71461
Oleh Melnyk
Memberif you still need it – try this script https://www.dropbox.com/s/lrank3o5r5lykph/Move%20TextFrame%20to%20Layer.jsx?dl=0 – it should work
I probably need to start posting my scripts in github))
-
November 7, 2014 at 4:33 pm #71498
Aaron Troia
ParticipantThank you so much Oleh, I’m not working on the projects that I was working on when I first posted, but I know this script will come in handy on future eBook conversions that come my way!
-
May 2, 2018 at 10:38 am #103492
Aaron Gray
ParticipantOleh, this script is a great idea and just what I was looking for. However, I’m having some trouble with it. It works great sometimes, but other times I get a JavaScript Error:
Error Number: 30477
Error String: Invalid value for parameter ‘to’ of method ‘move’. Expected Array of 2 Units, Spread, Page or Layer, but received nothing.
Line: 37
Source: app.activeDocument.textFrames[i].move(app.activeDocument.layers.item(layer));Do you have any idea what could be causing that? I’m using InDesign CC 2014.
Thanks!
Aaron Gray -
May 2, 2018 at 10:58 am #103494
Kai Rübsamen
MemberAaron, Olehs script is working for me. I get only an error, if a object is locked. Can you identify the situation when his script fails? Provide an example?
Kai
-
May 2, 2018 at 1:28 pm #103503
Aaron Gray
ParticipantThanks, Kai. I have an 11-page document with four layers in it: “DataFrame,” “Index,” “Layer 1,” and “Feature Boxes.” I have 10 different object styles in this document including one called “BB18 Index Frame.” I would like to move all the text frames in the document that have the “BB18 Index Frame” onto the “Index” layer, but when I try to do that with the script I get the JavaScript error. I’m also noticing that if I try to move all those objects to other layers, I get inconsistent results—some move and some don’t. I check to make sure that they all really do have the object style and they do, and there are no style overrides. Also, the layers are all unlocked.
-
May 2, 2018 at 1:45 pm #103508
Oleh Melnyk
MemberAaron, do all objects are text frames?
It would be easier if you could share your .indd file -
May 3, 2018 at 12:56 am #103515
Kai Rübsamen
MemberYou get inconsistent results, because the index per spread is messed up when the first frame is moved. Looping backwards will help here:
for(i = app.activeDocument.textFrames.length-1; i >= 0 ; i–)
-
May 3, 2018 at 5:58 am #103516
Aaron Gray
ParticipantThank, Kai. Where/how would I insert that into the code?
Oleh, is there an email address or other location I could send you a file?
Thanks!
-
May 3, 2018 at 6:02 am #103517
Kai Rübsamen
MemberAaron, if you open the script with a Texteditor or the ESTK you will find a line something similar to the new line. Simply change it. But this will maybe not solve your error. Because Oleh write here too, I’m pretty sure, he will correct his script and provide a new download link :)
-
May 3, 2018 at 6:11 am #103518
Aaron Gray
ParticipantHi Kai. I tried what you suggested and it did still return the same error, but I will wait and see if Oleh has any ideas. Thanks!
-
May 3, 2018 at 6:14 am #103519
Aaron Gray
ParticipantOleh, I see now that your email is in the script. I will send you a file. To answer your other question, they are all text frames that have the object style applied.
-
May 3, 2018 at 8:33 am #103520
Oleh Melnyk
MemberOk, this is weird! Looks like the problem is not with the script but with InDesign file, or to be more precise – with the layer name. Looks like “Index” is some sort of reserved word in InDesign, so all you need is to rename a layer, or at least – double-click on the layer name, so “Layer options” dialog opens – once it open, you can close this dialog and script should work ok… – Just try and let me know if it works!
Meanwhile, I made some changes to initial script, so the new version should now work with all objects, not just text frames + now you can undo what script made in just one step.
https://www.dropbox.com/s/uc8vmq878xwh4gf/Move%20Object%20with%20Selected%20ObjectStyle%20to%20Layer.jsx?dl=0 -
May 3, 2018 at 9:46 am #103522
Aaron Gray
ParticipantThanks, Oleh! I renamed the “Index” layer (to just “Layer 2”), and I even renamed the object style for good measure to not have “index” in the name of it, and now I’m no longer getting the JavaScript error.
However, I’m still getting inconsistent results. Whenever I run the script, some frames successfully move to new layers and some don’t, and it’s not always the same ones. I can’t figure out what the pattern is! They are all definitely text frames with the same object style applied to them. One thing I do notice is that it seems to work more consistently when I’m moving objects up in the layer stacking order as opposed to down. When I move them up, they all seem to go up, but when I move them down, some get left behind.
-
May 3, 2018 at 9:56 am #103523
Oleh Melnyk
MemberWell, I have no idea what might cause this problem. In file you sent me – everything works once I rename, or just open and close “Layer options” dialog (all text frames moves to ‘Index’ layer).
Maybe your InDesign file is corrupted?
Have you tried to save it as .idml (for CS4 and later versions), then open this .idml file – this might help to fix some errors.
Have you tried a new script version?
Otherwise, it’s hard to guess – need try script with real InDesign document -
May 3, 2018 at 10:58 am #103525
Aaron Gray
ParticipantThanks, Oleh. I will keep testing it out—in other documents as I have the opportunity. I did try saving it as an IDML but that didn’t resolve it. Thanks again for the help!
Aaron
-
May 4, 2018 at 12:21 am #103534
Kai Rübsamen
MemberOleh, why didn’t you loop backwards as suggested?
-
May 4, 2018 at 4:45 am #103535
Oleh Melnyk
MemberKai, when I loop backward, I got the same problem Aaron has – some object moves to a new layer and some don’t so I have to run the script multiple times… ?
I don’t think loop backward can solve this problem since script didn’t store order, page number, or folder then move the object to new page/folder/whatever might matters for loop order – script just iterate over every element in opened document, check if object has applied object style, and if that object is not in the desired layer – script just moves object to new layer…New version should work with locked layers/objects https://www.dropbox.com/s/knh502mk9uxjipg/Move%20Object%20with%20Selected%20ObjectStyle%20to%20Layer%20v2.jsx?dl=0
-
May 4, 2018 at 5:11 am #103536
Kai Rübsamen
MemberAaron sent his testfile only to you. So I built a simple sample: 4 pages as spreads. Page 1 and 4 alone, page 2+3 on one spread. If there are more than one objects with applied oStyle per spread, only one object will be moved to the new layer, if you move forwards. If you move backwards all objects are moved.
But you are right: I had sometimes problems with forward and backward loops, if I use collections. So sometimes it is helpful to deal with arrays instead. Maybe Aaron should built a example, that is available for everyone here.
-
May 4, 2018 at 5:53 am #103538
Oleh Melnyk
MemberWeird! I got an opposite issue while iterating backward.
I added “proceed until you bleed” while-loop that tries to move objects to the desired layer (1000 tries) – now it should work, lol
https://www.dropbox.com/s/r4dj5qktplewm7p/Move%20Object%20with%20Selected%20ObjectStyle%20to%20Layer%20v3.jsx?dl=0 -
May 4, 2018 at 6:57 am #103540
Kai Rübsamen
MemberOleh, weird indeed!
Assume you have one page with 4 items.
pageItems[0] > wrong style
pageItems[1] > right style to move
pageItems[2] > right style to move
pageItems[3] > wrong styleIf you move forwards within a collection you should get the following result:
pageItems[1] is moved to the new layer, but if you check the index of this object, the index is now [3]. That means, the previous [2] becomes [1] and will be ignored (!), and the previous [3] is now [2] and fails, because of the wrong style. But the previous [1] whos index is now [3] will be examined again.
This will not happen (normally), if you loop backwards or if you deal with pI = app.activeDocument.pageItems.everyItem().getElements() as static array forwards.
However: I had some issues with forwards or backwards in the past too ;-)
-
May 4, 2018 at 9:10 am #103545
Aaron Gray
ParticipantI tried the latest version and I’m still getting inconsistent results, but now in a different way. I’m finding that the objects with the object style I’ve selected are consistently moving to whichever layer I select. However, I also find that some other objects that don’t have that style are also moving to the selected layer.
Additionally, there seem to be certain layers where if I try to move objects to the layer with the script, I get an error with each object that says “Error: Cannot move locked items to a new layer,” even though none of the objects I’m trying to move are locked. However, then it goes ahead and moves the object to the layer anyway. (Here it seems like writing a line into the script to suppress error messages could be useful.)
I’m sorry I’m not able to post a sample file online, but the policies of the company I work for wouldn’t permit that. This seems like it will be a very useful script once it’s debugged. I wish I had the programming skills to help more!
-
May 4, 2018 at 9:28 am #103546
Kai Rübsamen
MemberAaron, you could sent me a file directly to forum@ruebiarts.de. Otherwise you should built an example with bla bla text ;-)
> However, I also find that some other objects that don’t have that style are also moving to the selected layer.
Hm, I cannot believe that, cause in Olehs script there is a line, that should prevent that!
-
May 4, 2018 at 1:25 pm #103550
Aaron Gray
ParticipantThanks, Kai! I didn’t get a chance today but I will send something your way next week.
-
May 4, 2018 at 1:30 pm #103551
Oleh Melnyk
Membercheck this script version with my InDesign test files – https://www.dropbox.com/s/nrb6me33sbtn9wg/MoveObjects2Layer.zip?dl=0
-
May 5, 2018 at 3:54 am #103554
Kai Rübsamen
MemberOleh, did you package the right files? Locked objects are not moved, if you choose move red to red, yellow is moved as well, but not on page 1. Objects with basic frame applied are moved on page 1 too ;-)
-
May 5, 2018 at 4:39 am #103555
Kai Rübsamen
MemberHaha, I had in the meantime 3 different samples and get different results, if I move forwards or backwards, but not any solution give the right results ;-)
First, you should remove your while loop. Second use a static array instead of your dynamic collection. This simplified example works for me in any solution:
var curDoc = app.activeDocument; var objectStyleName = "Red Style"; var layerName = "Red Layer"; var pItems = curDoc.pageItems.everyItem().getElements(); var nItems = pItems.length; for (var i = 0; i < nItems; i++) { var curItem = pItems[i]; if (curItem.appliedObjectStyle.name == objectStyleName && curItem.itemLayer.name != layerName) { // move objects to layer curItem.itemLayer = curDoc.layers.itemByName(layerName); } }
-
May 5, 2018 at 7:25 am #103559
Oleh Melnyk
Memberlooks like this is InDesign bug – sometimes it works, sometimes it doesn’t, and then – random results all the time
-
May 7, 2018 at 5:48 am #103575
Aaron Gray
ParticipantKai: Do you still want a test file? It sounds like you’re getting exactly the same results I was. However, I downloaded your simplified script, changed the object style and layer names to match the stuff I wanted to move, and it seems like it’s working fine. That may be all I need to solve my problem. Thanks!
-
May 7, 2018 at 10:14 am #103584
Kai Rübsamen
MemberAaron, if this is working for you, I don’t need additional testfiles.
Oleh, I’m not sure, if this is a bug or simply the behavior of collections.Kai
-
April 26, 2022 at 9:34 am #14364882
lynx
ParticipantThis has been such great code to dissect and learn from, Currently it wont pull objects styles in the dropdown that are in folders, how would I tweak the language to do that?
Secondly, If i change the top half to pull paragraph styles in the first list and objects styles in the second, how could I adjust the bottom portion to assign object styles from text frames that have the paragraph style chosen from the dropdown.
thank you so much for any help!!
-
-
AuthorPosts
- You must be logged in to reply to this topic.
