PDA

View Full Version : spline between 2 points


hotknife
06-25-2008, 11:45 AM
I have a script that reads a text file of xyz coordinates & creates dummy objects at these points. I have also read the max script help and got a 2nd script that creates a spline between 2 points. I am however having trouble marrying the 2 together to read a file, create a start & end point and join the 2 with a spline. If anyone could point my thicky head towards a no doubt simple solution I would be very gratefull. (scripts below)

cheers

Simon

script 1

-- open the file as text, read mode
f = openFile "c:\\temp\MeshOutputTest.txt" mode:"rt"
-- if it opened successfully (exists, etc)...
if f != undefined do
(
while not eof f do
(
-- Read a line from the file
l = readline f

-- turn that line into an array of strings using commas as delimiters
lf = filterString l ","

-- Create a Point3 from the array
p = [ lf[ 1 ] as Float, lf [ 2 ] as Float, lf[ 3 ] as Float ]

-- Make a dummy object using that point as pos
d = Dummy pos:p

-- Do whatever else you need to from here on out
-- ...
)
close f
)


script 2

fn drawLineBetweenTwoPoints pointA pointB =
(
ss = SplineShape pos:pointA
addNewSpline ss
addKnot ss 1 #corner #line PointA
addKnot ss 1 #corner #line PointB
updateShape ss
ss
)
newSpline = drawLineBetweenTwoPoints [10,20,30] [100,200,10]

magicm
06-25-2008, 12:02 PM
Is this for a single shape where each point in the file is added to the shape (A---B---C---D...) or separate shapes/spines containing just two knots (A---B, C---D, etc) ?

Martijn

hotknife
06-25-2008, 12:29 PM
It's for seperate objects, i'll have 120 coordinates to produce 60 randomly placed splines

magicm
06-25-2008, 01:39 PM
I haven't tested it but this should work:
(
fn drawLineBetweenTwoPoints pointA pointB =
(
ss = SplineShape pos:pointA
addNewSpline ss
addKnot ss 1 #corner #line PointA
addKnot ss 1 #corner #line PointB
updateShape ss
)

f = openFile "c:\\temp\MeshOutputTest.txt" mode:"rt"
if f != undefined do
(
-- array to store two positions
points = #()
while not eof f do
(
l = readline f
lf = filterString l ","
-- store position in array
append points [lf[1] as Float, lf[2] as Float, lf[3] as Float]
-- create dummy at last read position
d = Dummy pos:points[points.count]
-- two points in array?
if points.count == 2 then
(
-- draw a line between the points
drawLineBetweenTwoPoints points[1] points[2]
-- clear the array
points = #()
)
)
close f
)
)
Cheers,
Martijn

hotknife
06-25-2008, 03:50 PM
Cheers martijn, I'm getting a flag on the line

append points [lf[1] as Float, lf [2] as Float, lf[3] as Float]

and an '--Unable to convert: undefined to type: Float' error

any ideas

magicm
06-25-2008, 03:57 PM
Could you send me the data file you're using so I can see what's going wrong? You can send it to info[at]martijnvanherk[dot]com.

Martijn

hotknife
06-25-2008, 04:04 PM
Just sent it over, but essentailly it's a .txt file with the lines

0,0,0
100,100,100

kind regards

magicm
06-25-2008, 04:15 PM
You forgot to attach the file ;) However, I created a file myself and added some coordinates and the script ran without errors. So I suspect there's an error somewhere in your textfile.

Try putting format "[%]\n" lf right after the lf = filterString l "," line. If you run the script and open the Listener, the last printed line should be the coordinates containing the error.

Cheers,
Martijn

hotknife
06-25-2008, 04:29 PM
Martijn,
I created a new .txt file & it works fine so please ignore my last mail.

danke vell for your time

cheers

Simon

CGTalk Moderation
06-25-2008, 04:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.