Thanks, Pilou! ;)
---------------------------
Let's say I have this simple script that creates a line. By default, the object's name is empty and appears as
"Unnamed" in the UI.
How can I assign a name to this line immediately after it is created, without manually selecting it first, so that I can easily refer to it later in the script?
code:
var linefactory = moi.command.createFactory( 'line' );
linefactory.setInput( 0, moi.vectorMath.createPoint( 0,0,0 ) );
linefactory.setInput( 1, moi.vectorMath.createPoint( 10,10,10 ) );
linefactory.commit();
My goal is to build fully automated scripts where the user only provides the initial parameters. Because of that, it would be very convenient if I could obtain a reference to the newly created object immediately after creation and assign it a unique name or identifier. Is there something equivalent to a "last created object" reference?
As another example, suppose I create a box and then separate all of its faces into individual objects. How would I programmatically select a specific face among them without relying on manual object picking?
I think this is the part of the object model that I'm currently struggling to understand.
EDIT :
Just tried this:
code:
var factory = moi.command.createFactory( 'line' );
factory.setInput( 0, moi.vectorMath.createPoint(0,0,0) );
factory.setInput( 1, moi.vectorMath.createPoint(10,10,10) );
factory.commit();
moi.geometryDatabase.selectLastCreated();
still, the newly created line is not selected, so I can't specify its name (for future easy reference).
EDIT 2:
Just tried this:
code:
var factory = moi.command.createFactory( 'line' );
factory.setInput( 0, moi.vectorMath.createPoint(0,0,0) );
factory.setInput( 1, moi.vectorMath.createPoint(10,10,10) );
factory.commit();
moi.geometryDatabase.selectLastCreated();
moi.geometryDatabase.getSelectedObjects();
Not working, too... the line is not selected.
BUT : if I
manually create an object, and do this :
code:
moi.geometryDatabase.selectLastCreated();
moi.geometryDatabase.getSelectedObjects();
My last created object IS SELECTED!.
Furthermore:
code:
moi.geometryDatabase.selectLastCreated();
moi.geometryDatabase.getSelectedObjects().setProperty('name', 'ME!');
Successfully name the last-created-selected object to 'ME!'.
So, there's seems to be significant difference between creating object manually and via createFactory.commit() ?
EDIT 3 :
I think I may not have described my actual intention clearly enough, so I would like to clarify my use case.
First of all, I fully understand and respect that MoI has its own object model. I am not trying to make MoI work like another software. My previous analogy with CorelDRAW was only to explain my initial way of thinking and the kind of workflow that feels natural to me as I start learning scripting in MoI.
What I am really trying to understand is how to manage a large number of objects created by a script.
In my planned workflow, the script will create many objects step by step: solids, construction objects, cutting objects, and intermediate results for further operations.
Because many objects will be generated automatically, I need a practical way to identify them from a human perspective.
For example:
- This object is the main box.
- This object is the cutting plane.
- This object is the reference geometry.
- This object is the final result.
When working manually in MoI, it is easy for a user to recognize objects visually. But when everything is generated by a script, I need to understand the proper way to organize and keep track of those objects.
My original question was basically: After creating an object through scripting, what is the recommended MoI approach to identify and manage that object so it can be referenced again later when the script continues with more operations?
I am still learning the MoI object model, so I would really appreciate your guidance on the proper scripting pattern rather than trying to apply assumptions from other software.
Thank you again for your patience and for sharing your knowledge. I am very interested in understanding MoI scripting properly and learning the way it is intended to work.
- Elang