Single script to select different things
 1-11  12-31

Previous
Next
 From:  Michael Gibson
11127.12 In reply to 11127.11 
Hi Flowgun,

re:
> - if a single object is selected: selects its naked edges. if it has none, it can simply deselect it.

What if the single selected object is named?


> Edit: another behavior: if nothing is selected, then select the result of the last operation:

That conflicts with another condition that you specified originally which was this:

> if nothing is selected {
> // select all curves


= 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:  Flowgun
11127.13 In reply to 11127.12 
yup.
I'm aware of these conflicts. I meant to update old requests with new ones.
there are probably still more conflicts incoming though. I'm tired, boss xD

Maybe it's not that wise to try to cram everything together after all.

to continue with the effort for a holistic script:
- if a single object is named, select naked edges should hold higher priority.
Single objects are easily selectable from the viewport, and if the wanted result is to select
multiple named object, then selecting a couple of them and hitting the hotkey would select
all the rest.
- "Select all curves": only if an unnamed curve is selected.

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.

these 3 scripts can check first for selected edit points to select the rest of them.
they can be set for example to tilde, alt+tilde, and ctrl+tilde.
That's already lot neater and easier to keep up with than my older config with around 10 hotkeys for selection that I never got used to.
and I believe it's more user-friendly and more predictable than the all-in-one problematic solution.
  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
11127.14 In reply to 11127.13 
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
  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
11127.15 In reply to 11127.13 
So if you wanted to give the select naked edges part priority over the named object handling, take this piece:

code:
	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 );
		}
	}


Remove the "else" at the start there and insert a done = true; inside it, and move it above the named object handling which starts at this comment:
/* If a named object is selected, deselect it and select the next one */

And if you want it to do naked edges if only one object is selected change this:
if ( selected_objs.numBReps > 0 )
to this:
if ( selected_objs.numBReps == 1 )


But like I mentioned, if you do that then if you have a solid that is a named object and it is the only object with that name, the "step to next named object" is going to get stuck on it.

= 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:  Flowgun
11127.16 In reply to 11127.15 
Thank you a lot, Michael.
With this, I should have all the pieces I need.
sorry for asking too much.
I appreciate you.

- Flowgun
  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
11127.17 In reply to 11127.13 
Some more pieces to use for the 3 separate scripts:


> - 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)

Nothing selected is detected like this:

code:
var selected_objs = moi.geometryDatabase.getSelectedObjects();

if ( selected_objs.length == 0 )
{
        .....
}


Selecting last created objects is: moi.geometryDatabase.selectLastCreated();

Stepping through named objects is the chunk of the script above that follows this:

/* If a named object is selected, deselect it and select the next one */


> - one for selecting edges (naked edges or edge loops / boundaries)

Selecting naked edges is the part of the script above with:
/* If surfaces are selected, select their naked edges */

Selecting edges of a face is this part:
/* 1 face selected, select edges of face */

Loop selection is this part:
/* If any edges are selected do loop selection */


> - one to select curves: it would loop through selecting open curves, closed curves, and all curves. even if nothing is selected.

Selecting all curves is the part marked with this:
/* If nothing selected, select all curves */

to select just open or closed curves, that would be like this:

code:
var curves = moi.geometryDatabase.getObjects().getCurves();

