Export Points from object into txt file
 1-20  21-40

Next
 From:  dune1982
9071.1 
Hello MoI Forum,
I wonder if it is possible with MoI (perhaps with a script) to set points on a curve and then extract those coordinates into a .txt file.

For example think of a freeform curve that is over all 100mm long (if you walk along the curve), now set a point every 10mm of the way. Export all coordinates of the points into a .txt file.
  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:  amur (STEFAN)
9071.2 
Hi,

Michael has written an import and export points script,
but currently i have no link handy, sorry.

Regards
Stefan
  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
9071.3 In reply to 9071.1 
Hi dune1982, you can create points along a curve every 10mm by creating a point object (Draw curve > More > Pt) at the start of your curve and then selecting the point and using Transform > Array > Curve to duplciate it along the curve. The Array curve command has an option in it for whether to use an item count which calculates the distance or you can enter the distance directly which is what you would want to do.

After generating the points you can then select them and export them to a file using the SavePointFile plug-in from here:
http://moi3d.com/forum/display.php?webtag=MOI&msg=5124.2

There are instructions for installing a plug-in here:
http://moi3d.com/wiki/FAQ#Q:_How_do_I_install_a_plug-in_script.3F

- 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:  dune1982
9071.4 In reply to 9071.3 
Thank you Michael,
that is close to perfect. The only thing is that in the txt file the separator between a digit and its decimals is a point(.) but I need to have a comma (,)

I'm not speaking of the delimiters, i know i can adjust what is used there.
  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
9071.5 In reply to 9071.4 
Hi dune1982, to change that open the SavePointFile.js file in a text editor and go to line number 58 which currently has this:

code:
		for ( var j=0; j < 3; j++ )
		{
		    pt[j] = round( pt[j], Digits );
		}


Modify it by adding in a new line like this:

code:
		for ( var j=0; j < 3; j++ )
		{
		    pt[j] = round( pt[j], Digits );
		    pt[j] = pt[j].toString().replace( '.', ',' );
		}


That should then make the decimal point separator to be a comma instead of a point. But that may cause problems if you also use a comma as the delimiter between points as well.

- 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:  dune1982
9071.6 In reply to 9071.5 
Wow thank you Michael, the Export now is perfect.

But I did understand my task a little wrong, which makes it a bit more complicated.

I don't need to set the points while walking along the curve but at a certan distance. For example 500 point on the curve no matter how long the curve is.

I hope this indicates what I need to do.



After selecting all points export them into a file. For 500 points it is a little to much to do it by Hand, thats why I was thinking of a script.
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
9071.7 In reply to 9071.6 
Hi dune1982, for that case select your main curve and all the lines that cross it and use the Construct > Curve > Isect command to intersect them. That will generate a point object at each intersection and you can then select all points either with a strategically placed selection window or by using the Types > Points entry in the Scene Browser, then export them.

- 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:  Frenchy Pilou (PILOU)
9071.8 In reply to 9071.7 
How to redraw a curve by these points selected on the screen? (except by hand of course)
I have a black hole of memory! A command, script, plugin... ?

EDITED: 26 Sep 2018 by PILOU

  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:  amur (STEFAN)
9071.9 
Hi Pilou,

if i remember correctly Franz asked for this feature a while ago,
because it is not possible currently. I would like to have this
possibilty too.

Regards
Stefan
  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
9071.10 In reply to 9071.8 
Hi Pilou & Stefan, after writing the points out to the file you can use the ImportPointFile script at the same link above to do that:
http://moi3d.com/forum/display.php?webtag=MOI&msg=5124.2

It has an option for how to process the imported points, you can make point objects out of them, a polyline, a control point curve or an interpolated curve. The ordering of the points in the file is significant though.

- 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:  dune1982
9071.11 In reply to 9071.7 
Thank you Michael, the isect command works just fine.

Ok now I have to make a script that will creates trose 500 hundret lines with a distance based on the length of the initial curve. Then automaticaly select the curves and run the isect command. Then export the stuff to a file.

Sounds like it is possible but I nearly lost all my scripting skills over the years.
  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)
9071.12 In reply to 9071.10 
< ImportPointFile script

Ok that was that! the funny is that we must export then import! :)
---
Pilou
Is beautiful that please without concept!
My Moi French Site My Gallery
  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
9071.13 In reply to 9071.11 
Hi dune1982, you can just do those steps that you describe individually, for getting the length of a curve use this:
http://kyticka.webzdarma.cz/3d/moi/#CurveLength

You can decide what length to use based on that, then with the regular Transform > Array > Dir command you can make 500 lines with the spacing you need, you can select all the lines that were just created using this on a shortcut key:
script: moi.geometryDatabase.selectLastCreated();

