Getting all points of a curve using a script
 1-20  21-40  41-42

Next
 From:  Martin (MARTIN3D)
6257.1 
How can I get the x and y coordinates of the three points that are between the start and the endpoint of the curve below?



code:
script:
var crvs = moi.geometryDatabase.getSelectedObjects().getCurves();
for ( var i = 0; i < crvs.length; i++ )
{
	var crv = crvs.item(i);
	moi.ui.alert( crv.getStartPt().x );
	moi.ui.alert( crv.getStartPt().y );
	moi.ui.alert( crv.getEndPt().x );
	moi.ui.alert( crv.getStartPt().y );
}



-Martin
Attachments:

  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:  bemfarmer
6257.2 In reply to 6257.1 
Hi Martin

Is it a polyline?
Are the points endpoints, or control points? (or both)
Maybe separate into individual curves?
Seems like it should be easy to get the endpoints, but I would have to study on it a bit. Meanwhile someone else will
answer :-)

I do not know if control points can be obtained by script?

- Brian
  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:  Martin (MARTIN3D)
6257.3 In reply to 6257.2 
Hi Brian,

thanks. Its a Polyline and the points are normal curve points. I'm not interested in getting control points just all points that are on the curve.
If there are control points I would use the REBUILD command and its # Points mode to generate points in between.

EDITED: 5 Nov 2013 by MARTIN3D

Image Attachments:
Size: 60 KB, Downloaded: 24 times, Dimensions: 394x324px
  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:  bemfarmer
6257.4 In reply to 6257.3 
Two preliminary suggestions:
There is a predecessor to the rebuild command called, I think, reconstruct, which arrays points on a curve... On a MoI site...

I used seiffertCurve.getEndPt() and .getStartPt() in seiffert script.

No more time right now. :-)

- Brian

EDITED: 6 Nov 2013 by BEMFARMER

  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
6257.5 In reply to 6257.1 
Hi Martin, I'm sorry but there isn't any way currently for a script to access those points.

I've added in something for the next beta so that the start and end of curve _segments_ can also be retrieved. Right now they can only be gotten for the full curve, not for individual segments. Once this is in place then you would be able to get the segments by doing var segs = crv.getSubObjects(); , then each segment will respond to getStartPt() and getEndPt() in the next beta.

I guess one possible work around at the moment might be to run the polyline curve through the separate factory, then retrieve the results of that, that will be a bunch of individual curve objects generated for each segment in the original curve, since those are full curve objects the start and end points of those would be accessible now.

- 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:  Martin (MARTIN3D)
6257.6 In reply to 6257.5 
Thank you Michael,
getSubObjects() will be useful but actually Brians and your suggestion to seperate a multiline does what I need.

But I run into another problem:
I'm trying to use MoI to draw tool paths and then use a script to generate xy coordinates for a CNC router and for this I would need a way to break up freeform curves or arcs into lots of segments.
I thought REBUILD generates new points on a freeform curve or arc but now I see that it only generates more control points.
I would need a solution to generate new points on a freeform curve or arc like shown below. The points on the right are not control points but "real" points drawn by hand using the multi line tool. Is this possible?

Attachments:

  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
6257.7 In reply to 6257.6 
Hi Martin, you should probably be able to find some CAM program that would take in curves and generate toolpath data like you're looking for... Maybe someone with CAM experience will be able to point you towards an already existing solution for this.

> I thought REBUILD generates new points on a freeform curve or arc but now I see that it only generates more control points.

Rebuild generates points on the curve, and then creates a new curve that interpolates those points. It's basically like doing Curve > Freeform > "Through points" and drawing a new curve with the points to interpolate snapped onto the existing curve.

But yes it does generate a smooth curve as the result and not a polyline curve as the result like I think you're looking for?


> The points on the right are not control points but "real" points drawn by hand using the multi line tool. Is this possible?

If you want to generate a bunch of equally spaced points along a curve, you can get that by drawing in one point object at the start of the curve and then using Transform > Array > Curve to replicate that point along the curve.

There is an older and different version of Rebuild that is made with a script that internally uses this array point technique to generate the points, and it may have an option to generate a polyline for the points, check that out here:
http://kyticka.webzdarma.cz/3d/moi/#ReconstructCurve

- 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:  blowlamp
6257.8 
I'm with Michael here. If you want to generate toolpath data for your router such as G-code, then all you need is a CAM program.

My main workhorse and what I recommend is CamBam, both for its ease of use and general capability for 2d and 3d work - cost is £93 or $149. Other free CAM programs are available too, if that is what you want.

I can send you some sample G-code if you tell me what you're after.


Martin.
  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:  Frenchy Pilou (PILOU)
6257.9 
You can also export your polyline for Sketchup and then use some plugins for save your points on an excel's file for example or STL for CAM... :)
  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:  Martin (MARTIN3D)
6257.10 In reply to 6257.7 
Hi Michael,

>If you want to generate a bunch of equally spaced points along a curve, you can get that by drawing in one point object at the start of the curve and then using Transform > Array > Curve to replicate that point along the curve.

thank you, that's great and does exactly what I need. Getting point object coordinates by script is even easier to do . I'll also take a look at the reconstruct command.


@all
Thanks for the help with CAM software but I'm somewhat peculiar using my own very simple CNC controller based on an Arduino UNO. So no G-Code spoken here just up(); down() and go(x,y); :-) I don't need more to cut simple shapes with the router. Currently I'm using Illustrator and a script to get "tool path" data it works well but I like MoI better and it looks like I'm able to use it now for that.

