General technical questions about v3 Moi's API
 1-11  12-26

Previous
Next
 From:  Michael Gibson
8010.12 In reply to 8010.11 
Hi Marco, it's a pretty big effort for me to release new versions like that for individual special requests. I'm sorry but you'll have to wait until the v4 betas until I'll be able to add control point access for scripting. Just one example - I don't have any way to distribute a new version like that other than rebuilding the full official release, it would not work for me to post something like that on the forum because I don't want people who make cracked versions of MoI to have easy access to the full version binary.

- 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.13 In reply to 8010.12 
Ok Michael,

I understand your point of view...

Well...i'll wait the V4 betas!

Again, all good wishes for your work.

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.14 In reply to 8010.11 
Hi Marco, one possibility for getting low level access to a curve's control points and knots right now would be to export your curve to 3DM format, and then write a c++ helper .exe program that would read the 3DM file and write out the data you need to a text file that could then be read in by your script.

You can open 3DM files in your own c++ program using the OpenNURBS library which is available from here: http://opennurbs.org/

- 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.15 In reply to 8010.14 
Hi Michael,

Thanks a lot for this suggestion!

I think that it should be pretty easy to do a thing like that.
I hope to get some time off work, to take a look at the docs of http://opennurbs.org/

Maybe it would be better for me if I could use Java instead C++, but anyway i think it's more or less the same thing.

Thanks!

Marco (mkdm)

P.S. i see in http://opennurbs.org/ that it's possible to use the .NET framework also. Good thing!
  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.16 In reply to 8010.14 
Hi Michael,

Considering that i own a commercial version of Rhino V5, i'm thinking that i could also use Rhino + Grasshopper and Rhino Script Compiler for Rhino5.
(for example i saw that Grasshopper has a ControlPoints component that extracts the nurbs control points and knots of a curve.)

Maybe it could be a good idea...

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

Regarding the possibility to easily access curves' control points, i've found a solution that has always been in front of me!

I've written a modified version of Max's DelCorners script, that simply given a bunch of selected curves as input,
creates a bunch of new point objects, automatically selected, representing the selected curves' control points.

I'm aware that this is a simple solution that doesn't allow me to access to the control points' data,
as said by you in your post (http://moi3d.com/forum/index.php?webtag=MOI&msg=6890.5)

> Hi Andrei, Max's script works by doing a "select all" and then a copy to the clipboard of the points and then a paste back in of those points.
> That is indeed a way for a script to access the points without there being a proper script interface, but it's limited in what it can recover,
> it only gets a big bunch of points and isn't able to access additional information like being able to determine
> which particular points are actually corner points or not.

> Just in general it's difficult to make scripts that do control point manipulation since things
> are not currently set up to make all the information about the points accessible to a script.

Here's my code :

code:
// ExtractCurvesControlPoints.js v.0.1 - Marco Di Mario (mkdm), 2016
// based on :
// 		Max Smirnov's DelCorners, v.1.0.2015.09.09

// Given a bunch of selected curves as input, creates a bunch of new point objects, automatically selected,
// representing the selected curves' control points.


function extractCurvesControlPoints() {
	var gd = moi.geometryDatabase;	

	var obj = gd.getObjects(); // get all the objs
	
	var selCurves = gd.getSelectedObjects().getCurves(); // get all the selected curves
	
	if (selCurves.length == 0) {
		moi.UI.alert("At least one curve must be selected!");
		return;
	}
	
	// 1 - deselect everything and turn off all control points
	obj.setProperty('selected', 0);
	obj.setProperty('showPoints', 0);
	
	// 2 - turn on control points on selected curves
	selCurves.setProperty('showPoints', 1);
	
	// 3 - select all the objs
	gd.selectAll();
	
	// 4 - doing so, only all control points remains selected.
	// In this case, the control points of the selected curves
	obj.setProperty('selected', 0);
	
	// 5 - doing so only the control points will be copied and then pasted.
	// Pasted objects are automatically selected
	gd.copyToClipboardCommand( selCurves );	
	gd.pasteFromClipboard();
	
	// 6 - turn off control points on selected curves
	selCurves.setProperty('showPoints', 0);
	
	// As final result, we have now a bunch of new point objects, automatically selected,
	// representing the selected curves' control points!

}

extractCurvesControlPoints();



The ExtractCurvesControlPoints.zip file contains a 3dm example file that can be useful to test the script.

The ExtractCurvesControlPoints.js file can be equally copied to "commands" or "scripts" folder.

I've written this script also for using it together with some NodeEditor's nodes that i'm writing
and that i hope to post as soon as possible.

For example one of these, called "ArrayRemDupl", can be used to remove duplicated points.
That is, given a PointArray and a distance, this node returns a new PointArray, containing only
all the original points, far from each other at least the given distance.

Anyway....thank you for all and have a nice day!

Ciao.

Marco (mdkm).

  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.18 In reply to 8010.17 
Hi Marco, yeah Max figured out that you can use the copy/paste function to extract control points since that duplicates the control points as point objects.

But be aware that it's not exactly a general solution, there is more to the definition of a curve than just control points (there are also values for degree, weights, and knot vector) and so if you try to build a new curve from those points alone it won't necessarily be the same curve as the one you extracted the points from except in the case of what's called a "uniform" curve. But Draw curve > Freeform > Control points does make a uniform curve.

- 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.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-11  12-26