Notifications
Clear all

[Closed] Why I need to run it twice?

first time I run this script I get error:

-- Unknown property: "count" in undefined

in line:

If boneX.count > 0 then

Second time I run it it works. I really do not know what I am doing wrong. Could someone explain it to me? Please.
here is first part of script (part in witch is probably an error):

ObjA=$
  convertToPoly (snapshot ObjA name:"Booo")
  NumBones = skinOps.GetNumberBones ObjA.modifiers[1]
  --create arays for bones 
  	for i = 1 to NumBones do
  	(
  		stringA  =  "Bone" + i as string  +  " = #()"
  		execute stringA
  	)
  --append vertexes to bone arrays
  	for j = 1 to ( skinOps.GetNumberVertices ObjA.modifiers[1] ) do
  	(
  		BonesCount = skinOps.GetVertexWeightCount ObjA.modifiers[1] j
  		for Bcoun = 1 to BonesCount do
  		(
  			WeightA = skinOps.GetVertexWeight ObjA.modifiers[1] j Bcoun
  			If WeightA >= 0.5 then 
  			(
  				Najdena = (skinOps.GetVertexWeightBoneID ObjA.modifiers[1] j Bcoun) as string
  				execute ("append " + "Bone" + Najdena   + " " + j as string)
  			)
  		)
  	)
  --Create meshes
  	for k = 1 to NumBones do
  	(
  		stringA = "Bone" + k as string
  		execute ("BoneX="+"Bone" + k as string)
  		If boneX.count > 0 then

it goes on but U would be probably not interested how it ends.

2 Replies

efan,

You need to declare your variables properly at the beginning of your script. The first ti it runs, bones doean’t exist, the second time it does because of the first time you ran it.

Josh.

It would help to know what you’re trying to do there…so at least show the complete for-loop that’s crashing…

Anyway…I rewrote your snippet of code…don’t know if it works, since I couldn’t test it (max is busy rendering), but it looks like it should…I am not completely sure about the nested Array creation at the beginning…in any case it looks neater, at least to me…no more ‘execute’…


ObjA=$
  convertToPoly (snapshot ObjA name:"Booo")
  NumBones = skinOps.GetNumberBones ObjA.modifiers[1]
  NumVerts = skinOps.GetNumberVertices ObjA.modifiers[1] 

bonesArr = for i in 1 to NumBones collect #()  

for j in 1 to NumVerts do
(
  BonesCount = skinOps.GetVertexWeightCount ObjA.modifiers[1] j

  for Bcoun = 1 to BonesCount do
  (
    WeightA = skinOps.GetVertexWeight ObjA.modifiers[1] j Bcoun

    If WeightA >= 0.5 then 
    (
      BoneID = skinOps.GetVertexWeightBoneID ObjA.modifiers[1] j Bcoun
      append bonesArr[BoneID] j
    )
  )
)

for i in 1 to NumBones do
(
  if BonesArr[i].count > 0 then
  (
    ...whatever comes in here...
  )
)

Hope it helps (and works ;))