For help output Spline Knot Position Array

Spline Knot Position Array output as txt or print

1.Each 4 Spline as a group
2.Output Spline Knot Position (Pos.X Pos.Y Pos.Z )such as :
splinel.kont1.Pos.Y spline2.kont1.Pos.Y spline3.kont1.Pos.Y spline4.kont1.Pos.Y spline1.kont1.Pos.Z spline2.kont1.Pos.Z spline3.kont1.Pos.Z spline4.kont1.Pos.Z spline1.kont1.Pos.X spline2.kont1.Pos.X spline3.kont1.Pos.X spline4.kont1.Pos.X splinel.kont2.Pos.Y spline2.kont2.Pos.Y spline3.kont2.Pos.Y spline4.kont2.Pos.Y spline1.kont2.Pos.Z spline2.kont2.Pos.Z spline3.kont2.Pos.Z spline4.kont2.Pos.Z spline1.kont2.Pos.X spline2.kont2.Pos.X spline3.kont2.Pos.X spline4.kont2.Pos.X
......
The four spline Knot Position output order is 1、3、5、7...2、4、6、8...

The sample Spline.rar final is:-11.005 -13.772 -16.225 -10.059 0 0 0 0 3.694 -8.541 -12.463 -14.982 -11.005 -13.772 -16.225 -10.059 2.220 2.220 2.220 2.220 1.667 -8.541 -12.463 -14.982 -11.005 -13.772 -16.225 -10.059 4.439 4.439 4.439 4.439 1.667 -8.541 -12.463 -14.982 -11.005 -13.772 -16.225 -10.059 6.659 6.659 6.659 6.659 1.667 -8.541 -12.463 -14.982 .......
Please help Tanks!

AttachmentSize
spline.rar26.64 KB

Comments

Comment viewing options

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

Please print the knot array such as the Attachment!

Thank you very much barigazy!

AttachmentSize
ptint_order.txt 6.46 KB
dingwangfan's picture

Please print the knot array such as the Attachment

Thank you barigazy !!!

AttachmentSize
ptint_order.txt 6.46 KB
barigazy's picture

...

I don't undertand your order. Why do you start with Y pos.
You mean like this?
#1 knot of each spline
s1.k1.pos.X | s2.k1.pos.X | s3.k1.pos.X | s4.k1.pos.X -- x pos
s1.k1.pos.Y | s2.k1.pos.Y | s3.k1.pos.Y | s4.k1.pos.Y -- y pos
s1.k1.pos.Z | s2.k1.pos.Z | s3.k1.pos.Z | s4.k1.pos.Z -- z pos
#2 knot of each spline
s1.k2.pos.X | s2.k2.pos.X | s3.k2.pos.X | s4.k2.pos.X
s1.k2.pos.Y | s2.k2.pos.Y | s3.k2.pos.Y | s4.k2.pos.Y
s1.k2.pos.Z | s2.k2.pos.Z | s3.k2.pos.Z | s4.k2.pos.Z
#3 knot of each spline
s1.k3.pos.X | s2.k3.pos.X | s3.k3.pos.X | s4.k3.pos.X
s1.k3.pos.Y | s2.k3.pos.Y | s3.k3.pos.Y | s4.k3.pos.Y
s1.k3.pos.Z | s2.k3.pos.Z | s3.k3.pos.Z | s4.k3.pos.Z
#4 knot of each spline
s1.k4.pos.X | s2.k4.pos.X | s3.k4.pos.X | s4.k4.pos.X
s1.k4.pos.Y | s2.k4.pos.Y | s3.k4.pos.Y | s4.k4.pos.Y
s1.k4.pos.Z | s2.k4.pos.Z | s3.k4.pos.Z | s4.k4.pos.Z

bga

dingwangfan's picture

One software import need this

One software import need this order