Then run isect and that SavePointFile plug-in.

Why do you need to combine that into a single script?

- 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:  amur (STEFAN)
9071.14 
Hi Michael,

thanks a lot! I completely forgot that this is possible with the import script.

Regards
Stefan
  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:  dune1982
9071.15 In reply to 9071.13 
Since I have to do this task couple of times now and in the future a script would make it easier.

I already got this far (create some lines and put them in a list, but I fail selecting the one line where all the intersections are on)


#include "GetObjects.js"

//Set vareables 
var i;
i=0;
var linelength;
linelength=50;

var linelist = moi.geometryDatabase.createObjectList();


//Will draw a line with the given coordinates 
function drawLine(x1,x2,y1,y2) 
{
   	var linefactory = moi.command.createFactory( "line" );
   	linefactory.setInput( 0, moi.vectorMath.createPoint( x1, y1, 0 ) );
   	linefactory.setInput( 1, moi.vectorMath.createPoint( x2, y2, 0 ) );
	    
	var objlist = linefactory.calculate();
   	var line = objlist.item(0);
	moi.geometryDatabase.addObject( line );
   	return line;
}	


for ( var j=0; j < 17; j++ )
{
	linelist.addObject(drawLine(i,i,0,linelength));
	i=i+10;
}
//works fine until here

	

//Will do the intersection 
function DoIntersect()
{
	
	var objectpicker = moi.ui.createObjectPicker();
	//objectpicker.min = 2;
	
	if ( !GetObjects( objectpicker ) )
		return;
	linelist.addObject(objectpicker);
	
	var factory = moi.command.createFactory( 'intersect' );
	factory.setInput( 0, linelist.objects );
	
	factory.commit();
}

DoIntersect();


for the corresponding .htm file I just copied the content of the intersect.htm

It works so far that MoI asks me to pick objects for the intersection. I assume that the lines created by the scipt are in the linelist, so I just select the one line that crosses all the created lines. But that fails in the errormessage attached

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
9071.16 In reply to 9071.15 
Hi Dune1982,
It seems that you have not posted the code which includes the variable allownothing?
- 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:  dune1982
9071.17 In reply to 9071.16 
Hello Brian,
that is part of getobjects.js wich is a part of the MoI core files.
  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
9071.18 In reply to 9071.15 
Hi dune1982, it looks like the error report is off, the actual error is 2 lines down from GetObjects(), here:

code:
linelist.addObject(objectpicker);


ObjectList.addObject() expects a geomobject while that is passing an objectpicker instead. Also further down for the setInput call I think you need to pass just linelist since it is an objectlist, linelist.objects would be an error.

So something like this:

code:

//Will do the intersection 
function DoIntersect()
{
	
	var objectpicker = moi.ui.createObjectPicker();
	//objectpicker.min = 2;
	
	if ( !GetObjects( objectpicker ) )
	    return;

	var picked_objects = objectpicker.objects;

	for ( var i = 0; i < picked_objects.length; ++i )
	    linelist.addObject( picked_objects.item(i) );
	
	var factory = moi.command.createFactory( 'intersect' );
	factory.setInput( 0, linelist );
	
	factory.commit();
}

DoIntersect();

  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:  pior (PIOR_O)
9071.19 
Hello all, Michael,

Does this SavePointFile script still work for V4, and if yes, where does it write out the file ? I am not getting any prompt for a save location and can't seem to find any .txt file written out.

For context I am currently working on a small DIY project that would require to export out points data from a MOI drawing, to later plot them physically as straight pen lines between each point, in "turtle" fashion, using a small Arduino robot. And while an OBJ export of filled polygon objects seems like a good starting point as it is very human readable, I have been wondering if there is already a way to write out point data (in good order of course) to CSV, which led me to this thread.

[edit] Just found this other thread here where it is mentioned that the script is intended to work on point objects, rather than points from objects.
http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=8996.2
It is giving me a long series of floats, separated by commas. I suppose that they are to be interpreted as X0,Y0,X1,Y1,X2,Y2... and so on ? I suppose the order is maintained from the original object ?

EDITED: 14 Sep 2021 by PIOR_O

  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
9071.20 In reply to 9071.19 
Hi pior,

re:
> It is giving me a long series of floats, separated by commas. I suppose that they are to be interpreted as X0,Y0,X1,Y1,X2,Y2... and so on ?

It should be making a separate line in the text file for every point with an x,y,z value on every line.

Can you please post an example output file where it's all on one line?

Are you using the version from here? :
http://moi3d.com/forum/index.php?webtag=MOI&msg=5124.2


> I suppose the order is maintained from the original object ?

It's going to be in the same order that the point objects are in the geometry database.

- 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
 

Reply to All Reply to All

 

 
Show messages:  1-20  21-40