ScriptSpot

Forum topic · Scripts Wanted

Spline from 100+ XYZ coordinates?

By Caspar83 · 2014-03-20

Downloads
Description

Hi!

I've been looking for a way to generate a spline in 3ds Max 2010
from a list of XYZ coordinates like this:

-633.899467 253.472601 -922.572420
-633.634657 253.328655 -922.612933
-633.424837 253.285432 -922.631823
-633.215333 253.320855 -922.725688
-633.008533 253.449184 -922.869686
-632.952400 253.733482 -922.965703
-632.982588 253.956076 -922.999394
-633.077269 254.217309 -922.978714

(it goes on for quite a while)

The XYZ coordinates could either be in a .txt file or an .xyz file

Would this be a lot of work for someone with scripting skills?

I've attached an example of a longer list as a .txt file.

Cheers/

Caspar

Comments (6)

.

Caspar83 · 2014-03-26

Hey!

There were a few slightly strange things, but I found a quick solution:
The script seems to generate 3 vertices for each point and switching vertice attribute between corner, smooth, bezier et.c doesn't have any effect. By saving the spline as an OBJ and importing it back, things were back to normal and the duplicate vertices got welded automatically.

Thanks again Miauu, really appreciate it!

Will use this script in a new sculpture project.
If you're curious, check here some time from now!
---> casparforsberg (dot) com

.

miauu · 2014-03-26

It realy creates 3 knots at the same position. The reason is that I had another idea to create knots, but then I change it with another way and forgot to remove the first one. Here the fixed code, so no need to export/import as obj.


(
	xyzFile = getOpenFileName()
 
	if xyzFile != undefined and doesFileExist xyzFile do
	(
 
		ss = splineShape()
		addNewSpline ss
		xyz = openFile xyzFile	
		while not eof xyz do
		(
			nextLine = filterString (readLine xyz) " "
			addKnot ss 1 #corner #line [(nextLine[1] as float),(nextLine[2] as float),(nextLine[3] as float) ]
		)
		updateShape ss
		CenterPivot ss
	)
)

.

miauu · 2014-03-20

Try this:


(
	xyzFile = getOpenFileName()
	
	if xyzFile != undefined and doesFileExist xyzFile do
	(
		
		ss = splineShape()
		addNewSpline ss
		xyz = openFile xyzFile	
		while not eof xyz do
		(
			nextLine = filterString (readLine xyz) " "
			for i = 1 to 3 do
			(
				addKnot ss 1 #corner #line [(nextLine[1] as float),(nextLine[2] as float),(nextLine[3] as float) ]
			)
		)
		updateShape ss
                CenterPivot ss
	)
)

Caspar83 · 2014-03-23

Thank's a lot Miauu,
I'll give this a try!

Best regards/

Caspar

.

Caspar83 · 2014-03-23

Works great, thank you again so much!

Cheers/Caspar

.

miauu · 2014-03-24

Glad to help. :)