[Closed] spline between 2 points
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:\ emp\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]
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
It’s for seperate objects, i’ll have 120 coordinates to produce 60 randomly placed splines
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:\ emp\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
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
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
Just sent it over, but essentailly it’s a .txt file with the lines
0,0,0
100,100,100
kind regards
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 “[%]
” 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
Martijn,
I created a new .txt file & it works fine so please ignore my last mail.
danke vell for your time
cheers
Simon