oki then iwil do it,
here try this:
Global oldDataPosition = 0
fn getLastSplineDataFrom filePath =
(
local f = openFile my_file mode:“r”
local arr_data = #()
local newDataPosition = 0
while (skipToString f “Start”) != undefined do – case sensitive
(
newDataPosition +=1
)
if newDataPosition == 0 or oldDataPosition >= newDataPosition do return false
oldDataPosition = newDataPosition
while not eof f do
(
local line = readLine f
–if line == “Start” do exit
if line == “End” do – case sensitive
(
flush f
close f
return arr_data
)
arr_data += #(execute line)
)
flush f
close f
return arr_data –this wil return an array from 3Point values
)
fn createLineFrom arr_points =
(
if classOf arr_points != Array or arr_points.count == 0 do return false
local ss = SplineShape pos:arr_points[1]
addNewSpline ss
for i=2 to arr_points.count do
(
addKnot ss 1 #corner #line arr_points[i]
)
updateshape ss
)
createLineFrom (getLastSplineDataFrom “c:\ emp\scan.dat”)
I use that script with this file. whats it suposed to do ?
start
[-43.5, -43.5, -47.8]
[-56.4, -52.1, -58.1]
[-61.5, -59.8, -61.0]
[-60.0, -60.5, -59.1]
[-57.4, -58.3, -53.6]
[-46.1, -49.9, -38.5]
end
start
[-43.5, -43.5, -47.8]
[-54.4, -52.1, -58.1]
[-63.5, -59.8, -61.0]
[-69.0, -60.5, -59.1]
[-56.4, -58.3, -53.6]
[-44.1, -49.9, -38.5]
end
and it gives me this errors in the listener.
0
getLastSplineDataFrom()
createLineFrom()
-- Error occurred in getLastSplineDataFrom()
-- Frame:
-- line: undefined
-- arr_data: undefined
-- newDataPosition: undefined
-- my_file: undefined
-- filePath: "/scan.dat"
-- f: undefined
-- called in anonymous codeblock
-- Frame:
-- Unable to convert: undefined to type: FileName
OK
yes u are right , I forget change some locals , now will be ok
Global oldDataPosition = 0
fn getLastSplineDataFrom filePath =
(
if not doesFileExist filePath do return false
local f = openFile filePath mode:"r"
seek f oldDataPosition -- more sped up
local newDataPosition = oldDataPosition
while (skipToString f "start") != undefined do -- case sensitive
(
newDataPosition = filePos f
print newDataPosition
)
local arr_data = #()
--format "old:% new:%
" oldDataPosition newDataPosition
if newDataPosition == 0 or oldDataPosition >= newDataPosition do return false
oldDataPosition = newDataPosition
seek f newDataPosition
while not eof f do
(
local line = readLine f
if findString line "end" != undefined do exit -- case sensitive (u can avoid findString)
local val = execute line
if classOf val == Point3 do arr_data += #(val)
)
flush f
close f
return arr_data --this wil return 3Point values as array
)
fn createLineFrom arr_points =
(
if classOf arr_points != Array or arr_points.count == 0 do return false
local ss = SplineShape pos:arr_points[1]
addNewSpline ss
for i=2 to arr_points.count do
(
addKnot ss 1 #corner #line arr_points[i]
)
updateshape ss
)
createLineFrom (getLastSplineDataFrom "c:\ emp\\scan.dat")
ok, now it creates the spline, but, it dosn’t read the file each X miliseconds or is it?
also when i write
start
[0,0,0]
[1,1,1]
[2,3,4]
end
start
[2,3,0]
[1,5,1]
[2,6,4]
end
it only creates one spline instead of two.
rollout xxx “” width:249 height:147
(
local filePath = “c:\ emp\scan.dat”
local lastDataPosition = 0, oldModSize = 0, newSpline, scanNewSpline
Timer tmr1 “Timer” pos:[17,16] width:24 height:24 interval:400–40
fn createLineFrom filePath =
(
local f = openFile filePath mode:"r"
seek f lastDataPosition -- continue on last pos
if not eof f do
(
local theLine = readLine f
lastDataPosition = (filePos f) + 3
format "theLine:% filePos:%
” theLine lastDataPosition
if findString theLine “end” != undefined then – case sensitive (u can avoid findString to be more faster)
(
print “spline create end”
/*
if scanNewSpline != undefined do
(
if (queryBox “u like to close shape?”) do close scanNewSpline 1
)
*/
)
else if findString theLine “start” != undefined then
(
newSpline = true
)
else
(
local val = execute theLine
if classOf val == Point3 do
(
if newSpline == true
then
(
print “create new line”
scanNewSpline = SplineShape pos:val
addNewSpline scanNewSpline
addKnot scanNewSpline 1 #corner #line val
newSpline = false
)
else if scanNewSpline != undefined do
(
print “add vert”
addKnot scanNewSpline 1 #corner #line val
updateshape scanNewSpline
)
)
)
)
format “newSpline:% filePos:%
” newSpline lastDataPosition
flush f
close f
–format “scanNewSpline:%
” scanNewSpline
–if scanNewSpline != undefined do (updateshape scanNewSpline; scanNewSpline = undefined)
)
fn needUpdate =
(
if not doesFileExist filePath do return false
if oldModSize == undefined
then oldModSize = getFileSize filePath
else newModSize = getFileSize filePath
local mode = oldModSize < newModSize
oldModSize = newModSize
return mode
)
on tmr1 tick do
(
--print "tick"
if needUpdate() do
(
print "create"
createLineFrom filePath
)
)
)
createDialog xxx
how to use:
- create a file “c:\ emp\scan.dat”
- write first word < start > save file
- after < [1,1,1] > save file
- after < [2,2,2] > save file
- to end current spline < end > save file
etc…
start
[1,1,1]
[2,2,2]
end
Best luck wit you scanner Juan
Hi, ive been trying but i cant get it to work fine … this i what ive get so far. i dont know how to make it read an incomplete spline and add the knots
Global oldDataPosition = 0
rollout xxx "" width:249 height:147
(
local filePath = "c:\ emp\\scan.dat"
local oldModSize = 0
Timer tmr1 "Timer" pos:[17,16] width:24 height:24 interval:40
fn createLineFrom filePath =
(
local f = openFile filePath mode:"r"
seek f lastDataPosition -- continue on last pos
if not eof f do
(
local theLine = readLine f
lastDataPosition = (filePos f) + 3
format "theLine:% filePos:%
" theLine lastDataPosition
if findString theLine "end" != undefined then -- case sensitive (u can avoid findString to be more faster)
(
print "spline create end"
/*
if scanNewSpline != undefined do
(
if (queryBox "u like to close shape?") do close scanNewSpline 1
)
*/
)
else if findString theLine "start" != undefined then
(
newSpline = true
)
else
(
local val = execute theLine
if classOf val == Point3 do
(
if newSpline == true
then
(
print "create new line"
scanNewSpline = SplineShape pos:val
addNewSpline scanNewSpline
addKnot scanNewSpline 1 #corner #line val
newSpline = false
)
else if scanNewSpline != undefined do
(
print "add vert"
addKnot scanNewSpline 1 #corner #line val
updateshape scanNewSpline
)
)
)
)
format "newSpline:% filePos:%
" newSpline lastDataPosition
flush f
close f
--format "scanNewSpline:%
" scanNewSpline
--if scanNewSpline != undefined do (updateshape scanNewSpline; scanNewSpline = undefined)
)
fn getLastSplineDataFrom filePath =
(
local f = openFile filePath mode:"r"
seek f oldDataPosition -- more sped up
local newDataPosition = oldDataPosition
while (skipToString f "start") != undefined do -- case sensitive
(
newDataPosition = filePos f
print newDataPosition
)
local arr_data = #()
--format "old:% new:%
" oldDataPosition newDataPosition
if newDataPosition == 0 or oldDataPosition >= newDataPosition do return false
oldDataPosition = newDataPosition
seek f newDataPosition
while not eof f do
(
local line = readLine f
if findString line "end" != undefined do exit -- case sensitive (u can avoid findString)
local val = execute line
if classOf val == Point3 do arr_data += #(val)
)
flush f
close f
return arr_data --this wil return 3Point values as array
)
fn needUpdate =
(
if not doesFileExist filePath do return false
if oldModSize == undefined
then oldModSize = getFileSize filePath
else newModSize = getFileSize filePath
local mode = oldModSize < newModSize
oldModSize = newModSize
return mode
)
on tmr1 tick do
(
print "tick"
if needUpdate() do
(
print "creating line"
createLineFrom filePath
)
)
)
createDialog xxx
this is a pretty cool project I have a question:
how is the scanner generating the text file? or rather how does it interface with a computer to do so?
this is cool keep on.
`Baker
im using a small program done with visual basic to read the serial port buffer and save the file.
why could we not create a C# extension that reads the serial port and updates in real time ?
shure, that would be gr8… did you think you can help us to do that ? cuz i realy dunno how