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

Beginner: help with ungroup script

Guest
Jul 29, 2010 Jul 29, 2010

Copy link to clipboard

Copied

I just began learning Javascript for InDesign CS5 and I would appreciate some step by step help

Goal: Ungroup all grouped objects in the active document.

- Active document

- Select all grouped items

- Ungroup the items

I tried a bunch of different ways… but I always got an orange highlight in the ESTK. What would the first step be?

TOPICS
Scripting

Views

11.5K
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

Guide , Jul 29, 2010 Jul 29, 2010

#target indesign function unGroup() {      if (app.documents.length == 0) {           alert("Please have an 'Indesign' document before running this script.");           return;      }      docRef = app.activeDocument;      with(docRef) {           alert('This doc has '+groups.length+' groups…')           while (groups.length != 0) {                groups.everyItem().ungroup();                alert('This doc now has '+groups.length+' groups…')           }      }      } unGroup();

The count may i

...

Votes

Translate
Engaged ,
Feb 21, 2013 Feb 21, 2013

Copy link to clipboard

Copied

fillColor is actually a property of the pageItem, not one of the transparency (effect) Setting objects, so you address it just by pageItem.fillColor. (both a textFrame and a Group are PageItems.)

So we can just add a hasFillColor function and add that test to the hasAnEffect test that we have already implemented. hasFillColor() is a little bit more complicated than you would expect, since, as the documentation states, fillColor can either be a Swatch object or a Color object. So we have to test for both cases.

(By the way, I don't "just know" all these things -- I have a horrible memory, actually -- I usually have to look them up in the object reference documentation.)

So you get something like this:

#target "indesign"

var doc = app.activeDocument;

var newLayer = doc.layers.itemByName("MyNewTextFrameLayer");

if (!newLayer.isValid)

          newLayer = doc.layers.add({name:"MyNewTextFrameLayer"});

var tfs = doc.spreads.everyItem().textFrames.everyItem().getElements();

while(tf = tfs.pop())

{

          if(hasFillColor(tf) || hasAnEffect(tf)) {

                    ; // do nothing

          } else {

                    tf.move(newLayer);

          }

}

function hasFillColor(pageItem) {

          var swatch = pageItem.fillColor;

          if (swatch.constructor && swatch.constructor.name == "Swatch") {

                    return (swatch.index == 0) ? false : true; // [None]

                    // the reason I'm testing swatch.index == 0 instead of swatch.name == "None"

                    // is that I can't remember if the swatch names get localized or not,

                    // and we don't want our script to break in a non-English-language country.

          } else {

                    return true;          // not a Swatch -- so a non-swatch (unnamed) Color was applied

          }

}

function hasAnEffect(pageItem) {

          var contentX = pageItem.contentTransparencySettings;

          var fillX = pageItem.fillTransparencySettings;

          var strokeX = pageItem.strokeTransparencySettings;

          var tX = pageItem.transparencySettings;

          if (settingHasAnEffect(contentX)

                              || settingHasAnEffect(fillX)

                              || settingHasAnEffect(strokeX)

                              || settingHasAnEffect(tX)) {

                    return true;

          } else {

                    return false;

          }

}

function settingHasAnEffect(settingX) {

          var test1 = settingX.bevelAndEmbossSettings.applied;

          var test2 = (settingX.blendingSettings.blendMode != BlendMode.NORMAL);

          var test3 = settingX.directionalFeatherSettings.applied;

          var test4 = (settingX.dropShadowSettings.mode == ShadowMode.DROP);

          var test5 = (settingX.featherSettings.mode != FeatherMode.NONE);

          var test6 = settingX.gradientFeatherSettings.applied;

          var test7 = settingX.innerGlowSettings.applied;

          var test8 = settingX.innerShadowSettings.applied;

          var test9 = settingX.outerGlowSettings.applied;

          var test10 = settingX.satinSettings.applied;

 

          if (test1 || test2 || test3 || test4 || test5 || test6 || test7 ||

                    test8 || test9 || test10) {

                    return true;

          } else {

                    return false;

          }

}

Votes

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
Participant ,
Mar 07, 2024 Mar 07, 2024

Copy link to clipboard

Copied

Can anyone provide the .jsx script file for this?  I am new to scripting and totally lost in this list of revised code - not sure which to use.  

Votes

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