A script to have the used styles at the top

Next
 From:  codi (CODISESAN)
11186.1 
Sorry for ungrammatical English translated with translator
I normally work with a file that has the COLOUR RAL styles (1000 to 9023).

Develop a script to have the used styles at the top?
It is not convenient to scroll through the whole list to switch on/off styles used in a long list.

Thank you.

Mario
Image Attachments:
Size: 1.1 MB, Downloaded: 53 times, Dimensions: 1941x1101px
Size: 849.1 KB, Downloaded: 45 times, Dimensions: 1941x1101px
Size: 876 KB, Downloaded: 66 times, Dimensions: 1941x1101px
  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:  Michael Gibson
11186.2 In reply to 11186.1 
Hi Mario, one method you can use to do that is to select all your objects and use File > Export to write them to a new .3dm file.

Export only writes the selected objects and only the styles used by those objects to the exported file, unlike "SaveAs" which writes the whole list.

Then open up your compacted export file and use File > Import to open up a blank file that has your full set of styles in it. That will place the unused ones below the compacted ones.

You can use that method right now but I'll see about making a script to do it too.

- Michael
  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:  wayne hill (WAYNEHILL5202)
11186.3 
Hi Mario,

You could try this script to remove all the unused layers.

https://moi3d.com/forum/index.php?webtag=MOI&msg=3774.2

Wayne


code:
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();
}
	moi.geometryDatabase.addDefaultStyles();
  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:  Michael Gibson
11186.4 In reply to 11186.3 
(Note, reposted this msg, it got lost temporarily from web server migration)


hello WAYNEHILL5202, I know and use the script to remove unused styles.

My request is different.

What I was asking, is the possibility of having a script that would allow you to bring up all the styles used in the design, and keep underneath all those available but not yet used. (In my case a table of RAL colours from 1000 to 9023).

Ciao. 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:  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