Highlighted

Get all textframes inside a library element

New Here ,
Apr 23, 2020

Copy link to clipboard

Copied

I was able to select the library item in a document using `app.libraries.item(0)` but how do I get all the elements(text frames) inside the library 

TOPICS
Scripting

Views

571

Likes

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

Get all textframes inside a library element

New Here ,
Apr 23, 2020

Copy link to clipboard

Copied

I was able to select the library item in a document using `app.libraries.item(0)` but how do I get all the elements(text frames) inside the library 

TOPICS
Scripting

Views

572

Likes

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
Apr 23, 2020 0
Adobe Community Professional ,
Apr 23, 2020

Copy link to clipboard

Copied

You would check all the assets in your library.

Likes

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
Reply
Loading...
Apr 23, 2020 0
New Here ,
Apr 23, 2020

Copy link to clipboard

Copied

this is how I am selecting a specific library

```

app.libraries.item(0).assets.item("LIB_NAME")
>> [object Asset]

```

 

but how to get all the elements in that specific library? 

Likes

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
Reply
Loading...
Apr 23, 2020 0
Adobe Community Professional ,
Apr 23, 2020

Copy link to clipboard

Copied

Seems like you should be selecting the library you want with:

var lib = app.libraries.itemByName("LIB_NAME");

From there, you can get all assets in that library with: 

var assets = lib.assets; 

From there, you can loop through the assets and check if they are text assets with: 

for (var i = 0; i < assets.length; i++) {
    if (assets[i].assetType = AssetType.TEXT_TYPE) {
        assets[i].select();
    }
}

More on the Asset DOM is here: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Asset.html#d1e298313 

Likes

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
Reply
Loading...
Apr 23, 2020 0
Adobe Community Professional ,
Apr 23, 2020

Copy link to clipboard

Copied

Hi Brian,

AssetType is one idea. But one could doubt if the right assetType is applied to the right object.

Further: What happens if you store two or more objects in one asset?

 

I think one could only filter a text frame out of library assets if you place the asset.

asset.placeAsset() will return an array of objects. Loop the array and you know what it does contain.

 

 

var doc = app.documents.add();

var assetsArray = app.libraries[0].assets.everyItem().getElements();

for( var n=0; n<assetsArray.length; n++)
{
	var placedAssetArray = assetsArray[n].placeAsset( doc );
	
	for( var a=0; a<placedAssetArray.length; a++ )
	{
		$.writeln( n +"\t"+ a +"\t"+ placedAssetArray[a].constructor.name );
	};
};

// Tidy up:
doc.close( SaveOptions.NO );

 

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Apr 23, 2020 0
Adobe Community Professional ,
Apr 23, 2020

Copy link to clipboard

Copied

Good idea. I will purport to not having worked with assets, but placing and looping through it sounds like a good approach. Thanks for building it out further (and my knowledge base 🙂

Likes

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
Reply
Loading...
Apr 23, 2020 0
Adobe Community Professional ,
Apr 26, 2020

Copy link to clipboard

Copied

Hi Brian,

my code snippet currently is using only one new document for placing the assets.

If one likes to actually use the assets it could be better to do one new document for every array of assets.

Why? Because there could be conflicts between incoming styles, custom named colors and styles and custom named colors that are already inside the document one like to place an asset.

 

It's easier to solve such conflicts if you start from scratch with a new document and move a placed asset over to the target document.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Apr 26, 2020 0