Hi Flowgun,
re:
> - if a single object is named, select naked edges should hold higher priority.
So the consequence of doing this is that if you have a named object and it's the only one with that name, that the "cycle between named objects" mechanism will get stuck when it hits this object since it will try to select naked edges when the selection is on it rather than continuing with the named object cycling.
> Otherwise, to avoid conflicts, and even offer more options, the script can be broken into 3:
> - one for dealing with objects: selects last-created objects if nothing is selected, otherwise
> looping through named objects (and it wouldn't matter if they are curves or not)
> - one for selecting edges (naked edges or edge loops / boundaries)
> - one to select curves: it would loop through selecting open curves, closed curves, and all curves. even if nothing is selected.
Do you have all the pieces you need to compose these 3 scripts yourself?
Maybe if you get stuck on a particular part I can help you with that particular part instead of trying to create the whole script myself, because there have just been way too many changes for me to keep track of, sorry.
For selecting the last created you already showed the code to do that above. There is also this method:
moi.geometryDatabase.selectLastCreated();
I have an update here though which fixes up the named object cycling so that if some but not all of a named object set are selected it gets all of the current name first before stepping to the next name:
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 a named object is selected, deselect it and select the next one */
if ( !done )
{
var objects = [], name_index = [];
for ( var i = 0; i < all_objs.length; ++i )
{
var obj = all_objs.item(i);
var name = obj.name;
if ( name )
{
if ( name_index[name] == undefined )
{
name_index[name] = objects.length;
objects.push( [] );
}
var index = name_index[name];
objects[index].push( obj );
}
}
function sortfunc( a, b )
{
var a_name = a[0].name;
var b_name = b[0].name;
return a_name.localeCompare(b_name);
}
objects.sort( sortfunc );
var index_to_select = -1;
for ( var i = 0; i < objects.length && index_to_select == -1; ++i )
{
var obj_array = objects[i];
for ( var j = 0; j < obj_array.length && index_to_select == -1; ++j )
{
var obj = obj_array[j];
if ( obj.selected )
{
var any_unselected = false;
for ( var k = 0; k < obj_array.length; ++k )
{
if ( !obj_array[k].selected )
{
any_unselected = true;
break;
}
}
if ( any_unselected )
index_to_select = i;
else
index_to_select = (i+1) % objects.length;
}
}
}
if ( index_to_select != -1 )
{
moi.geometryDatabase.deselectAll();
var obj_array = objects[index_to_select];
for ( var i = 0; i < obj_array.length; ++i )
{
var obj = obj_array[i];
obj.selected = true;
}
done = true;
}
}
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 surfaces 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();
}
}
- Michael