Automatically select last created object(s) when the operation ends?

Next
 From:  Flowgun
10650.1 
Hello everyone,

so, since I usually make operations to newly created objects, especially curves, I wanted to add the functionality of automatically selecting them to certain commands.
I don't understand programming well enough to achieve this. For example, I tried combining the Rectangle script with the "select Last created objects" script, but the best result I was able to obtain is to select the previously created object and not the newly created one when I confirm (I guess the function gets compiled before so it doesn't register the last one?).

Anyways, I'm pretty sure there's a very simple way to do it. I tried a "setTimeout()" in case it needs delay to grab the newly created object, but this function is not supported in MoI.
I tried to study the code of various scripts in order to find a way, and even find resources about MoI API as I was ready to take a deep dive into it, but it seems that most resources are no longer available.

I think that it would be great if objects get automatically selected after creation by default. Especially curve objects since oftentimes they are directly followed by an operation to them.
For future updates, maybe confirming with Middle mouse button would keep the objects selected. that would be an awesome functionality, no?

otherwise, for a script that exits with the newly created objects selected, I can conceive like 3 main scenarios that might need different scripts:
* nothing else is selected during creation: no issues - just select the newly created one. this doesn't interfere with other cases at all.
* there's a selection:
- overwrite it: I guess this is the wanted behavior in most cases - it avoids accidently doing operations to other elements in the scene.
- add to it: such a script can be useful for example after array operations, as the older object(s) are part of the whole.
- keep it and exit without affecting initial selection (the current Default): I guess this would be a rarely needed, but you can't blame someone for being too precious about his selection.

* Another awesome feature would be undo/redo scripts that keep objects as they are and undo/redo only selections. This would take MoI's selection capabilities to the next level.

I hope Michael or anyone can help me with this, and I hope that my feedback is useful =)
  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
10650.2 In reply to 10650.1 
Hi Flowgun, the difficulty in what you're describing is that it isn't a single script that would just run
when you push a shortcut key. What you are describing would need your custom script code to run
after every single command has been run.

There is not currently any mechanism in MoI that is set up like that to run custom script after
every command.

It is possible to modify individual commands to do it though, like for Rectangle like you were
trying, the current Rectangle.js command has this:

code:
#include "GetRect.js"
#include "GetRectRoundCorner.js"

var factory = moi.command.createFactory( 'rectangle' );
	
if ( GetRect( factory )
	&& GetRectRoundCorner( factory, factory.getInput(0).getValue(), 4 ) )
{
	factory.commit();
}


You can modify this by adding one line before the factory.commit() like this:

code:
#include "GetRect.js"
#include "GetRectRoundCorner.js"

var factory = moi.command.createFactory( 'rectangle' );
	
if ( GetRect( factory )
	&& GetRectRoundCorner( factory, factory.getInput(0).getValue(), 4 ) )
{
	factory.getCreatedObjects().setProperty( 'selected', true );
	factory.commit();
}


I don't really recommend changing every command though, because you will run into
problems later on down the line when commands change with new features added to them.


re:
> Another awesome feature would be undo/redo scripts that keep objects as they are
>and undo/redo only selections. This would take MoI's selection capabilities to the next level.

I specifically chose not to do it this way because then there would need to be 2 different kinds
of undo/redo to trigger and that's a good example of the kind of complexity and UI bloat that
I've worked very hard to avoid with MoI.

So there is a selection undo in MoI but it's part of the regular undo and it only applies
to the most recent selection action.

- 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
10650.3 In reply to 10650.1 
Hi Flowgun,

re:
> * nothing else is selected during creation: no issues - just select the newly created one. this
> doesn't interfere with other cases at all.

But the problem is that it does interfere with things in subtle ways.

Here's a simple scenario - you want to draw in a line with the intention of using it as the cutting object in boolean difference.

But boolean difference doesn't just work on a single selection, it needs 2 separate selections, one for the base objects and then a second selection step where you give it the cutting objects.

If a newly drawn line was selected automatically you now need to do an extra step to deselect it before you can run boolean difference because it needs to be selected as a cutting object not as a base object.

It's just not the case that it would universally be helpful to alter the selection like that.

- 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
10650.4 In reply to 10650.2 
Thank you for the quick reply. this is exactly what I was looking for.

For exiting with selection when nothing is selected, you are right. I didn't think it through well enough.
Boolean difference between a curve and a surface/solid would provide a similar result as a boolean merge. maybe MoI can smartly differentiate between that, or maybe, even better and easier, invert the operations to select the cutter first and then the target object (Blender-Style)? wouldn't that save the sea turtles from snorting all the disregarded mouses due to the extra clicks? I think this can be a bit more streamlined in one way or another, but I guess lots of complexity may arise with multiple objects and so on, so I don't know. I trust your judgment.

I will experiment with both methods and see. I feel that clicking anywhere in the 3d space to deselect and proceed would be faster and more care-free than having to precisely click the created object for selection. This would certainly be faster after arraying on a big surface (better than having to ctrl+shift+click and drag left to right from the right angle).

Thank you for that line of code.

Happy Weekend =)
  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
10650.5 In reply to 10650.4 
Hi Flowgun, I'm glad that line of script was helpful!

re:
> or maybe, even better and easier, invert the operations to select the cutter first
> and then the target object (Blender-Style)? wouldn't that save the sea turtles from
> snorting all the disregarded mouses due to the extra clicks?

No, the sea turtles would be upset at that because it would violate one of their design
goals of prioritizing MoI to be easy to use and quick to learn.

One element of that is having commands operate in a consistent manner. In MoI
this is applied by this design rule - commands that modify objects select the object to
be modified first and any supplementary stages after that.

- 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
 From:  Flowgun
10650.6 In reply to 10650.5 
UPDATE:

I was able to set up my hotkeys with Autohotkey to be "Spring-loaded", as Adobe calls them.
For me, H is rectangle, J is circle, K is polygon, and L is line (across most Software that I use).
Pressing the key just sends it once. Holding it for more than 200 milliseconds keeps it waiting, and once I release it, it sends the hotkey associated with "Select Last Created Object" Script.

This way, I get the best of both worlds.

It can be done with "Extrude" too. If it's kept held, then it'll send "Delete" after the release, removing the original curves.

The possibilities are endless. It's a matter of preference at this point.

Hope this helps. Cheers.
  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