[Closed] Spline_IK_control: select the createhelper point
when I created a spline_IK_control,and created 10 points, how I can use for loop to select the points and update their postion?
JHN give me the method
Code:
[left]getProperty $.modifiers[1] #helper_list[/left]Assuming modifiers[1] is the modifier. If you create a modifier in script you could also directly call the getProperty on the modifier like
Code:
[left]getProperty theSplineIKMod #helper_list[/left]Provided theSplineIKMod is the variable pointing to the modifier.
It will return an array of helpers, which you can use to apply the data to.
and what I want to do:
SC=Spline_IK_Control()
addModifier $MySpline01 SC
SC.linkTypes=2
SC.createhelper 10
getProperty SC #helper_list
--a=#helper_list
--dont know how to get the following through
with animation on
for i=1 to 10 do
(
read data from dat file
get point[i]
point[i].pos=readvalue of file
)
theSpline = selection[1]
numSplinePoints = numKnots theSpline
-- I have no clue on how your data looks, so can't help with that.
-- I'm using a sample array of arrays to get data, will generate a 10 row array (time) in wich each row has 8 position values
timeStep = 10
dataArray = for t = 0 to 100 by dataArray collect for o = 1 to numSplinePoints collect [random -100 100,random -100 100,random -100 100]
sc = Spline_IK_Control()
sc.linkTypes=2
addModifier theSpline sc
sc.createhelper numSplinePoints
thePoints = getProperty sc #helper_list
with animate on
for i = 1 to dataArray.count do -- time loop
(
--read data from dat file
for j = 1 to dataArray[i].count do -- data loop
(
at time ((i - 1) * timeStep) -- start at 0 (-1) and times (*) timeStep
thePoints[j].pos = dataArray[i][j]
)
)
I would recommend chewing on this a bit and read through the manual and on this forum about retreiving data from a file, there’s plenty of info on that.
Also try to keep related posts in the same thread, you shouldn’t have to create a new thread for each “clearly related to the original problem” request/question.
Hope this helps,
-Johan
Hi ,JHN , thanks for take time to solve my questions and I will take care next time;)
the data was created by random function ,but we can make it fuitable , isnt it?
here I give the link that the code to create the data I will use to animate the points
http://forums.cgsociety.org/showthread.php?f=98&t=747372
My code as follow,when I excute it , it got a erro:
– Compile error: Unexpected end-of-script
– In line:
/* CREATE A SPLINE */
theSpline = splineShape name:(uniqueName #MySpline) wirecolor:orange -- create a base spline
addNewSpline theSpline -- add a spline
for i = 1 to 10 do
addKnot theSpline 1 #smooth #curve [30*i,0,0] -- add some knots
updateShape theSpline -- Now draw the shape in the viewport
SC=Spline_IK_Control()
addModifier $MySpline01 SC
SC.linkTypes=2
SC.createhelper 10
thePoints =getProperty SC #helper_list
with animate on(
f=getopenfilename types:"data(*.dat)|*.dat|all|*.*"
thefile=openfile f
for t = 0 to 100 by 5 do (
at time t
for i = 1 to thePoints.count do (
local theLine = readLine thefile
if (eof thefile) do ( seek thefile 0 )
local mySet
if (matchPattern theLine pattern:"set *") then (
mySet = (filterString theLine " ")[2] as integer
)
else if (matchPattern theLine pattern:"end set *") then ( )
else if (theLine == "") then ( )
else (
local myPoint3Array = filterString theLine " "
local myPoint3 = point3 (myPoint3Array[1] as float) (myPoint3Array[2] as float) (myPoint3Array[3] as float)
thePoints[i].pos += myPoint3
)
)
)
the data was created by random and the code was given by losbellos as follow
function writeout = (
a=1
b=1000
extfile = createfile "d:/randomdata.dat"
for i= 1 to 44 do (
format "set %
" i to:extfile
for k=1 to 500 do (
format "% % %
" (random a b) (random a b) (random a b) to:extfile
)
format "end set %
" i to:extfile
format "
" i to:extfile
)
close extfile
)
writeout()
some one can figure out why I got the erro ,thanks