MoI discussion forum
MoI discussion forum

Full Version: V4 released!

Show messages:  1-8  …  69-88  89-108  109-128  129-148  149-168  169-188

From: Michael Gibson
11 May 2021   [#129] In reply to [#128]
HI Marco, if you show it as a dialog it's possible for a dialog to implement a function OnKeyDownEvent( event ) in it which will give it a chance to process keyboard events if it is the current focus window. There's an example of that in ShortcutKeyDialog.htm .

So for your case where you want it to hide on any keystroke, you could implement this script function inside the page:

code:
			function OnKeyDownEvent( e )
			{
				moiWindow.close();
			}


Then for showing your UI use moi.ui.createDialog( 'DialogUrl.htm' ); instead of showMenu().

Does that work?

I'll see about making the keyboard event processing work for flyout menus as well as dialogs for v5.

- Michael
From: mkdm
11 May 2021   [#130] In reply to [#129]
Thanks Michael for your tip.

But...no, I'm sorry, It doesn't work properly.

let me explain...

If I use your suggested "OnKeyDownEvent" and I open the popup as a DIALOG, ok, it works.
But ONLY for single keystrokes.
But most of my shortcuts are a combination of a key and qualifiers, and if I use OnKeyDownEvent, as soon as I press a qualifier, the dialog closes.

So I've tried the OnKeyUpEvent instead.

But, if open the popup ad DIALOG, it immediately gets the focus, and while I'm releasing the A key (that opens the dialog) it automatically closes.

SO, I'VE FOUND THIS PARTIAL SOLUTION:

I open the popup NOT as a dialog BUT as a MENU with showMenu(...) and I use the OnKeyUpEvent so I can handle the shortcuts that are combination of a key and qualifiers.
And all works fine :)

But now I only would need that the popup menu could gets automatically the FOCUS as soon it open.
Because if I don't first click inside it, but only press any of the keyboard shortcuts, the related command starts, but the popup menu doesn't close.
Instead, if I first click inside it, then when I press a keyboard shortcut, the popup menu close correctly.




Thanks for your help.
From: Michael Gibson
11 May 2021   [#131] In reply to [#130]
Hi Marco,

re:
> But now I only would need that the popup menu could gets automatically the FOCUS as soon it open.

Unfortunately this does not happen with a popup menu, it's because it uses the Qt popup mechanism. When Qt shows a popup window all key events are sent to it regardless of what window has the current focus.

I've fixed this up for v5 so that popup windows will get the script keyboard events sent to them always but for v4 it's only reliable on a dialog not on a menu.


> But most of my shortcuts are a combination of a key and qualifiers, and if I use
> OnKeyDownEvent, as soon as I press a qualifier, the dialog closes.

Your OnKeyDownEvent() handler could look at what key the event is for and if it's for a modifier don't close the window. There is documentation on the event properties in ShortcutKeyDialog.htm .

- Michael
From: Michael Gibson
11 May 2021   [#132] In reply to [#130]
Hi Marco, also maybe it would be easier to handle launching commands inside of OnKeyDownEvent/OnKeyUpEvent , bypassing the regular keyboard shortcut launcher. To do that set event.handled = true; that will prevent Moi from doing anything further with that key event.

Your event handler can call moi.command.execCommand( 'command_name' ); to launch a command itself.

- Michael
From: mkdm
11 May 2021   [#133] In reply to [#131]
Hello Michael.

Ok. Thanks for the tips.

re
> Your OnKeyDownEvent() handler could look at what key the event is for...

I'll try it asap, and I'll let you know.

re:
> I've fixed this up for v5...

Maybe you could publish some intermediate versions like 4.x.y
I said this because it would be good for us if you'll be able to publish new versions with small useful changes, rather than wait for a long period before you can publish another major version.

re:
> ...bypassing the regular keyboard shortcut launcher....

Ok. I'll try also this tip, and I'll let you know.

Thanks.
From: Michael Gibson
11 May 2021   [#134] In reply to [#133]
Hi Marco,

re:
> Maybe you could publish some intermediate versions like 4.x.y

It's not easy for me to do that because I don't want to make a final release version that has not had some time spent in beta release first to try and avoid regressions,. The next beta release will be for v5 so that's where changes like this will be going into.

- Michael
From: mkdm
13 May 2021   [#135] In reply to [#132]
Hello Michael.

So...after your suggestion, I nailed it :)

I open my custom UI in a pop-up dialog and I manage all the shortcuts is this way:

code:
<script>
	var cmds = [];
	cmds[parseInt("0x31")] = "line";
	cmds[parseInt("0x32")] = "curve";
	... other commands ...

	var cmdsAlt = [];
	cmdsAlt[parseInt("0x31")] = "polyline";
	cmdsAlt[parseInt("0x32")] = "interpcurve";
	... other commands ...

	var cmdsCtrl = [];
	cmdsCtrl[parseInt("0x35")] = "circletangent";
	cmdsCtrl[parseInt("0x36")] = "arccontinue";
	... other commands ...

	var cmdsShift = [];
	cmdsShift[parseInt("0x32")] = "sketchcurve";
	cmdsShift[parseInt("0x33")] = "rect3pts";
	... other commands ...

	function OnKeyDownEvent(e) {
		e.handled = true;

		var cmdName = null;

		if (e.shift) {
			cmdName = cmdsShift[e.keyCode];
		} else if (e.ctrl) {
			cmdName = cmdsCtrl[e.keyCode];
		} else if (e.alt) {
			cmdName = cmdsAlt[e.keyCode];
		} else {
			cmdName = cmds[e.keyCode];
		}

		if (!cmdName) {
			return;
		}
		
		moi.command.execCommand(cmdName);

		moiWindow.close();
	}
</script>


Then I also use a "fake" class to attach the "moiWindow.close();" command to all the moi:CommandButton that I use in the dialog:

code:
<moi:CommandButton class="myCmd" ...

<script type="text/javascript">
	var buttons = document.querySelectorAll(".myCmd");

	for (var i = 0; i < buttons.length; i++) {
	   buttons[i].addEventListener("click", function (event) {
	       moiWindow.close();
	   });
	}
</script>



I hope you will ad soon the capability of trapping key event also in pop-up menu.

Thanks and have a nice day.
From: Michael Gibson
13 May 2021   [#136] In reply to [#135]
That's great Marco, I'm glad that is working!

- Michael
From: mkdm
14 May 2021   [#137] In reply to [#136]
Hello Michael.

A quick (for you) help, if you can.

I need a very quick inline script that have to do the following:

Select all objects (solids or surfaces) that belongs to the currently selected edges (and, at the same time, deselect the input selected edges)

Could you tell me?

Thanks and have a nice day.
From: mkdm
14 May 2021   [#138] In reply to [#136]
Helo Michael.

I'm sorry if I ping you again...

Could you help with the little inline script I asked for?
(you can find the answer in my previous message)

Thanks.
From: Michael Gibson
14 May 2021   [#139] In reply to [#137]
Hi Marco,

re:
> Select all objects (solids or surfaces) that belongs to the currently selected edges (and, at
> the same time, deselect the input selected edges)

You can get the selected edges using this:
code:
var edges = moi.geometryDatabase.getSelectedObjects().getEdges();

Then you'll want to loop through every edge something like this:
code:
for ( var i = 0; i &lt; edges.length; ++i )
{
var edge = edges.item(i);
....
}

To deselect the edge you would do:
code:
edge.selected = false;

To get the parent surface or solid of the edge you would do:
code:
edge.getParentBRep();

So putting that all together it would go something like this:

code:
var edges = moi.geometryDatabase.getSelectedObjects().getEdges();
for ( var i = 0; i < edges.length; ++i )
{
   var edge = edges.item(i);
   edge.selected = false;
   edge.getParentBRep().selected = true;
}


Hope that helps! - Michael
From: mkdm
14 May 2021   [#140] In reply to [#139]
Perfect Michael!

Exactly what I needed.
Thanks!

One question...

Trying to write some new scripts for my very personal workflow, I've seen that the version of JS that Moi can interpret is rather...aged.
I can't use any modern construct or technique of ES6 like, arrow functions, let and const, deconstructing and so on...

Which version of JS Moi is capable of?

Are you thinking of support newer and more modern version of JS?

Thanks again.
From: Michael Gibson
14 May 2021   [#141] In reply to [#140]
Hi Marco, I'm glad that was what you needed.


> Which version of JS Moi is capable of?

I think it's ECMAScript5.


> Are you thinking of support newer and more modern version of JS?

No, currently I don't have any specific plans for that.

- Michael
From: mkdm
14 May 2021   [#142] In reply to [#141]
re > No, currently I don't have any specific plans for that.

..Pity

ES6 has a very good sets of other modern programming languages paradigm.

Anyway. Thanks for the reply.

Message 10083.143 was deleted


From: pokoy (MARCIN)
19 May 2021   [#144] In reply to [#1]
I totally missed the v4 release as I have lost the track but here's my belated congrats and a big thank you!
V4 managed to open files that I couldn't import in my main DCC app so it's already helped me within the first 10 minutes after the purchase :D

Also, it's nice to see that this place still is as cozy and warm as it was years ago.
Michael, thank you again for MoI3d and stay safe and healthy!
From: mkdm
19 May 2021   [#145] In reply to [#1]
Hello Michael.

I ask you a little help to do the followings two things, because I don't know where I could find this documentation.

FIRST question:
In one of my scripts, I need to programmatically and temporarily set to "FixedColor" this two settings:

code:
moi.view.surfaceColorMode
moi.view.edgeColorMode


But none of the attempts that I show you here worked out.

code:
moi.view.surfaceColorMode = "FixedColor";
moi.view.edgeColorMode = "FixedColor";

moi.view.surfaceColorMode = 0;
moi.view.edgeColorMode = 1;

moi.view.surfaceColorMode = "Fixed color";
moi.view.edgeColorMode = "Fixed color";

moi.view.surfaceColorMode = "FixedColor";
moi.view.edgeColorMode = "FixedColor";


Also I can't figured out how to revert to the original state:
code:
moi.view.surfaceColorMode = "ByStyle";
moi.view.edgeColorMode = "ByStyle";


None of them did work.

What I have to write in the code?

SECOND question:

I need to put in an javascript array ALL the NAMED objects. That is, ALL the objects that have a NAME explicitly set by the user.

What is the Moi'API call to use?




Thanks and have a nice day.
From: Michael Gibson
19 May 2021   [#146] In reply to [#145]
Hi Marco,

re:
> But none of the attempts that I show you here worked out.

Your code is working ok for me over here. Here is what I tested:

moi.view.surfaceColorMode = "FixedColor";
moi.view.edgeColorMode = "FixedColor";

moi.ui.alert( moi.view.surfaceColorMode ); // Says "FixedColor".
moi.ui.alert( moi.view.edgeColorMode ); // Says "FixedColor";

moi.view.surfaceColorMode = "ByStyle";
moi.view.edgeColorMode = "ByStyle";

moi.ui.alert( moi.view.surfaceColorMode ); // Says "ByStyle".
moi.ui.alert( moi.view.edgeColorMode ); // Says "ByStyle".


re:
> I need to put in an javascript array ALL the NAMED objects. That is, ALL the objects that have a NAME explicitly set by the user.
>
> What is the Moi'API call to use?


Call moi.geometryDatabase.getObjects() to return an object list of all objects, then go through and test each object's .name property.

Something like:

var objs = moi.geometryDatabase.getObjects();
var names = [];

for ( var i = 0; i < objs.length; ++i )
{
var obj = objs.item(i);
if ( obj.name )
names[ obj.name] = true;
}

- Michael
From: mkdm
19 May 2021   [#147] In reply to [#146]
Hi.

re:
> "Your code is working ok for me over here."

Hmmm...strange thing :) It didn't work for me.
Ok. I'l try it one more time

Thanks for the other reply also.
From: mkdm
20 May 2021   [#148] In reply to [#146]
OK :)

I managed how to achieve what I want.

I discovered that (it seems) the problems is that after calling:

code:
moi.view.surfaceColorMode = "FixedColor";
moi.view.edgeColorMode = "FixedColor";


the current active viewport (in my case the "3D" viewport) doesn't do a "refresh", so the objects still looks like before.

But, instead, if I other two lines of code, all works as excpeted:

code:
moi.view.surfaceColorMode = "FixedColor";
moi.view.edgeColorMode = "FixedColor";

// just to FORCE the refresh of the active viewport
moi.geometryDatabase.selectAll();
moi.geometryDatabase.deselectAll();


So, now it works.
Anyway...am I using the correct solution?

Thanks.

Show messages:  1-8  …  69-88  89-108  109-128  129-148  149-168  169-188