Trying to get the Root from the Scene nodes and respective children

Simple trick for this

var repeat = true
function myPluginCommand(selection, documentRoot) {

    	if (selection.hasArtboards) {
    		var rootnodes = selection.insertionParent.parent;
    		var nodes = selection.items[0];
    		//console.log(rootnodes);

    		rootnodes.children.forEach(element => {
    			//This is ArtBoard

    			let artboardname = element.name;
    			selection.items = [element];
    			let rect = new Rectangle();
    			rect.height = 10;
    			rect.width = 10;
    			rect.fill = new Color("red");
    			selection.insertionParent.addChild(rect);

    			var children = element.children;
    			console.log(children.length);
    			children.forEach(element => {
    				//This is an Artboard child
    				console.log(element);
    				selection.items = [element];
    				let height = element.globalDrawBounds.height;
    				let width = element.globalDrawBounds.width;

    				let x = element.globalDrawBounds.x;
    				let y = element.globalDrawBounds.y;
    				console.log("height : " + height + "width : " + width);
    				console.log("x : " + x + "y : " + y);
    				let rect = new Rectangle();
    				rect.height = height / 10;
    				rect.width = width / 10;
    				rect.fill = new Color("red");
    				selection.insertionParent.addChild(rect);
    				let xParent = rect.parent.globalDrawBounds.x;
    				let yParent = rect.parent.globalDrawBounds.y;
    				console.log("rect parent : " + rect.parent);
    				rect.moveInParentCoordinates(x - xParent, y - yParent);
    			})
    		});
    	} else if (!selection.hasArtboards && repeat) {
    		repeat = false;
    		console.log("Selected Otherthan Artboards");
    		//console.log(documentRoot.children);
    		console.log(documentRoot.children.forEach(element => {
    			console.log(element);
    			selection.items = [element]
    			myPluginCommand(element, 0);
    		})
    		);
    	}
    }

try and reply me i can modify it now if it doest work

1 Like

It is starting to work. Thank you :slight_smile:

:pray::pray::pray::pray:

with some changes because above runs only first time.

var repeated = false;
function myPluginCommand(selection, documentRoot) {
	if (selection.hasArtboards) {
		(repeated) ? console.log("repeated") : 0;
		var rootnodes = selection.insertionParent.parent;
		var nodes = selection.items[0];
		console.log(rootnodes.children.length);
		rootnodes.children.forEach(element => {
			//This is ArtBoard
			let artboardname = element.name;
			selection.items = [element];
			let rect = new Rectangle();
			rect.height = 10;
			rect.width = 10;
			rect.fill = new Color("red");
			selection.insertionParent.addChild(rect);

			var children = element.children;
			children.forEach(element => {
				//This is an Artboard child
				console.log(element);
				selection.items = [element];
				let height = element.globalDrawBounds.height;
				let width = element.globalDrawBounds.width;

				let x = element.globalDrawBounds.x;
				let y = element.globalDrawBounds.y;
				console.log("height : " + height + "width : " + width);
				console.log("x : " + x + "y : " + y);
				let rect = new Rectangle();
				rect.height = height / 10;
				rect.width = width / 10;
				rect.fill = new Color("red");
				selection.insertionParent.addChild(rect);
				let xParent = rect.parent.globalDrawBounds.x;
				let yParent = rect.parent.globalDrawBounds.y;
				console.log("rect parent : " + rect.parent);
				rect.moveInParentCoordinates(x - xParent, y - yParent);
			})
		});
	} else if (!selection.hasArtboards) {
		repeated = true;
		console.log("Selected Otherthan Artboards");
		var element;
		var set = true;
		documentRoot.children.forEach(element => {
			if (set) {
				selection.items = [element];
				set = false;
			}
		});
		myPluginCommand(selection, documentRoot);
	}
}
1 Like

Yup, finally it works. Fantastic. Thank you very much for your help.

An off topic thing i want to ask is, how do you have your console black themed?

1 Like

This is win10 with dark mode turn on. :slight_smile: Will make even fil explorer black.

is not an ADOBE XD feature.

I do have the windows dark theme enabled, but still the console is in light theme for me.

You need the latest version of the update. It was not available on the first version.