addAndweld multiple Shapes to one Spline

Hi iam not realy good in coding, and maybe thats the reason why this short script is just half working - could someone point me in the right direction? i try to slice a object with sections and add those to a spline shape - but it ignores some parts of the selection

- here is my script

---- EDIT ----

HI sorry i dont know how to delete this post - i found the solution -
the problem was that i run through the selection instead of the array - sorry for being stupid ;-)

obj_copyZ=#()
newArray=#()

myZbox = section length:40.0 width:40.0 pos:[0,0,0]

for z in 1 to 10 do
(

box_copy_Z = copy myZbox
box_copy_Z.pos = [0,0,z*10]
append obj_copyZ box_copy_Z
append obj_copyZ myZbox
)

select obj_copyZ
macros.run "Modifier Stack" "Convert_to_Spline"
select obj_copyZ

for p in $ do
(
addAndWeld myZbox p 0.01
)

ANSWER:

obj_copyZ=#()
newArray=#()

myZbox = section length:40.0 width:40.0 pos:[0,0,0]

for z in 1 to 10 do
(

box_copy_Z = copy myZbox
box_copy_Z.pos = [0,0,z*10]
append obj_copyZ box_copy_Z
)

select myZbox
macros.run "Modifier Stack" "Convert_to_Spline"
select obj_copyZ
macros.run "Modifier Stack" "Convert_to_Spline"
select obj_copyZ

for p in obj_copyZ do
(
addAndWeld myZbox p 0.01
)