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

What is the correct way to get the Scene node to make a foreach per node, starting with each artboard.

don’t understand why documentRoot.children does not work since I get the root node. Please help.

What do you required ?
Children of the artboard
@igcorreia

1 Like

Nop :), the entire list of ARTBOARDS and than I want to do a for each for every element inside the artboard.

Ok I will try and reply

1 Like

ok i will getting list of artboards for now do you?
where you stopped?

1 Like

As per my understanding you want get all art boards and dosomething
i just implemented for each artboard only so you can extend it furthur

this is my crazy implementation

function myPluginCommand(selection, documentRoot) {
	var rootnodes = selection.insertionParent.parent;
	var nodes = selection.items[0];
	console.log(rootnodes);
	rootnodes.children.forEach(element => {
		console.log(element.name);
		selection.items = [element];
		let rect = new Rectangle();
		rect.height = 100;
		rect.width = 100;
		rect.fill = new Color("grey");
		selection.insertionParent.addChild(rect);
	});
}
1 Like

@igcorreia
see the implementation

1 Like

full fledged implementation is :
@igcorreia

function myPluginCommand(selection, documentRoot) {
	var rootnodes = selection.insertionParent.parent;
	var nodes = selection.items[0];
	//console.log(rootnodes);
	rootnodes.children.forEach(element => {
		//This is ArtBoard
		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);
		})
	});
}
1 Like

@PramUkesh trying it

Your example only works if I choose 1 artboard correct?

I want to get ALL ARTBOARDS and ALL CHILDRENS. Getting all artboards is my problems.

So with 1 artboard selected it works perfectly.

but with now artboards selected:

Means you want pasteboard content ?

Let say I have 2 artboards and on each artboard I have 2 squares, in one a red one and in another a black one.

I want to get the colors of all squares in all artboards. I want to find all colors for used in a project.

where the code is failing

When I DON’T select any artboard.

wait a second i will try it

1 Like

do you remember how you managed to add artboards in experience generator
i forgot those method
i was trying to get now once i got i will show that or
you can add some code snippet from plugin so that i can explain with ease

1 Like
for (let a = 0; a < settingsScope.length; a++) {
    var expDevSetting = settingsScope[a];
    var artBoardHeight = expDevSetting.height;
    var artBoardWidth = expDevSetting.width;
    var artBoardName = expDevSetting.title;     
    var newArt = new Artboard();
    newArt.name = checkedDeviceValue.charAt(0).toUpperCase() + checkedDeviceValue.replace("_", "-").substr(1)  + ' ' +checkedExperienceValue.charAt(0).toUpperCase() + checkedExperienceValue.replace("_", "-").substr(1)  +  ' - ' +artBoardName;
    newArt.width = artBoardWidth;
    newArt.height = artBoardHeight;
    newArt.fillEnabled = true;
    newArt.fill = new Color("white");
    newArt.focusedArtboard = true;
    documentRoot.addChild(newArt, 0);

    if(a>=1){              
        newArt.moveInParentCoordinates(nextArtboardPosition, farthestH + artboardVertSpacing);
        nextArtboardPosition = nextArtboardPosition + newArt.width + artboardSpacing;
    }
    else{
        nextArtboardPosition = nearestW + newArt.width + artboardSpacing;
        newArt.moveInParentCoordinates(nearestW, farthestH + artboardVertSpacing);
    }
}

But I want to GET the scares not to design a new one.

I am trying to OBTAIN information and not GENERATE.

Obtain the colors of squares already created.

When I do a console.log(documentRoot) I get this:

RootNode {
  children: [Artboard, Artboard, Text]
}

But I cant reach .children or the Artboard and I don’t know why.

To do this:

we also need to have access to all text elements in all artboards.

Help