General technical questions about v3 Moi's API
 1-18  19-26

Previous
Next
 From:  mkdm
8010.19 In reply to 8010.18 
Hi Michael,

You're right, as usual.

In fact, as said in my previous post, I'm aware that this is a simple solution that doesn't allow me to access to the control points' data.

But for the moment, since i'm overwhelmed at work and have i no time to take a look at the openNURBS library,
it's enough for me to get a bunch of simple point objects in order to elaborate them with the utility nodes that i'm writing,
dedicated to the elaboration of PointArrays.

But, it would be very interesting for me at least having the possibility to recognize which of the control points extracted, are real SHARP points.
This could make me a qualitative leap into the elaboration of those points.

So I'm wondering if some of the javascript code, present in your "fillet" commands, could lead me in that direction.
I saw that, given a single StandaloneCurve selected, the "fillet" command starts by showing
the CORNER points present in that curve.

Maybe i can get these CORNER points for recognize them inside the code of my ExtractCurvesControlPoints.js,
in order to, for example, reconstruct the original curve leaving intact at least the original SHARP points.

Maybe....

What do you think about it ? It is a feasible thing, to use a portion of the javascript code in your "fillet" command ?

Thank you for your support and...Ciao!

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.20 In reply to 8010.19 
Hi Marco, yes I think it's possible to use the Fillet factory to get corner points, there is a custom method .generateVertices() on the fillet factory, you can use it like this to get an object list of point objects, one at each sharp corner of the curve:

code:

function GetCorners( crvs )
{
	var factory = moi.command.createFactory( 'fillet' );
	
	factory.setInput( 0, crvs ); // Set an object list with one curve in it.
	factory.generateVertices();

	var corners = factory.getCreatedObjects();
	
	factory.cancel();
	
	return corners;
}

function TestGetCorners()
{
	var crvs = moi.geometryDatabase.getSelectedObjects().getCurves();
	if ( crvs.length != 1 )
	{
		moi.ui.alert( 'Select a curve before running this command.' );
		return;
	}
	
	var corners = GetCorners( crvs );
	
	moi.ui.alert( 'Got ' + corners.length + ' corners' );
}	

TestGetCorners();



- 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.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-18  19-26