Update: Just tried reconstructCurve with it's polyline option. It does exactly what I need!

EDITED: 6 Nov 2013 by MARTIN3D

  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:  bemfarmer
6257.11 In reply to 6257.10 
Grbl is free G-code interpreter software to use with an Arduino,
for CNC milling control.
A low cost "shield" is also available, which is a stepper driver...

http://makezine.com/2010/06/14/grbl-an-arduino-based-g-code-interp/

http://dank.bengler.no/-/page/show/5470_grbl?ref=checkpoint

http://makezine.com/arduino/grbl/

(I've never used it. I use Mach3)


- Brian
  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:  Martin (MARTIN3D)
6257.12 In reply to 6257.11 
Thanks Brian,

I came across Grbl previously but still decided to "reinvent the wheel" to have a lean and easy to understand solution.

-Martin
  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:  Max Smirnov (SMIRNOV)
6257.13 
I've found solution of this problem several months ago.
This method is stupid, but it's works. :)

en code:
function GetCurveControlPoints(curve)
{
	var gd = moi.geometryDatabase;
	var obj = gd.getObjects();
	obj.setProperty( 'showPoints', false); 
	curve.showPoints = true; 
	gd.selectAll();
	obj.setProperty( 'selected', false);
	
	var objectpicker = moi.ui.createObjectPicker();
	objectpicker.allowEditPoints();
	objectpicker.done();
	gd.copyToClipboardCommand( objectpicker.objects );
	gd.pasteFromClipboard();	
	var points = gd.getSelectedObjects();

	gd.removeObjects(points);	
	curve.showPoints = false; 
	return points;
}

/* example */
var curves = moi.geometryDatabase.getSelectedObjects().getCurves();	
if (curves.length === 1)
{
	pts = GetCurveControlPoints(curves.item(0));
	/* let's build polyline through control points */
	var factory = moi.command.createFactory( 'curve' );
	for ( var p = 0; p < pts.length; ++p)
	{
		factory.createInput('point');	
		factory.setInput(factory.numInputs - 1, pts.item(p).pt); // point
		factory.createInput('bool');	
		factory.setInput(factory.numInputs - 1, true);  // corner
	}
	if  (curves.item(0).isClosed)
	{
		factory.createInput('point');	
		factory.setInput(factory.numInputs - 1, pts.item(0).pt);
		factory.createInput('bool');	
		factory.setInput(factory.numInputs - 1, true);
	}
	factory.commit();
}

EDITED: 7 Mar 2022 by SMIRNOV

  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:  Martin (MARTIN3D)
6257.14 In reply to 6257.13 
Hi Max,

although it doesn't do what I need (I don't care about control points and need in between points ON the curve. The next Beta will allow this.) your script is very interesting. 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:  BurrMan
6257.15 In reply to 6257.14 
Hey Martin,
After you get your points by array on curve or whatever method, you can get the xyz coords for your router in a file by using "savePointFile".

You can then use a spreadsheet program like excel to add any particular command values to the xyz coords listed.
  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:  Martin (MARTIN3D)
6257.16 In reply to 6257.15 
Thanks BurrMan.
  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 6257.17 deleted 7 Mar 2022 by SMIRNOV

Previous
Next
 From:  Max Smirnov (SMIRNOV)
6257.18 
Martin, this is exactly what you want :))
code:
function GetCurveControlPoints(curve)
{
	var gd = moi.geometryDatabase;
	var obj = gd.getObjects();
	obj.setProperty( 'showPoints', false); 
	curve.showPoints = true; 
	gd.selectAll();
	obj.setProperty( 'selected', false);
	
	var objectpicker = moi.ui.createObjectPicker();
	objectpicker.allowEditPoints();
	objectpicker.done();
	gd.copyToClipboardCommand( objectpicker.objects );
	gd.pasteFromClipboard();	
	var points = gd.getSelectedObjects();
	gd.removeObjects(points);			
	
	curve.showPoints = false; 
	return points;
}

var curves = moi.geometryDatabase.getObjects().getCurves();	
for ( var f = 0; f < curves.length; ++f)
{
	pts = GetCurveControlPoints(curves.item(f));
	for ( var p = 0; p < pts.length; ++p)
	{
		var factory = moi.command.createFactory( 'text' );
		factory.setInput(0, moi.VectorMath.createFrame ( pts.item(p).pt) );
		factory.setInput(1, ' xyz('+ Math.round(pts.item(p).pt.x*10)/10 + ', ' + Math.round(pts.item(p).pt.y*10)/10 + ', ' + Math.round(pts.item(p).pt.z*10)/10+ ')');
		factory.setInput(2, 'Arial');
		factory.setInput(5, 'curves' );
		factory.setInput(6, 0.5);
		factory.setInput(7, 1);
		factory.commit();
	}
}

EDITED: 7 Mar 2022 by SMIRNOV

  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:  BurrMan
6257.19 In reply to 6257.18 
Max,
He wants the points "on the curve", not the weighted control points. Thats a great script.
Image Attachments:
Size: 108.2 KB, Downloaded: 64 times, Dimensions: 542x605px
  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:  Max Smirnov (SMIRNOV)
6257.20 In reply to 6257.19 
Ops, sorry.. Now I see.
Anyway, no problem :) I know how to get it. ;)
  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-40  41-42