MoI discussion forum
MoI discussion forum

Full Version: Modification of ImportPointFile script

From: bemfarmer
7 Apr   [#1]
Hi Michael,

In order to modify the PointImportFile script, to add the name of the text file to the object create (a curve), would the final line of code below do the job?
Or is there a better example?

Thank you,
- Brian


code:
/

Code from _ImportObj.htm:


				objName = moi.filesystem.getFileNameFromPath(objPath);
				objName = objName.substr(0, objName.lastIndexOf('.'));

faceobj=scale3d.calculate();
				
		moi.geometryDatabase.addObjects(faceobj);
		// if ( normalize ) if (scale > 1) { objName = objName + " ["+scale+":1]" }
		// else if (scale < 1) { objName = objName + " [1:"+Math.round(100/scale)/100+"]" }
		if (errors>0) objName = objName + " err:"+errors;
				faceobj.setProperty( 'name', objName);
***************



Code from ImportPointFile.js:

function ImportPointFile()
{
	var filename = moi.filesystem.getOpenFileName( 'Choose a point file', 'Point files (*.txt, *.xyz, *.csv)|*.txt;*.xyz;*.csv|All files (*.*)|*.*' );
	if ( filename == '' )
		return; // User canceled.
***************


Other code from ImportPointFile.js:


	else
		ObjectList = GetCurve( ImportAs, PointList, CurveEnd );
	
	ObjectList.setProperty( 'selected', true );
	moi.geometryDatabase.addObjects( ObjectList );
***************	
Proposed code to add???:
	objName = filename.substr(0, filename.lastIndexOf('.'));
	ObjectList.setProperty( 'name', objName);
	



I would also like the whereabouts of an example of "bulk selection" of filenames to import, if possible?
From: Michael Gibson
7 Apr   [#2] In reply to [#1]
Hi Brian,

re:
> In order to modify the PointImportFile script, to add the name of the text file to the object create
> (a curve), would the final line of code below do the job?
> Or is there a better example?

It looks fine to me, does it work ok?


> I would also like the whereabouts of an example of "bulk selection" of filenames to import, if possible?

If you want to process all the files in a certain directory, there is an example here of using
moi.filesystem.getFiles() to get a list of files contained within a folder,
http://moi3d.com/forum/index.php?webtag=MOI&msg=6689.2

Like this:
var files = moi.filesystem.getFiles( 'c:\\iges_files', '*.igs' );

- Michael
From: bemfarmer
7 Apr   [#3] In reply to [#2]
Thank you very much Michael,

The ability to import all of the .xyz files in a directory should be very helpful.

I will do some testing...for both coding.

- Brian