Single script to select different things

 From:  Michael Gibson
11127.4 In reply to 11127.3 
Hi Flowgun,

re:

> - curve selection: if some curves are already selected, it selects the rest of curves also.

Updated version below should do this now.


> - Group selection: I use your script that groups selected objects by name (object_0001, object_0002,..).
> Is it possible to make this script loop through named objects? (if one group is selected / nothing is selected)?

Sorry I'm not understanding what you want with this part, can you describe it in some more detail please?


> - point selection: if some points on a curve are selected, it selects the rest.

This is in the updated version below.


> also, I noticed that if more than one object is selected, the script does nothing.
> Maybe it would be useful to select the naked edges of all selected objects

This should also be in the updated version below.

- Michael


code:
script: var selected_objs = moi.geometryDatabase.getSelectedObjects();
var all_objs = moi.geometryDatabase.getObjects();
var done = false;

/* If some points on a curve are selected, select the rest */

for ( var i = 0; i < all_objs.length; ++i )
{
	var obj = all_objs.item(i);
	if ( obj.isCurve && obj.hasSelectedEditPoints )
	{
		moi.geometryDatabase.selectAll();
		done = true;
		break;
	}
}

if ( !done )
{
	if ( selected_objs.length == 0 )
	{
		/* If nothing selected, select all curves */
		moi.geometryDatabase.getObjects().getCurves().setProperty( 'selected', true );
	}
	else if ( selected_objs.numStandaloneCurves > 0 )
	{
		/* If some curves are already selected, select the rest of the curves. */
		moi.geometryDatabase.getObjects().getCurves().setProperty( 'selected', true );
	}
	else if ( selected_objs.numBReps > 0 )
	{
		/* If breps are selected, select their naked edges */
		selected_objs.setProperty( 'selected', false );

		var breps = selected_objs.getBReps();
		for ( var i = 0; i < breps.length; ++i )
		{
			var brep = breps.item(i);
			brep.getNakedEdges().setProperty( 'selected', true );
		}
	}
	else if ( selected_objs.length == 1 && selected_objs.numFaces == 1 )
	{
		/* 1 face selected, select edges of face */
		var face = selected_objs.item(0);
		face.selected = false;
		face.getEdges().setProperty( 'selected', true );
	}
	else if ( selected_objs.numEdges > 0 )
	{
		/* If any edges are selected do loop selection */
		moi.geometryDatabase.selectLoop();
	}
}