#1 knot of each spline
s1.k1.pos.Y | s2.k1.pos.Y | s3.k1.pos.Y | s4.k1.pos.Y -- y pos
s1.k1.pos.Z | s2.k1.pos.Z | s3.k1.pos.Z | s4.k1.pos.Z -- z pos
s1.k1.pos.X | s2.k1.pos.X | s3.k1.pos.X | s4.k1.pos.X -- x pos
#2 knot of each spline
s1.k2.pos.Y | s2.k2.pos.Y | s3.k2.pos.Y | s4.k2.pos.Y
s1.k2.pos.Z | s2.k2.pos.Z | s3.k2.pos.Z | s4.k2.pos.Z
s1.k2.pos.X | s2.k2.pos.X | s3.k2.pos.X | s4.k2.pos.X
#3 knot of each spline
s1.k3.pos.Y | s2.k3.pos.Y | s3.k3.pos.Y | s4.k3.pos.Y
s1.k3.pos.Z | s2.k3.pos.Z | s3.k3.pos.Z | s4.k3.pos.Z
s1.k3.pos.X | s2.k3.pos.X | s3.k3.pos.X | s4.k3.pos.X
#4 knot of each spline
s1.k4.pos.Y | s2.k4.pos.Y | s3.k4.pos.Y | s4.k4.pos.Y
s1.k4.pos.Z | s2.k4.pos.Z | s3.k4.pos.Z | s4.k4.pos.Z
s1.k4.pos.X | s2.k4.pos.X | s3.k4.pos.X | s4.k4.pos.X

Thanks!

barigazy's picture

...

Here we go

fn storeKnotsPosToTxt spl selectedOnly:off order: txtFile: = 
(
	if isKindOf spl Line or isKindOf spl splineshape do
	(
 
		local splines = if selectedOnly then sort (getSplineSelection spl) else #{1..(numsplines spl)} as array
		if splines.count != 0 do
		(
			local minKnots = amin (for s in splines collect numknots spl s)
			local sioFile = dotNetClass "System.IO.File"
			local coords = #(), cnt = 1, printArr = #()
			while cnt <= minKnots do (append coords (for s in splines collect getKnotPoint spl s cnt) ; cnt+=1)
			for c in coords do
			(
				for p in c do
					for o in order do append printArr ((getProperty p o) as string)
			)
			sioFile.WriteAllLines txtFile printArr ; free printArr ; txtFile
		)
	)
)
storeKnotsPosToTxt $Line001 selectedOnly:on order:#("Y","Z","X") txtFile:@"C:\Temp\knotsPos.txt"

Because output of this fn is the text file path you can at the and use this ...

txt = storeKnotsPosToTxt $Line001 selectedOnly:on order:#("Y","Z","X") txtFile:@"C:\Temp\knotsPos.txt"
edit txt

... to open result in the maxscript editor

bga

dingwangfan's picture

The spline selected on or off never mind !

The spline selected on or off never mind !

barigazy's picture

...

This fn works only for your example (all splines must have same number of knots)

fn storeKnotsPosToTxt spl txtFile: = 
(
	if isKindOf spl Line or isKindOf spl splineshape do
	(
		fn breakUp arr idx = (if idx > arr.count do return #() ; for i = idx to arr.count collect arr[i])
		fn roundP3 val = (for a in #("x","y","z") where abs (getProperty val a) < .0001 do (setProperty val a 0) ; val)		
		local fStream = createFile txtFile
		local minKnots = amin (for s = 1 to numsplines spl collect numknots spl s)
		local oddArr = #(), evenArr = #(), cnt = 1, coords = #()
		while cnt <= minKnots do 
		( 
			kpos = (for s = 1 to numsplines spl collect roundP3 (getKnotPoint spl s cnt))
			if mod cnt 2 != 0 then append oddArr kpos else append evenArr kpos ; cnt += 1
		)
		coords = #(oddArr, evenArr)
		for arr in coords do
		(
			for i = 1 to arr.count do
			(
				while arr[i].count != 0 do
				(
					format "% % % %\n" arr[i][1].y arr[i][2].y arr[i][3].y arr[i][4].y to:fStream
					format "% % % %\n" arr[i][1].z arr[i][2].z arr[i][3].z arr[i][4].z to:fStream
					format "% % % %\n" arr[i][1].x arr[i][2].x arr[i][3].x arr[i][4].x to:fStream
					arr[i] = breakUp arr[i] 5
				)
			)
		)
		flush fStream ; close fStream ; free coords ; free oddArr ; free evenArr
	)
)
storeKnotsPosToTxt selection[1] txtFile:@"c:\temp\test.txt"

bga

dingwangfan's picture

Thank you barigazy!

The script is so Perfect!

barigazy's picture

...

Yep. This function works only if you have spline shape object with 4,8,12,16 etc. splines but if you have different number then you need to change formating part in the code.

bga

dingwangfan's picture

ok ,Tank you !

ok ,Tank you !

Comment viewing options

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