Notifications
Clear all

[Closed] Function not reading array

Hi all,

I am trying to create a function where it takes an array of objects, makes a snapshot of them and then attaches them all together.

The snapshot part seems to work fine, however I’m getting stuck with passing the snapshot objects to be attached.

I have tried defining a local array but cannot seem to append to the SnapShotArray I create to pass on to the attaching code.

How do you pass variables/arrays out of an event handler? I have tried defining the array globally as well.

Any help appreciated.

 fn clusterAttach &objArr =
	  (
	  
		
		for BodyCount = 1 to objArr.count do
		(
		SnapShotArray = #()
		theObj = objArr[BodyCount]
		theTMesh = snapshotAsMesh theObj
		EmptyMesh = Editable_mesh()
		EmptyMesh.mesh = theTMesh
		convertTo EmptyMesh Editable_Poly
		move EmptyMesh[115,0,0]
		append SnapShotArray $EmptyMesh
		print SnapShotArray
		)
		-- Attach --
		  j = 1
		  count = SnapShotArray.count
			  
		  undo off
		  (
			  while SnapShotArray.count > 1 do
			  (				
				  if classof SnapShotArray[j] != Editable_Poly then converttopoly objArr[j]
					  
				  polyop.attach SnapShotArray[j] SnapShotArray[j+1]
				  deleteItem SnapShotArray (j+1)
					  
				  j += 1
					  
				  if (j + 1) > SnapShotArray.count then j = 1
				  
			  )
		  )
		  return SnapShotArray[1]
	  )
1 Reply

Shouldn’t it be return SnapShotArray, not return SnapShotArray[1]?