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
|