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


#1

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.


#2

What do you required ?
Children of the artboard
@igcorreia


#3

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


#4

Ok I will try and reply


#5

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


#6

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);
	});
}

Artbobard Name from Selection?
#7

@igcorreia
see the implementation


#8

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);
		})
	});
}

#9

@PramUkesh trying it


#11

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:


#12

Means you want pasteboard content ?


#13

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.


#14

where the code is failing


#15

When I DON’T select any artboard.


#16

wait a second i will try it


#17

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


#18
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);
    }
}

#19

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.


#20

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.


#21

To do this:

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

Help