points file to line, line to point file

I'm looking for a script (or someone to create one for me) that reads a comma delimited csv file (X,Y,Z) and creates a multi-point line (close it at the last point). and another script to take a multi-point line and save it back into the same csv format.

syntax sample

1.2345, 2.3456, 3.4567

thanks...Tom

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

(
	global rol_splineFromTXT
	try(destroyDialog rol_splineFromTXT)catch()
	rollout rol_splineFromTXT "miauu Spline from file"
	(
		button btn_txtToSpline "TXT to Spline" width:140
		button btn_splineToTxt "Spline to TXT"  width:140
 
		on btn_txtToSpline pressed do
		(
			txtFile = openFile (getOpenFileName())
			if txtFile != undefined do
			(
				ss = splineShape()
				addNewSpline ss
				while not eof txtFile do
				(
					fStr = filterString (readline txtFile) "," splitEmptyTokens:false
					if fStr.count == 3 do
					(
						addKnot ss 1 #smooth #curve [fStr[1] as float, fStr[2] as float, fStr[3] as float]
					)
				)
				close ss 1
				close txtFile
			)
		)
 
		on btn_splineToTxt pressed do
		(
			if selection.count == 1 and classOf selection[1] == SplineShape or classOf selection[1] == Line do
			(
				txtFile = (getSaveFileName())
				if txtFile != undefined do
				(					
					outFile = createFile (txtFile + ".txt")
					ss = selection[1]
					knotsCnt = numKnots ss 1 
					for k = 1 to knotsCnt do
					(
						kPos = getKnotPoint ss 1 k
						format "%,%,%\n" kPos.x kPos.y kPos.z to:outFile
					)
					flush outFile
					close outFile
					messagebox "Done!" title:""
				)
			)
 
		)
 
	)
	createdialog rol_splineFromTXT 
 
)

Spline primitives(Circle, Donut, Rectangle, etc.) are not supported when the splines' points are saved in a txt file.

This will convert the selected shape to editable spline(which you may not want to happen), so Circles, Rentangles, etc. are supported:

(
	global rol_splineFromTXT
	try(destroyDialog rol_splineFromTXT)catch()
	rollout rol_splineFromTXT "miauu Spline from file"
	(
		button btn_txtToSpline "TXT to Spline" width:140
		button btn_splineToTxt "Spline to TXT"  width:140
 
		on btn_txtToSpline pressed do
		(
			txtFile = openFile (getOpenFileName())
			if txtFile != undefined do
			(
				ss = splineShape()
				addNewSpline ss
				while not eof txtFile do
				(
					fStr = filterString (readline txtFile) "," splitEmptyTokens:false
					if fStr.count == 3 do
					(
						addKnot ss 1 #smooth #curve [fStr[1] as float, fStr[2] as float, fStr[3] as float]
					)
				)
				close ss 1
				close txtFile
			)
		)
 
		on btn_splineToTxt pressed do
		(
			if selection.count == 1 and superClassOf selection[1] == Shape do
			(
				txtFile = (getSaveFileName())
				if txtFile != undefined do
				(					
					outFile = createFile (txtFile + ".txt")
					ss = selection[1]
					convertToSplineShape ss
					knotsCnt = numKnots ss 1 
					for k = 1 to knotsCnt do
					(
						kPos = getKnotPoint ss 1 k
						format "%,%,%\n" kPos.x kPos.y kPos.z to:outFile
					)
					flush outFile
					close outFile
					messagebox "Done!" title:""
				)
			)
 
		)
 
	)
	createdialog rol_splineFromTXT 
 
)
TomB's picture

scripts

works great but....

after the spline is brought in, it's not able to be manipulated. cant edit vertices or segments. this happens in both versions of the script.

after I save the file and re-open I get an "obsolete data format error". asks me to resave the file. It still opens it up and it is now editable.

I'm using 3DS max 2020 btw.

I changed the parameters to #corner and #line since I needed it unsmoothed.

Export works fine.

Thanks for this!

Tom B.

jahman's picture

.

add
updateShape ss
after the close file command

miauu's picture

.

Yep. I forgot about it. :)
Thank you. :)

TomB's picture

perfect...thx

perfect...thx

Tom B.

miauu's picture

.

Can you provide a csv file?

TomB's picture

sure...

sure...

AttachmentSize
sample.txt 28.38 KB

Tom B.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.