Saving object's new labels using flexscript

Saving object's new labels using flexscript

christian_bezzi
Contributor Contributor
136 Views
1 Reply
Message 1 of 2

Saving object's new labels using flexscript

christian_bezzi
Contributor
Contributor

Hi all,

 

while not running the model (model is stopped) I am creating tens of labels into tens of Control Area objects, using flexscript, looping into a Group. That is ok.

 

Now I need to save the new created labels so that at reset they won't disappear. It there a command that can substitute the manual click on the button "Save reset values for all labels" ? if not, how could I add them into the labelreset treenode ?

 

Thank you !

0 Likes
137 Views
1 Reply
Reply (1)
Message 2 of 2

FelixMoehlmann
Mentor
Mentor

You could just not activate the reset labels function and renew the labels on every reset through the model reset trigger.

In many cases you can inspect the code that gets executed by GUI elements by right-clicking onto the GUI background (in this case next to the save icon) and choose "View -> Explore Structure".

Screenshot 2026-09-30 083413.png

This tells you that the save button just replaces the "labelreset" node with a copy of the object's label node. You can use the same code (needs a reference to the label node as the starting point) or write your own code to do the same. That could look like the example below.

Array objects = Group("Group1").toFlatArray();
Object obj;
for(int i = 1; i <= objects.length; i++)
{
	obj = objects[i];
	obj.NewLabel = 2;
	
	// This saves all current labels as reset values
	{
		treenode labelNode = labels(obj);
		treenode resetLabelNode = obj.attrs.assert("labelreset");
		createcopy(labelNode, resetLabelNode, 0, 0, 0, 1);
		resetLabelNode.name = "labelreset";
	}
	
	// This adds a specific label to the reset labels
	{
		treenode label = obj.labels["NewLabel"];
		treenode resetLabelNode = obj.attrs.assert("labelreset");
		treenode resetLabel = resetLabelNode.subnodes.assert(label.name);
		createcopy(label, resetLabel, 1, 0, 0, 1);
	}
}
0 Likes