Notifications
Clear all

[Closed] many problems

I got stuck in my code.
And I came here as last hope to see if someone could give me some good advice on this.
To be honest myself, my knowledge for Maxscript is very noob, and only things that I know is things that I searched in the internet, so please be patient since you will see alot of strange coding, and mistake.

So first I`m trying to create a array with names of bones that is skinned in my selected model.

     bnumber = skinOps.GetNumberBones $.modifiers[#Skin]
 
     b_list = #()
 
     for i = 1 to bnumber do
         (            
             b_list [i] = skinOps.GetBoneName $.modifiers[#Skin] i 1
 
         )
 
 And this looks works alright.
 
 and now I`m collapsing and apllying the skin again.
 
     maxOps.CollapseNode $ off
     modPanel.addModToSelection (Skin ()) ui:on
     arrbones = $BB_* as array
 
     for i in arrbones do
         (
             skinOps.addBone $.modifiers[#Skin] i 1
         )
 
 Since all my bones is set with "BB" at the begginning I skinned all. (I didn`t know how to bring the selection of bones in stored array and convert to actual bones selection for addBones.)
 So after add all the bones in the scene for my model, now I want to remove the bones that it is not in stored array "b_list".
 
     bnumber = skinOps.GetNumberBones $.modifiers[#Skin]
     b_unit = #()
     b_find = 1
     b_count = 0
         
     for i = 1 to bnumber do
         (    
             b_unit [i] = skinOps.GetBoneName $.modifiers[#Skin] i 1
             b_find = findItem b_list b_unit[i]
                 if b_count < 1 do
                 (
                     print "match"
                     
                     b_count += 1 
                     
                     skinOps.addBone $.modifiers[#Skin] i 1
                 )
             print "not"
         )

As you can see my knowledge for programming is very slow, but since I found most of the tutorial and lessons in the internet too high level for me, I couldn`t solve the problem myself.

Any help will be welcome.
Thanks in advance

4 Replies

(
Local bnumber = skinOps.GetNumberBones $.modifiers[#Skin]
Local b_list = #()

for i = 1 to bnumber do
	(
	append b_list (getnodebyname (skinOps.GetBoneName $.modifiers[#Skin] i 1))
	)

maxOps.CollapseNode $ true
modPanel.addModToSelection (Skin()) ui:on

for i in b_list do
	(
	skinOps.addBone $.modifiers[#Skin] i 1
	)

-- bnumber = skinOps.GetNumberBones $.modifiers[#Skin]
-- b_unit = #()
-- b_find = 1
-- b_count = 0

-- for i = 1 to bnumber do
-- 	(
-- 	b_unit[i] = skinOps.GetBoneName $.modifiers[#Skin] i 1
-- 	b_find = findItem b_list b_unit[i]
-- 	if b_count < 1 do
-- 	(
-- 	
-- print "match"

-- b_count += 1

-- skinOps.addBone $.modifiers[#Skin] i 1
-- 	)
-- 	print "not"
-- 	)

)

I don’t really know what you are trying to do with the last part …maybe you could explain a bit more ?

Thanks Martoyx, for looking at my code.
Id being working more to try to see where is wrong, but didnt work yet.
I did some minor change here so I will try to explain in comment after the code.


         bnumber = skinOps.GetNumberBones $.modifiers[#Skin] ""THIS STORE THE AMOUNT NUMBER OF AMOUNT OF BONES FOR `FOR` OPERATION.""
 	b_unit = #() "" CREATE A ARRAY TO STORE THE NAME OF THE BONES IN THE NEW SKIN""
 	b_find = 1 ""THIS IS A FLOAT VALUE TO INDENTIFY IF THE NEW BONE NAME IS IN THE OLD SKIN BONES NAME LIST""
 	b_count = 0 "" I CREATE THIS BECAUSE i DIDN`T KNOW HOW TO CHANGE THE VALUE FOR `FOR` OPERATION ONCE YOU ARE ALREADY IN THE OPERATION"
 		
 	for i = 1 to bnumber do
 		(	
 			b_unit [i] = skinOps.GetBoneName $.modifiers[#Skin] i 1 ""HERE I GET THE LIST OF THE BONES NAME IN THE SKIN IN ARRAY""
 			b_find = findItem b_list b_unit[i] ""HERE I`M COMPARING THE NEW BONES NAME LIST WITH THE OLD BONES NAME LIST AND RETRIEVING THE VALUE TO B_FIND""
 				if b_find <= 1 do ""IF THE VALUE OF B_FIND IS MORE EQUAL 1, BECAUSE IN CASE THE NEW BONE NAME IS NOT IN THE OLD ONE WILL RETRIEVE 0"" 
 				(
 					print "match"
 					b_count += 1 ""WILL PLUS THE B_COUNT, OR WILL OVERLOAD THE AMOUNT OF BONES RELATED TO VALUE OF i""
 
                                         skinOps.addBone $.modifiers[#Skin] (i - b_count) 1 ""THIS IS TO REMOVE THE BONE THAT DIDN`T MATCH THE NAME IN THE OLD LIST""
 				)
 			print "not"
 		)

Thanks again and please let me know if I`m doing something wrong or all it is worng.

Please wrap your code in [ code ] tags (the # symbol on the WYSWYG editor) to make it easier to read.

	prjfolder = pathConfig.getCurrentProjectFolder()
 
 	bnumber = skinOps.GetNumberBones $.modifiers[#Skin]
 
 	b_list = #()
 
 	for i = 1 to bnumber do
 		(			
 			append b_list (getnodebyname (skinOps.GetBoneName $.modifiers[#Skin] i 1))
 
 		)
 
 	skinOps.SaveEnvelope $.modifiers[#Skin] (prjfolder+"	emp_skin.env")
 		
 	maxOps.CollapseNode $ true
 	modPanel.addModToSelection (Skin ()) ui:on
 
 	for i in b_list do
 		(
 			skinOps.addBone $.modifiers[#Skin] i 1
 		)
 		
 	skinOps.LoadEnvelope $.modifiers[#Skin] (prjfolder+"	emp_skin.env")

Martroyx Id being looking into your code, and I notice the use of append and getnodebyname. And I did some change in my code, but now I got a crash, when I try to save the skin into project folder. The reason I want to do this in code is because, Im using the .x exporter for exporting the model to XNA, but since I need to make some change in the model, I would need to bring the skin history in top of everything and to make it more clean, would be better to collapse and re-skin again, otherwise seems the exporter is saving the skin data of model before the modification.

Thanks Professor, this is my frist try in coding forum so for something I might not be usefull so in any case of trouble please let me know.