MoI discussion forum
MoI discussion forum

Full Version: Selection questions

Show messages:  1-20  21-22

From: Bravlin
23 Nov 2018   [#1]
I have a couple of questions about moi3d selection, API classes, attributes and logic.
To not spread amongst different threads i guess it's better to ask them in one thread here.

Q_01:
There are couple scripts that converts current select from faces to edges.
But i didn't find scripts that converts selected edges to faces.
Does edge object have attribute like neighbor or connected faces to query ?
I didn't find it in maxsm's sdk: http://moi.maxsm.net/api/
Or maybe i should use different approach to it.
From: Michael Gibson
23 Nov 2018   [#2] In reply to [#1]
Hi Bravlin,

> Does edge object have attribute like neighbor or connected faces to query ?

Yes, there's a .getFacesOfEdge() function on curves - if it is an edge curve it will return a list of faces that use that edge curve as part of its trimming boundary.


> I didn't find it in maxsm's sdk: http://moi.maxsm.net/api/

It's there but it's under Curve, an edge curve and a "standalone" curve both use the same Curve interface.

- Michael
From: Bravlin
26 Nov 2018   [#3] In reply to [#2]
Thank you Michael.
Its strange that such a simple script doesn't mentioned in a script lists. Or maybe i'm just bad at searching.


From: Bravlin
27 Nov 2018   [#4]
Q_02:
is it posible to query current active <Style> if no objects currently selected ?
In other words get this Style index from UI or some other way.

Image Attachments:
pic1_proc.jpg 


From: bemfarmer
27 Nov 2018   [#5] In reply to [#4]
Try clicking arrow to right of Style title?
From: Michael Gibson
27 Nov 2018   [#6] In reply to [#4]
Hi Bravlin, do you mean you want to get that through script?

That is at:

moi.geometryDatabase.activeStyle

That will get or set the style index value of the active style where newly created objects will go.

To set it through the UI, right-click on the swatch.

- Michael
From: Bravlin
28 Nov 2018   [#7]
Yes. Through the script indeed.

Here is a small script to unhide all objects of active layer.
But its kind slow because of a mesh&solids unhide workaround.

From: Michael Gibson
28 Nov 2018   [#8] In reply to [#7]
Hi Bravlin, the slow part might be that when showing a brep object it will need to create a display mesh for it if it has never been displayed before.

Probably just the iteration through sub-objects shouldn't be too slow, an alternative though to doing a loop like that is to use:

obj.getSubObjects().setProperty( 'hidden', false );

That will still do a loop like you're doing in script but the loop will be in internal C++ code.

- Michael
From: Bravlin
28 Nov 2018   [#9] In reply to [#8]
Oh its nice.
By the way maybe you share a couple of words or links about Moi architecture ?
What levels it have. How does .js plugins processed. I am trying to understand the plugin development process for MOI.
I guess i am spoiled by Autodesk reach SDK. But without one the customization goes via "guess and try" method.
I am not big in development, but have some experience in C++ for Softimage.
From: Michael Gibson
28 Nov 2018   [#10] In reply to [#9]
Hi Bravlin, well the layers are that the inner core is C++ compiled code and the UI is implemented in HTML and JavaScript which use the WebKit and JavaScriptCore libraries.

JavaScriptCore has an API that MoI uses to make an object in the js runtime that calls C++ functions when properties are accessed or functions invoked.

Unfortunately making a well documented SDK is an extremely time consuming process and since I'm only one person working on MoI I just do not have enough time available to do developer oriented documentation. So it has not been possible to make that a priority as of yet. It is something that I would like to work on in the future but other functionality targeted at "regular" non-developer users has been and still is my priority currently.

- Michael
From: Bravlin
28 Nov 2018   [#11]
ok. i see. let's leave complex SDK to better days.
For example Softimage have Script Editor, SDK Explorer etc.
They helps to debug and examine scripts, objects atributes etc.
What developer environment MOI have ?
In some scripts i notice moi.ui.alert( ) used as loggin mechanism.
From: Michael Gibson
28 Nov 2018   [#12] In reply to [#11]
Hi Bravlin, MoI does not currently have any built in developer environment, you just use a text editor to write the files and use moi.ui.alert('text') to pop up messages to help you see what is going on.

Also set the option in moi.ini to disable file caching so it will reload scripts every time they are run, to find that go to http://moi3d.com/wiki/Scripting and go to the link that says "See here for info on disabling file caching so commands will reload on every run".

I would like to work on having an integrated script debugger built in to MoI in the future but it will be a highly time consuming thing to work on so I'm not sure when that will happen.

- Michael
From: Bravlin
9 Dec 2018   [#13]
Q_03:
Still talking about styles.
How should i query style for a subcomponents ?
This approach is good for objects but on a components its kinda slow.

I guess it takes time to iterate throgh all subcomponents.
Here is a small script to imitate selection set. It should toggle components selection by moving them to style 'selectset' and back to activstyle.

Maybe we can select style components through moi UI objects ?
From: Michael Gibson
9 Dec 2018   [#14] In reply to [#13]
Hi Bravlin, can you post the pieces that are needed to reproduce the slow performance? Like for example if it is happening when running your script on a particular model please post the model too so I can give it a test over here.

One other quick note for the part about creating the style if it's not there, you can use moi.geometryDatabase.findStyle( 'name', true /*CreateIfNotFound*/ ); something like this:

code:
    var style = moi.geometryDatabase.findStyle( 'name', true ); // true for second parameter means create the style if not already existing.
    var  index = style.index;


- Michael
From: Bravlin
10 Dec 2018   [#15]
Sure. Try it this way: select some faces from one object. Use script to set current selection to 'selectset' style.
Deselect all. Then use script again to reselect comps. And you see the performance loss (or some lag).
I have i72.2GHz 8GB DDR3.
Unfortunately it happen on every model so i guess it's not a model issue.

Attachments:
TEST.3dm


From: Michael Gibson
10 Dec 2018   [#16] In reply to [#15]
Hi Bravlin, I'm not noticing any lag over here with your script.

But a couple of things that could improve performance though - first thing is a script that does selection type stuff is better to run as an "instant script" than as a command.

A command in MoI handles various things related to creating and deleting objects like setting up undo units, clearing selection lock, loading UI files, etc...

If you run it as instant script you will bypass all that stuff. Also you can trigger instant script while running inside of a command. If it's run as a command it will exit any currently running command since there can only be one "command" running at a time.

One way to run things as an instant script is to have the script code pasted directly into the Command field of the Shortcut key editor, prefixed with "script:" . But it is also possible to set up instant script from a .js file. To do that, make a directory named "scripts" as a sibling of "commands" in the moi appdata directory and put it in there. Then for your shortcut key use the name of the script file including the .js file extension like: SaveSelectToStyle.js . You can also put it in any directory and put the whole path to it in the shortcut key like c:\scripts\SaveSelectToStyle.js .

Also a couple other things would be to use geometryDatabase.findStyle() to get the style, and also line 23 if(obj.type = 7) looks like a bug, first you would need == there but also type number 7 is a mesh object will only be around when you're exporting to a mesh format. The objects that you're working with in TEST.3dm are BRep objects so you could use obj.isBRep . I would kind of think that trying to assign to the read only obj.type property would trigger an exception but I guess not, that might be a bug.

So give this one a try with it set up to run as immediate script, does it behave any better for you? :

code:
function DoSaveSelectToStyle()
{
    var gd = moi.geometryDatabase; 
    var activstyleidx = moi.geometryDatabase.activeStyle;
    var objects = gd.getObjects(); 
    var savedobjsnum = 0;

    var si = moi.geometryDatabase.findStyle( 'selectset', true /*CreateIfNotFound*/ ).index;
   
    
    // reselect all selectset objs
    for ( var i = 0; i < objects.length; ++i )
    { 
        var obj = objects.item(i); 
        if(obj.styleIndex == si)
        {
            obj.styleIndex=activstyleidx; 
            obj.selected=true;
            savedobjsnum +=1;
        }
        else
        {
            if(obj.isBRep)
            {
                var subs = obj.getSubObjects();
                for ( var j = 0; j < subs.length; ++j ) 
                { 
                    var sub = subs.item(j); 
                    if(sub.styleIndex == si)
                    {
                        sub.styleIndex=activstyleidx; 
                        sub.selected=true;
                        savedobjsnum +=1;
                    }
                }
            }
        }
    }
    
    // if no objs in style selectset
    if(savedobjsnum == 0)
    {
        var selobjects = gd.getSelectedObjects(); 
        selobjects.setProperty( 'styleIndex', si ); 
    }
}
DoSaveSelectToStyle();




- Michael
From: Bravlin
11 Dec 2018   [#17]
"=". My bad. That's what happens when you work without IDE support.
I paste code of functions here, but i use them as .js files.

I tried your code today but unfortunately it also have this lag.
Maybe we can somehow reach UI style selection functions (those that fires up when we press near style gui to select all obj)?
They sure doesn't have any performance issues.

Here is how this lag looks like: https://www.dropbox.com/s/wjy47s71b8quh5r/Dv5mujpFSg.mp4
I use " SHIFT+` " as hotkey to fire script.
From: Michael Gibson
11 Dec 2018   [#18] In reply to [#17]
Hi Bravlin,

re:
> Maybe we can somehow reach UI style selection functions (those that fires up when we press near
> style gui to select all obj)?
> They sure doesn't have any performance issues.

There isn't any way set up to access that from script right now but I can add script access to it for the next v4 beta.

Just to make sure I understand, you mean a way to trigger by script the same thing that happens when you click on this selection dot spot in the scene browser? :


- Michael

Image Attachments:
bravlin_scene_browser.jpg 


From: Bravlin
11 Dec 2018   [#19]
Yes. I guess the similar query interface will be handy for a group selection also.
From: Bravlin
2 Jan 2019   [#20]
Theas thread helps with performance issue a lot.
http://moi3d.com/forum/messages.php?webtag=MOI&msg=6440.1

script: /*SAVE SELECT TO STYLE*/moi.command.execCommand ('var gd = moi.geometryDatabase; var activstyleidx = moi.geometryDatabase.activeStyle; var objects = gd.getObjects(); var savedobjsnum = 0;var si = moi.geometryDatabase.findStyle( "selectset", true ).index; for ( var i = 0; i < objects.length; ++i ) { var obj = objects.item(i); if(obj.styleIndex == si){ obj.styleIndex=activstyleidx; obj.selected=true; savedobjsnum +=1; } else { if(obj.isBRep) { var subs = obj.getSubObjects(); for ( var j = 0; j < subs.length; ++j ) { var sub = subs.item(j); if(sub.styleIndex == si){sub.styleIndex=activstyleidx; sub.selected=true; savedobjsnum +=1; }}}}}if(savedobjsnum == 0){var selobjects = gd.getSelectedObjects(); selobjects.setProperty( "styleIndex", si ); }');

Show messages:  1-20  21-22