selectLastCreated usage

Next
 From:  dan (DANLANIGAN)
8256.1 
Hi all,

I'm writing a script that, as part of its functionality, creates a point and then selects it (for the purpose of naming it). Below is a simplified version of what I'm trying to do:
code:
function SelectLatest()
  {
  var pointfactory = moi.command.createFactory('point');
	pointfactory.setInput(0,moi.vectorMath.createPoint(0,0,0));
	pointfactory.commit();
  moi.geometryDatabase.selectLastCreated(true);
  }      
SelectLatest();

Problem is that this doesn't select the point that was just created, it doesn't select anything. If I assign
code:
script: moi.geometryDatabase.selectLastCreated(true);
to a keyboard shortcut and run it after manually adding a point it works fine. Is there something I am missing? Also is there a way to assign a name to an object, in this case a point, during creation? This would be more streamlined than what I'm currently trying to do.

Thanks.
  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
8256.2 In reply to 8256.1 
Hi dan, when a command exits MoI remembers what the geometry database revision number was at that exit time, and later on that's what is used to inside of moi.geometryDatabase.selectLastCreated(). So that function will select the objects that were created by the last command that finished. In your case there you're using it inside of a command that has not exited yet, so it's not going to find objects created by that still running command.

Try this sequence to get the created point object instead:

code:
var pointfactory = moi.command.createFactory('point');
pointfactory.setInput(0,moi.vectorMath.createPoint(0,0,0));

// call factory.update() to generate objects, while the factory is still kept active.
pointfactory.update();

// factory.getCreatedObjects() will now be able to retrieve an object list of what the command generated.
var objlist = pointfactory.getCreatedObjects();

// call factory.commit() to finalize the factory, if commit is not called the factory will be canceled when the
// command exits and the objects it created will be removed. Note that you can't call .getCreatedObjects()
// after .commit() because the factory clears out all of its internal states once .commit() is called and it's
// not expecting to have any connection to what it did previously at that point.
pointfactory.commit();


> Also is there a way to assign a name to an object, in this case a point, during creation?

Once you have the object list you can iterate over it and assign a name to each object by setting the obj.name property, like obj.name = 'thename'; , or you can assign the same name to everything contained inside of an object list by calling objlist.setProperty( 'name', 'thename' ); . The object does not have to be selected when you access the .name property directly through script.

In v4 I'm expecting to implement more types of geometry creation methods other than the factory interface.

Hope this helps!

- 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:  dan (DANLANIGAN)
8256.3 In reply to 8256.2 
Thanks Michael, That's perfect for what I need. Looking forward to the new scripting tools in v4.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Message 8256.4 deleted 10 Jan by IGNITER
 

Reply to All Reply to All