A script to have the used styles at the top
All  1-4  5-10

Previous
Next
 From:  wayne hill (WAYNEHILL5202)
11186.5 In reply to 11186.4 
Hi Mario,

The last line of the that script restores the default styles. Append your favorite style script to the end of the purge script.
I did not consider duplicate styles being created. No coffee so far this morning.

Wayne

Example:

code:
// Purge unused styles and append 100 styles to list.

script: var gd = moi.geometryDatabase;
var styles = gd.getObjectStyles();
var counts = new Array(styles.length);
for (var i = 0; i < counts.length; ++i) {
	counts[i] = 0;
}
var objs = gd.getObjects();
for (var i = 0; i < objs.length; ++i) {
	var obj = objs.item(i);
	if (obj.styleIndex < counts.length) ++counts[obj.styleIndex];
	var subobjs = obj.getSubObjects();
	for (var j = 0; j < subobjs.length; ++j) {
		var subobj = subobjs.item(j);
		if (subobj.styleIndex < counts.length) ++counts[subobj.styleIndex];
	}
}
for (var i = 0; i < styles.length; ++i) {
	if (counts[i] == 0) styles.item(i).remove();
}

// Restore default styles:
moi.geometryDatabase.addDefaultStyles();

// append 100 styles to listing
script: /* Make gradient styles */ var red = 12,
	green = 15,
	blue = 20;
for (var i = 1; i <= 100; ++i) {
	var style = moi.geometryDatabase.addStyle();
	style.name = 'Gradient ' + i;
	style.color = ((red % 256) << 16) | ((green % 256) << 8) | (blue % 256);
	red += 2;
	green += 3;
	blue += 7;
}
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  MO (MO_TE)
11186.6 
Hi
I modified the above script:
It'll arrange your styles and keep your unused styles at the end of the list. (Keeps the names and colors intact)
code:
script: var gd = moi.geometryDatabase;
var styles = gd.getObjectStyles();
var counts = new Array(styles.length);
var unusedStylesList = {};
unusedStylesList.name=[];
unusedStylesList.color=[];
for (var i = 0; i < counts.length; ++i)
{
	counts[i] = 0;
}
var objs = gd.getObjects();
for (var i = 0; i < objs.length; ++i)
{
	var obj = objs.item(i);
	if (obj.styleIndex < counts.length) ++counts[obj.styleIndex];
	var subobjs = obj.getSubObjects();
	for (var j = 0; j < subobjs.length; ++j) {
		var subobj = subobjs.item(j);
		if (subobj.styleIndex < counts.length) ++counts[subobj.styleIndex];
	}
}
moi.geometryDatabase.styleEditorOpened();
for (var i = 0; i < styles.length; ++i)
{
	if (counts[i] == 0)
	{
		unusedStylesList.name.push(styles.item(i).name);
		unusedStylesList.color.push(styles.item(i).color);
		styles.item(i).remove();
	}
}
for(i=0;i<unusedStylesList.name.length;i++)
{
	var style = moi.geometryDatabase.addStyle();
	style.name = unusedStylesList.name[i];
	style.color = unusedStylesList.color[i];
}
moi.geometryDatabase.styleEditorClosed();
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  codi (CODISESAN)
11186.7 In reply to 11186.6 
wow !!! great.
thanks guys.

Mario
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  christian (CHRI)
11186.8 In reply to 11186.6 
well done MO
We are lucky to have great people like you on this forum.

Thanks
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  MO (MO_TE)
11186.9 In reply to 11186.8 
Thank you Christian :)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  wayne hill (WAYNEHILL5202)
11186.10 
Great work Mo!
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1-4  5-10