General technical questions about v3 Moi's API
 1-20  21-26

Previous
Next
 From:  mkdm
8010.21 In reply to 8010.20 
Thank you very much Michael, it's exactly what i wanted.

Here's my code :

code:
function extractCurveSharpControlPoints() {
	var gd = moi.geometryDatabase;	

	var obj = gd.getObjects(); // get all the objs
	
	var selCurves = gd.getSelectedObjects().getCurves(); // get all the selected curves
	
	if (selCurves.numStandaloneCurves != 1) {
		moi.UI.alert("Select alone Stand Alone Curve!");
		return;
	}
	
	// 1 - deselect everything and turn off all control points
	obj.setProperty('selected', 0);
	obj.setProperty('showPoints', 0);	
	
	var factory = moi.command.createFactory( 'fillet' );
	factory.setInput( 0, selCurves );
	
	// 2 - get corner points
	factory.generateVertices();
	var points = factory.getCreatedObjects();

	factory.cancel();
	
	// 3 - add the points to the geometry database
	gd.addObjects(points);
	
	// 4 - select the points
	points.setProperty('selected', 1);
}

extractCurveSharpControlPoints();


When possible i will integrate this code into the other code i want to write.

Thanks again!!!

P.S. I noticed that putting this code in a .js file copied into "script" folder, the job is done, but at the end i need to press "escape" key
in order to get the viewports reactive to the further user selection.
Instead, if I put this code into "commands" folder ALL is ok.

Marco (mkdm).
  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
8010.22 In reply to 8010.21 
Hi Marco, I'm glad that works for you. re: Scripts vs commands folder - when you put it into the script folder, that means the code is run as "instant script" which just executes your code and does nothing else. When you put it in the commands folder, it is run as a command which has various things done before the command is launched and also after the command is finished to clean up some various states.

Some of the stuff done before a command starts includes loading any associated UI from a companion .htm file, clearing any "selection transition" display, clearing "selection lock", preparing the undo manager, and recording the current geometry database revision number and current selection counter.

Some of the stuff done when a command ends includes clearing selection lock, hiding the "Calculating..." and "Calculation failed" UI, persisting control values from the controls in the UI, clearing the command UI, canceling any factories that were created in the command that were not committed, generating undo units if any geometry was created or removed during the command, and deactivating any command or command set buttons associated with that command.

So when you run as "instant script" instead of as a "command", none of those additional cleanup tasks are happening and that's why you see a difference in behavior from those. You would have to do all those cleanup things yourself if you wanted to get the exact same behavior. I'm not sure which exact thing is responsible for your particular case though. It's usually good to run things that generate or remove geometry as a command so they get undo units made for them though.

At some time in the future I might try to make some of these things happen for "instant script" as well, but it might be a bit tricky because it can be useful to run scripts that do focused tasks like adjusting the selection and you might want to have that script do that stuff while you are still running inside of an existing command.

- 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:  mkdm
8010.23 In reply to 8010.22 
Hi Michael,

Thank you very much for these clarifications.

Have a nice day.

- Marco (mkdm).
  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:  Mindset (IGNITER)
8010.24 In reply to 8010.20 
> factory.generateVertices();
> var corners = factory.getCreatedObjects();

How can I get the x,y coordinates of a corner?

var factory = moi.command.createFactory( 'fillet' );
factory.setInput( 0, objlist );
factory.generateVertices();
var points = factory.getCreatedObjects();
factory.cancel();
for ( var j = 0; j < points.length; j++ )
{
var pnt = points.item(j);

moi.ui.alert( "pnt = " + pnt);


moi.ui.alert( "pnt.x = " + pnt.x);


moi.ui.alert( "pnt.y = " + pnt.y);


}

___________

I tried to treat it as an array as well... no luck so far.

Thanks,
-- Mindset

  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:  Karsten (KMRQUS)
8010.25 In reply to 8010.24 
Hello Mindset,

try something like this: points.item(i).pt.x
pt is a mathPoint (moi.VectorMath.createPoint())

var pnt = points.item(j); gives you an PointObject (visible Object like a line or a cube) that has a mathpoint inside:-) the mathpoint has x,y,z

I hope that helps.

Have a nice day
-Karsten
  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:  Mindset (IGNITER)
8010.26 In reply to 8010.25 
Wunderbar!
Du bist eine kräftige Stimme

THANK YOU very much, Kersten.
-- Mindset
  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

 

 
 
Show messages:  1-20  21-26