Color Gradient script?
 1-4  …  45-64  65-84  85-92

Previous
Next
 From:  GonzoRus
9676.85 
I probably explain it wrong)

I need a simple script.

Just a fixed color. Color predefined in the script.

I understand color definition like this: red = XX, green = XX, blue = XX


1. all curves is assigned a color red = XX, green = XX, blue = XX (one fixed color)

2. the selected curves are assigned a color red = XX, green = XX, blue = XX (one fixed color)




only in MOI v.3 language for MOI to understand :)
Attachments:

  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:  bemfarmer
9676.86 In reply to 9676.85 
Hi GonzoRus,

I think that the desired colors need to exist in the Styles menu???

An existing script is:
code:
script: /*!Assign styles to curves */ var styles = moi.geometryDatabase.getObjectStyles(); var curves = moi.geometryDatabase.getObjects().getCurves(); var style_index = 0; for ( var i = 0; i < curves.length; ++i, ++style_index ) { if ( style_index == styles.length ) { style_index = 0; } var curve = curves.item(i); curve.styleIndex = style_index; }


By a minor edit to this existing script, try out the following experimental script.
(I changed color from Black to Red, and deleted incrementing ++style index.)

TRY
code:

script: /*!Assign RED style to ALL curves */ var styles = moi.geometryDatabase.getObjectStyles(); var curves = moi.geometryDatabase.getObjects().getCurves(); var style_index = 1; for ( var i = 0; i < curves.length; ++i ) { var curve = curves.item(i); curve.styleIndex = style_index; }



- Brian
I'll leave any more up to the experts.

EDITED: 19 Dec 2020 by BEMFARMER

  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:  GonzoRus
9676.87 
script: /*!Assign RED style to ALL curves */ var styles = moi.geometryDatabase.getObjectStyles(); var curves = moi.geometryDatabase.getObjects().getCurves(); var style_index = 1; for ( var i = 0; i < curves.length; ++i ) { var curve = curves.item(i); curve.styleIndex = style_index; }

This script does not work quite correctly. It makes ALL curves the same specified color (color 0, 1, 2, 3, etc.) existing in the Style Menu. BUT. "Undo" and "Redo" stop working for styles.



script: /*!Assign styles to curves */ var styles = moi.geometryDatabase.getObjectStyles(); var curves = moi.geometryDatabase.getObjects().getCurves(); var style_index = 0; for ( var i = 0; i < curves.length; ++i, ++style_index ) { if ( style_index == styles.length ) { style_index = 0; } var curve = curves.item(i); curve.styleIndex = style_index; }

This script does not work correctly, it assigns different colors to the curves)
  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:  bemfarmer
9676.88 In reply to 9676.87 
Hi GonzoRus,

I concur with you. The same failure to "save" to history occurs in both MoI3 and MoI4beta.
Pushing enable history seemed to make no difference.

A test with multiple color changes, MoI3 or MoI4beta:
Create a few Black curves, and save .3dm.
Change the color of the curves to Green, using Style menu.
Change the color of the curves to Purple, using Style menu.
Change the color of the curves to Magenta, using Style menu.
Change the color of the curves to Red, with the RED script, OR to multi-colors, with the "multi-color" script.
Change the color of the curves to white, using Style menu.
Undo History is not saving the RED colored curves, but History is saving all of the other colored curves, as per multiple pressing of undo.
Similar for Redo History.

- Brian

The same applies to the script which applies "rainbow" colors to solids.

I would call it normal behavior, but not the desired behavior?
Is there some way to enable history for these color scripts?

EDITED: 19 Dec 2020 by BEMFARMER

  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
9676.89 In reply to 9676.87 
Hi GonzoRus,

re:
> This script does not work quite correctly. It makes ALL curves the same specified color
> (color 0, 1, 2, 3, etc.) existing in the Style Menu. BUT. "Undo" and "Redo" stop working
> for styles.

Please give these versions a try:

/* Assign selected curves to style = Red */ var starting_selection = moi.geometryDatabase.getSelectedObjects(); var curves = starting_selection.getCurves(); moi.geometryDatabase.deselectAll(); curves.setProperty( 'selected', true ); var style = moi.geometryDatabase.findStyle( 'Red', false /*Create if not found*/ ); if ( style ) { moi.ui.propertiesPanel.editStyleIndex( style.index ); } moi.geometryDatabase.deselectAll(); starting_selection.setProperty( 'selected', true );

/* Assign all curves to style = Red */ var starting_selection = moi.geometryDatabase.getSelectedObjects(); var curves = moi.geometryDatabase.getObjects().getCurves(); moi.geometryDatabase.deselectAll(); curves.setProperty( 'selected', true ); var style = moi.geometryDatabase.findStyle( 'Red', false /*Create if not found*/ ); if ( style ) { moi.ui.propertiesPanel.editStyleIndex( style.index ); } moi.geometryDatabase.deselectAll(); starting_selection.setProperty( 'selected', true );

These use the properties panel mechanism for applying the style index, it's what is used when you assign a style by clicking on the style name in the properties panel and it does the extra work to set up an undo unit to make it work with undo. The properties panel only modifies the current selection so for the version that does all curves it modifies the selection first and then restores it afterwards.

- 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:  GonzoRus
9676.90 
Thanks Michael!

Everything works great with your scripts.

Undo and Redo work great. Thank you!)
  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:  bemfarmer
9676.91 In reply to 9676.89 
Both shortcuts work!

A minor observation:

For customUI shortcuts "gearpair" icon menu, add the ! i.e. /*!

Also, the second comment /*Create if not found*/ causes the customUI gearpair icon to display all of the code up to the last */, which is a long line of text in the menu.
so I removed the second comment /*Create if not found*/, in the installed shortcut.

- Brian
  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:  GonzoRus
9676.92 
Script for assigning "Magenta" color to selected faces.

code:
/* Assign selected faces to style = Magenta */ var starting_selection = moi.geometryDatabase.getSelectedObjects(); var faces = starting_selection.getFaces(); moi.geometryDatabase.deselectAll(); faces.setProperty( 'selected', true ); var style = moi.geometryDatabase.findStyle( 'Magenta', false /*Create if not found*/ ); if ( style ) { moi.ui.propertiesPanel.editStyleIndex( style.index ); } moi.geometryDatabase.deselectAll(); starting_selection.setProperty( 'selected', true );


"Magenta" can be changed to any color from the existing styles.
  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:  1-4  …  25-44  45-64  65-84  85-92