Friday, December 28, 2012

CGTalk Question and my reply

http://forums.cgsociety.org/showthread.php?f=98&t=1086207 For those who have access to cgsociety

Hi all,
I'm trying to make a simple script that assigns a random material id to some faces on an editable poly. I've followed through the listener, however when I copy the listener code and try to run it it comes back with an error. I looked in the help and tried materialIDToSet but that didn't seem to work either. It keeps saying "wanted 2 got 1" which sounds like a syntax error?
Its driving me bonkers that it works in the listener but not when I copy it to a script

if random 0 1 == 1 then
(
select $ball
macros.run "Modifier Stack"
"SubObject_4"
$.EditablePoly.SetSelection #Face #{144, 176, 208}
$.EditablePoly.setMaterialIndex 1
)
else
(
select $ball
macros.run "Modifier Stack"
"SubObject_4"
$.EditablePoly.SetSelection #Face #{144, 176, 208}
$.EditablePoly.setMaterialIndex 2
)
----------------------------------------------------------------------------------
The error this throws is saying that setMaterialIndex is expecting two parametres
but it's only getting one. The answer is easily found just by a quick Google search
http://forums.cgsociety.org/archive...p/t-791240.html which tells us to :-

$.EditablePoly.setMaterialIndex 1 0
$.EditablePoly.setMaterialIndex 2 0
---------------------------------------------------------------------------------
My reply was to add some variety to show the if loop working
if random 0 1 == 1 then
r = Sphere radius:19.0 name:"ball" segs:32 mapcoords:on pos:[0.0,0.0,0.0] isSelected:on 
converttopoly r 
subobjectlevel = 4 --go to polygon sub-object level 
r.EditablePoly.SetSelection #Face #{145, 148..150, 177, 180, 182, 209, 212..214, 241..242, 244}
r.EditablePoly.setMaterialIndex 1 0 
)
else 
r = Sphere radius:9.0 name:"balls" segs:32 mapcoords:on pos:[-30.0,0.0,0.0] isSelected:on 
converttopoly r 
subobjectlevel = 4 --go to polygon sub-object level 
r.EditablePoly.SetSelection #Face #{145, 148..150, 177, 180, 182, 209, 212..214, 241..242, 244} 
r.EditablePoly.setMaterialIndex 2 0 
r.extrudeFaces 2.5 
)

No comments:

Post a Comment