for ( var i = 0; i < curves.length; ++i )
{
    var crv = curves.item(i);
    if ( crv.isClosed )
        crv.selected = 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
Next
 From:  Flowgun
11127.18 In reply to 11127.17 
Here's what I came up with for now. It's not perfect, but still very useful:
code:
script: var selected_objs = moi.geometryDatabase.getSelectedObjects();
var all_objs = moi.geometryDatabase.getObjects();
var done = false;

if ( selected_objs.length == 0 )
{
	/* If nothing selected, select last-created object */
	moi.geometryDatabase.selectLastCreated();
	done = true;
}
else if ( selected_objs.numBReps > 0 )
	{
		/* If only joined surfaces are selected, select their naked edges */
		selected_objs.setProperty( 'selected', false );

		var breps = selected_objs.getBReps();
		var allNaked = true;
		
		for ( var i = 0; i < breps.length; ++i )
		{
			var brep = breps.item(i);
			if (brep.getNakedEdges().length == 0)
				allNaked = false;
		}
		if (allNaked)
		{
			for ( var i = 0; i < breps.length; ++i )
			{
				var brep = breps.item(i);
				var naked = brep.getNakedEdges();
				if (naked.length> 0)
					naked.setProperty( 'selected', true );
			}				
			done = true;
		}			
		else
			selected_objs.setProperty( 'selected', true );
}

/* If some points on a curve are selected, select the rest */
if ( !done )
{
for ( var i = 0; i < all_objs.length; ++i )
{
	var obj = all_objs.item(i);
	if ( obj.isCurve && obj.hasSelectedEditPoints ) /* this only works in latest versions */
	{
		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.numStandaloneCurves> 0 )
	{
		/* If some curves are already selected, we loop through curve selection. */
		var curves = moi.geometryDatabase.getObjects().getCurves();
		var allSelected = true;
		var closedCurves = true;

		for ( var i = 0; i < curves.length; ++i )
		{
			var crv = curves.item(i);
			if (! crv.selected)
			{
				allSelected = false;
				if ( crv.isClosed)
					closedCurves = false;
			}
		}
		selected_objs.setProperty( 'selected', false );

		if (allSelected)
		{
			for ( var i = 0; i < curves.length; ++i )
			{
				var crv = curves.item(i);
				if (crv.isClosed)
				crv.selected = true;
			}
		}
		else if (closedCurves)
		{
			for ( var i = 0; i < curves.length; ++i )
			{
				var crv = curves.item(i);
				if (! crv.isClosed)
					crv.selected = true;
			}
		}
		else /* select all */
		{
			curves.setProperty( 'selected', true );
		}
	}
	else if ( selected_objs.length> 0 && selected_objs.numFaces >= selected_objs.length )
	{
		/* faces selected, select the edges of the faces */
		for ( var i = 0; i < selected_objs.numFaces; ++i )
		{
			var face = selected_objs.item(i);
			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();
	}
}



// - Flowgun


Edited by Michael - convert // comments into /* */ and add a couple missing semi-colons so it can work pasted into a single line as a shortcut key.

EDITED: 14 Jul 2023 by MICHAEL GIBSON

  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
11127.19 In reply to 11127.18 
Hi Flowgun, thanks for sharing it. I edited your post to put it inside of <code></code> so it would show tabs.

- 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:  Psygorn (DRILLBIT)
11127.20 In reply to 11127.19 
Hi Michael,

With this script one can select loop of edges?

How about edges that are connected to a face?

I should assign a short key to this script, if I want to use it?

- Psygorn
  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
11127.21 In reply to 11127.20 
Hi Psygorn,

re:
> With this script one can select loop of edges?

It looks like it is set to select a boundary loop if you have edges selected before running it.


> How about edges that are connected to a face?

Looks like if you have faces selected it will select the edges of the face.


> I should assign a short key to this script, if I want to use it?

Yes set up a shortcut key under Options > Shortcut keys and copy/paste in the above script for the "command" part of the shortcut key.

- 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:  Psygorn (DRILLBIT)
11127.22 In reply to 11127.21 
Hi Michael,

I did what we usually do to assign a short key to MOI commands/scripts but I get this massive Error!



I want to have the effect you can see here: https://www.youtube.com/watch?v=9DBqE_CX7Zo (after 0:55 of the video you can see my desired effects; How can I have these? )

- Psygorn
  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
11127.23 In reply to 11127.22 
Hi Psygorn, there were a couple of things in there that was preventing it from working when pasted into a single line, try getting it again.

- 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:  Psygorn (DRILLBIT)
11127.24 In reply to 11127.23 
Hi Michael,

I tried getting it again and it works (No Error now)

But I cannot replicate the effect in the YouTube Video I sent to you earlier!

For example when I have a face selected it cannot select edges that are in contact with the selected face!

I am using this script for a long time now it selects edges of a selected face "script: /* Select edges v1.4 */ var gd=moi.geometryDatabase, so=gd.getSelectedObjects(); function ss(o,v){o.setProperty("selected",v)} function sl(o){ for ( var i=0; i<o.length; ++i ) o.item(i).getEdges().invertProperty("selected");} gd.selectLoop(); sl(so.getFaces()); sl(so.getSolids()); sl(so.getOpenBReps()); sl(so.getSingleFaceBReps()); ss(so.getBReps(),0); ss(so.getFaces(),0);"

But I want to have more than that and be able to select edge loops as well as corner edges (like the YouTube video) I appreciate your help in advance :-)

- Psygorn
  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
11127.25 In reply to 11127.24 
Hi Psygorn,

re:
> For example when I have a face selected it cannot select edges that are in contact with the selected face!

That's working ok for me over here. For example when I have this face of a box selected:


When triggering the script it results in this edge selection:



If you're not able to get that result, can you please post your moi.ini file so I can see if you've got the entire script in there? You can find your moi.ini file's location by going to Options > General > "Edit .ini file" button. A dialog will pop up and show you the location of the moi.ini file.

- 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:  Psygorn (DRILLBIT)
11127.26 In reply to 11127.25 
Hi Michael,

I want this effect:



and this one:



In a YouTube video which you can find it here: https://www.youtube.com/watch?v=9DBqE_CX7Zo it is mentioned in MOI V5 there are new features and from 00:55 seconds afterwards the above features are shown!
I saw the video and I thought I would want those features too. So, I reached out to you. :-)

- Psygorn
  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
11127.27 In reply to 11127.26 
Hi Psygorn, what you show there are not new features for MOI v5, they are features of some scripts that the person making those videos has made.

> I saw the video and I thought I would want those features too. So, I reached out to you. :-)

You'll need to reach out to them, those are not built in functions in MoI as of yet.

- 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:  Psygorn (DRILLBIT)
11127.28 In reply to 11127.27 
Hi Michael,

Oh, Ok :-)

Thank you.

- Psygorn
  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:  Frenchy Pilou (PILOU)
11127.29 In reply to 11127.28 
It's external plugings like the Max Smirnov like! ;)
---
Pilou
Is beautiful that please without concept!
My Moi French Site My Gallery My MagicaVoxel Gallery
  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:  pressure (PEER)
11127.30 In reply to 11127.28 
Hi Psygorn,

The corner edges plugin is here:

http://moi3d.com/forum/index.php?webtag=MOI&msg=11063.1

The tangent propagation shown in the video is probably using "_ExpandSelectionTangecy" from here:

http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=8665.195

- Peer
  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:  Psygorn (DRILLBIT)
11127.31 In reply to 11127.30 
Thanks PEER,

- Psygorn
  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-11  12-31