Scripting the Trim command -- programmatically select objects to keep or remove?

Next
 From:  mike (MVERHULST)
11415.1 
Hi,

I found this discussion.

https://moi3d.com/forum/lmessages.php?webtag=MOI&msg=8786.1

I am having some issues with this. When i run the code below (in a script passed to the moi.exe in windows), it seems to block the gui and wait for me to do something next? what am i missing?

var factory = moi.command.createFactory( 'circle' );
factory.setInput( 1, moi.vectorMath.createFrontFrame() );
factory.setInput( 3, 10 );
factory.commit();

var linefactory = moi.command.createFactory( 'line' );
linefactory.setInput( 0, moi.vectorMath.createPoint(0,0,0) );
linefactory.setInput( 1, moi.vectorMath.createPoint(10,0,0) );
var linelist = linefactory.calculate();

var pointfactory = moi.command.createFactory( 'point' );
pointfactory.setInput( 0, moi.vectorMath.createPoint(8,0,0) );
var pointlist = pointfactory.calculate();

var trimfactory = moi.command.createFactory( 'trim' );

trimfactory.setInput( 0, linelist );
trimfactory.setInput( 1, pointlist );
trimfactory.setInput( 2, moi.geometryDatabase.createObjectList() );

trimfactory.generateFragments();
trimfactory.finishedPickingFragments();

trimfactory.update();

var objs = trimfactory.getCreatedObjects();
moi.ui.alert( objs.length + ' objects created' );

trimfactory.commit();
  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
11415.2 In reply to 11415.1 
Hi Mike,

re:
> it seems to block the gui and wait for me to do something next?

The gui will be blocked because the call to moi.ui.alert() will show a modal dialog box.

You'll need to dismiss the alert dialog box for it to progress to the end of the script.

- 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:  mike (MVERHULST)
11415.3 In reply to 11415.2 
cool,

but i did dismiss the alert and the gui is still blocked. its like it is asking for me to select a section of the line to remove with the mouse. But how do i programmatically select line segments to keep or remove?
  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)
11415.4 In reply to 11415.3 
Hi Mike,

When I run your code on Windows in the latest v5 beta it works just fine. The GUI is responsive after I click through the alert.

Re:
> its like it is asking for me to select a section of the line to remove with the mouse.

Setting input 2 with an empty objectList like you're doing means that all fragments will be kept.

Re:
> But how do i programmatically select line segments to keep or remove?

What's kept and removed is determined by the contents of the objectList passed to input 2 and whether the factory is running in "keep" mode or "remove" mode.

- 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
Next
 From:  mike (MVERHULST)
11415.5 In reply to 11415.4 
can you test it in v4? i wonder if i am doing something wrong? see the image? i cant click on the circle, but i can click ui buttons and/or either of the 2 line segments

EDITED: 29 May 2024 by MVERHULST

Image Attachments:
Size: 109.9 KB, Downloaded: 16 times, Dimensions: 1039x776px
  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)
11415.6 In reply to 11415.5 
Hi Mike,

I can click on the circle fine in v4 and in v5.

Is the code that you posted the entirety of your script, or is there other code too? Is there anything going on in the companion .htm file?

It sounds like selection lock is getting set on the circle. That's the typical reason for not being able to click on something.

- 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
Next
 From:  mike (MVERHULST)
11415.7 In reply to 11415.6 
interesting

that is the whole script i dont have a html file

i am running it with this command

"C:\Program Files\MoI 4.0\MoI.exe" C:\Users\Administrator\Desktop\trimtest.js
  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:  mike (MVERHULST)
11415.8 In reply to 11415.7 
excellent,

thanks for your help :)

i needed to add

var objects = gd.getObjects();
objects.unlockSelection();
  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:  Michael Gibson
11415.9 In reply to 11415.8 
Hi Mike, clearing selection lock is something that normally happens when a command ends.

When you run a startup script it's not using the "command" mechanism and so you'll have to do some things manually 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
 

Reply to All Reply to All