Script to assign colour to objects
All  1-4  5-11

Previous
Next
 From:  shayno
11193.5 In reply to 11193.3 
I would just want to set specific labels and colours in as presets in the script that cycles through them each key press

Once it is written for metals I am able to customise it for another key for gemstones

gold 207 194 37
platinum 145 145 145
silver 207 208 203
rose gold 214 141 92

Thanks
shayne
  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
11193.6 In reply to 11193.5 
Hi shayne, try pasting this in for the "command" part of a shortcut key:

code:
script: /* Cycle selection through colors */

var styles = [
	[ 'gold', 207, 194, 37 ], 
	[ 'platinum', 145, 145, 145 ], 
	[ 'silver', 207, 208, 203 ], 
	[ 'rose gold', 214, 141, 92 ]
];

/* Create styles if not currently existing */

var style_indexes = [];

for ( var i = 0; i < styles.length; ++i )
{
	var style = moi.geometryDatabase.findStyle( styles[i][0], true /*Create if not found*/ );
	style_indexes.push( style.index );
	var r = styles[i][1];
	var g = styles[i][2];
	var b = styles[i][3];
	style.color = ( (r << 16) | (g << 8) | b );
}

var objects = moi.geometryDatabase.getSelectedObjects();

if ( objects.length > 0 )
{
	var obj = objects.item(0);
	var current = -1;
	for ( var i = 0; i < style_indexes.length; ++i )
	{
		if ( obj.styleIndex == style_indexes[i] )
			current = i;
	}

	var next = (current + 1) % style_indexes.length;
	objects.setProperty( 'styleIndex', style_indexes[next] );
}



- 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:  shayno
11193.7 In reply to 11193.6 
Hi Michael
That works perfectly ,
I had to remove any returns to make it all one line as it would not past in
thanks so much 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:  Michael Gibson
11193.8 In reply to 11193.7 
Hi shayne, I'm glad that was what you needed. For MoI version 4 or v5 the returns should be removed automatically when you paste it in.

- 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:  shayno
11193.9 In reply to 11193.8 
Thanks Michael
I am tempted to upgrade to ver4 but my ver3 is so custom now and full of scripts I feel it would be time consuming to change it .
I have previously reconfigured the sidepane to only have the commands I use and only 2 panels so not split for construct/ transform etc
I have colours I use for everything and a single key press I find is very fast to access them.
would it be difficult to script to hide a specific colour say r 207 g 194 b 37 ?
kind regards
shayne
  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
11193.10 In reply to 11193.9 
Hi shayne,


re:
> would it be difficult to script to hide a specific colour say r 207 g 194 b 37 ?

Try this:

code:
script: var r = 207, g = 194, b = 37;
var rgbcolor = (r << 16) | (g << 8) | b;
var style_index = -1;
var styles = moi.geometryDatabase.getObjectStyles();
for ( var i = 0; i < styles.length; ++i )
{
    var style = styles.item(i);
    if ( style.color == rgbcolor )
    {
         style_index = i;
         break;
    }
}

if ( style_index != -1 )
{
     var objs = moi.geometryDatabase.getObjects();
    for ( var i = 0; i < objs.length; ++i )
    {
        var obj = objs.item(i);
        if ( obj.styleIndex == style_index )
        {
            obj.hidden = true;
        }
    }
}


- 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
 From:  shayno
11193.11 In reply to 11193.10 
Hi Michael
Do you have a donation box so I can give you some money ?
cheers
shayne
  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-11