How to access the number of "variations" and the "index" of the active variation for Generative Fill smart objects?

I’m looking for a way to access the number of variations embedded in a Generative Fill smart object and a way to determine which variation is active, i.e. the active “index”.

Using:

const activeLayer = batchPlay([{ "_obj": "get", "_target":{ "_ref": "layer", "_enum": "ordinal", "_value": "targetEnum" } }], { synchronousExecution: true })
console.log(activeLayer)

I can get a lot of info about the Generative Fill layer. It looks like there are multiple smart objects embedded in this layer, but I can’t determine the index of any of them or which index is currently active and being displayed.

Alchemist has even more info, but still not able to locate the number of variations embedded in the smart object or which index is currently visible.

Alchemist can also capture code for changing which index is being displayed or for deleting an index, but that’s not helpful in determining the number of variations or which one is currently the active index. Photoshop is able to track all this, but I can’t find a way to access this basic info.

Thought I would check with the experts here to see if I’m overlooking something.

It might be a bit too early to play with it. Generative fill is still in Beta. Descriptors might change without warning at any time.

Anyway… maybe you could try JSON property of layer/document… in some configuration, it can see what is inside SO without opening it.

I need to retrieve two specific pieces of information for a Generative Fill layer:

1. The currently selected variation.

2. The total number of variations available.

So far, I can only get the variation count by changing the selected variation, which isn’t ideal because it alters the user’s current selection. Is there a way to access both the active variation index and the total variations count directly via batchPlay

If anyone has encountered this before or knows the relevant descriptors/commands, I’d appreciate your help.

did u find a way? I ve been looking for docs on generative fill too but couldnt find any.

I believe two topics are about the exact same issue, so I merged them..

I don’t think there are any docs, as the Ps UXP team was gone not long after GF was introduced. I wouldn’t expect any official support any time soon and would try what @Jarda suggested

you can get trough the batchPlay which targets JSON property on a variation layer

const result = await batchPlay(
	   [
		  {
			 _obj: "get",
			 _target: [
				{
				   _property: "json"
				},
				{
				   _ref: "document",
				   _id: app.activeDocument.id
				}
			 ],
			 expandSmartObjects: true,
			 getTextStyles: true,
			 getFullTextStyles: true,
			 getDefaultLayerFX: true,
			 layerID: app.activeDocument.activeLayers[0].id,
			 getCompLayerSettings: true,
			 getPathData: true,
			 imageInfo: true,
			 compInfo: true,
			 layerInfo: true,
			 includeAncestors: true,
			 _options: {
				dialogOptions: "dontDisplay"
			 }
		  }
	   ],
	   {}
	);
	const docInfo = JSON.parse(result[0].json);
	console.log("layer json");
	console.log(
		docInfo
	);

Then, you’ll see a nested complicated object.
following the properties
→ placed → layers → layers → here, variations.
Each variation layer has visible value which indicates the current selected variation
and also you count the number of variation.

3 Likes

Thank you! @shuji that solves my problem