• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Show hidden text-object depending on the name

Explorer ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hello there,

i have a long script with several functions, i just want implement something just right at the beginning of it, before the script execute any of the other stuff.

 

What i need is to make visible specific text object. These text object are called SAMPLE and are inside some layers of the doc, but not into every layer. (see pic below)

 

sample.JPG

 

 

 

 

 

 

 

 

 

Can you please tell mehow to do it and where to place it? (see pic of the first lines of code below)

 

2.JPG

 

Thank you in advance!

TOPICS
Scripting , Type

Views

186

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 04, 2023 Jul 04, 2023

Ohh, sorry to misunderstood. Use following if statement

if (_textFrames[i].name == "SAMPLE") {
        _textFrames[i].hidden = false;
}

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hi,

The following version will show only those textframes that are named as SAMPLE.

var _doc = app.activeDocument;
_textFrames = _doc.textFrames;
for (var i = 0; i < _textFrames.length; i++) {
    if (_textFrames[i].name != "SAMPLE") {
        _textFrames[i].hidden = true;
    }
}

 

In your screenshot, code is not completely visible. But what is visible, you can place above section of code, inside you main().

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hi Charu, thank you for your reply.

I apologize if i'm wrong but

hidden = true

shouldnt be

hidden = false

since i want them to not be hidden?

I'm not code expert, i just noticed something like that before, that's why i have this doubt.

 

So i can place it just after the line "main()", correct?

 

Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hi,

1. You need to place after the line

function main {

 

2. hidden = true is correct, because the condition in if statement says that if the name of the textframe is not SAMPLE, then hide. See operator !=

 

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hi and thank you.

Sorry if i wasnt clear. I dont need to hide the text object with different name than "SAMPLE". I want to make visible only the text objects called "SAMPLE", which in the document are currently hidden.

 

Thank you in advance.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Ohh, sorry to misunderstood. Use following if statement

if (_textFrames[i].name == "SAMPLE") {
        _textFrames[i].hidden = false;
}
Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Thank you, and sorry again, i might have been not clear enough :))

I tested your lines in a brand new jsx file and it works as intended.

Now i just need to be sure where to place them.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 06, 2023 Jul 06, 2023

Copy link to clipboard

Copied

Anyway, your script worked and i found the right spot for it. Thanks again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Unfortunately, your screenshots are cut off in the important places.


It is somewhat difficult without seeing how the layer palette is structured - and what exactly is shown or hidden.
Background: You cannot show a hidden element of a layer if the layer itself is hidden.


Also: How do you proceed if the text layer is shown but the parent layer is hidden?

This can be quite confusing with deeply nested structures, especially if nothing else on the layer is allowed to be displayed at the same time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hi Pixx and thank you for yoining the post.

Here is a more wide screenshot, sorry i can't show it entirely, hope is enough.

I tested Charu lines in a brand new jsx file and it works as intended.

Can you suggest me where to place it in the script i have?

Thanks!

 

Cattura.JPG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Also, more information: The layers that contains the text objets SAMPLE are always visible, only the text objects, and some other objects, inside of them are hidden.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2023 Jul 06, 2023

Copy link to clipboard

Copied

@Nasturzio -

You can place the code that is shared here above the line number 12. It can be wrong. but since you have mentioned that you want to execute it first before anything else, so I think by looking at your half code, it seems it is good to write above line 12.

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2023 Jul 04, 2023

Copy link to clipboard

Copied

Hi Charu

😉

 

Or perhaps - depending on the structure - something more like that?

 

//…
if (TF[i].name == "Sample" && TF[i].hidden == true) {
    var aTF = TF[i];
    try {aTF.hidden =!aTF.hidden;}
    catch (e) {
        if (aTF.parent.visible == false) {
            aTF.parent.visible  =!aTF.parent.visible;
            if(TF[i].hidden == true) {
                aTF.hidden =!aTF.hidden;
                }
            }
        }
    }
//…

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2023 Jul 06, 2023

Copy link to clipboard

Copied

@pixxxelschubser ,

Ofcourse, a better approach. I write it down the simple solution as nothing is visible in the existing code.

That's correct if layer is hidden, my code will work but since it was not mentioned anywhere in the OP post, I did not consider that.. 🙂

 

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2023 Jul 06, 2023

Copy link to clipboard

Copied

LATEST
quote

Hi Pixx and thank you for yoining the post.

Here is a more wide screenshot, sorry i can't show it entirely, hope is enough …


By @Nasturzio

 

I meant the first screenshot showing the "Layers" panel. Unfortunately, it is not possible to see how your document is structured and which layers, sublayers, groups and elements are locked or visible.

Hi @Charu Rajput 

everything is fine.

😉
Unfortunately, experience shows time and again that it is precisely such "little things" that are not mentioned that lead to many scripts not working and triggering errors. For this reason, I often programme an additional security level.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines