Dave Black
12-09-2004, 03:04 PM
--Collects all Editable Poly Objects into an array
PolyObjects = for i in geometry where classof i.baseobject == Editable_Poly and not i.ishidden and i.renderable collect i
--Gets the Material IDs of each obj in "PolyObjects"
InitialpolygonMatIds = for i in PolyObjects collect
(
num_faces = polyop.getNumFaces i.baseobject
for f in 1 to num_faces collect polyOp.getFaceMatID i.baseobject f
)
--TEST: Assigns a random Material ID to each face of each obj in "PolyObjects"
for i in PolyObjects do
(
local num_faces = polyop.getNumFaces i.baseobject
for f in 1 to num_faces do
(
polyop.setfacematid i f (random 1 100)
)
)
--Supposed to Reassign the Material IDs originally stored in "InitialpolygonMatIds" but only works when
--objects have equal face count.
for i in PolyObjects do
(
for j in 1 to PolyObjects.count do
(
num_faces = polyop.getNumFaces i.baseobject
for f in 1 to num_faces do polyop.setfacematid i f InitialpolygonMatIds[j][f]
)
)
This works with only one object, or with multiple objects with an equal number of faces.
If you create two objects with disimilar face counts, and run this script you will get an error.
I have been over these lines of code more times than I can count, and it seems that it should work. What appears to be happening, is that the code is attempting to apply MatIDs to an object when it's face count is out of range for that object. At first, I thought it was a problem with the "num_faces" variable, but the error seems to suggests differently. For instance:
-- Error occurred in f loop
-- Frame:
-- f: 7
-- called in j loop
-- Frame:
-- num_faces: 512
-- j: 2
-- called in i loop
-- Frame:
-- i: $Editable_Poly:Sphere01 @ [-22.015244,54.452343,0.000000]
-- Unable to convert: undefined to type: Integer
Thanks for taking the time to read all that.
This is a part of my script that is restorative. I do a bunch of operations to the objects's matIDs because of a bug in max, and I later want to restore the user's material IDs. My first rule in creating this monster was to "Do no harm". I could omit this step, but I really think it can be done. Perhaps my loops are too complicated...I honestly am out of ideas.
Any thoughts?
-Dave
PolyObjects = for i in geometry where classof i.baseobject == Editable_Poly and not i.ishidden and i.renderable collect i
--Gets the Material IDs of each obj in "PolyObjects"
InitialpolygonMatIds = for i in PolyObjects collect
(
num_faces = polyop.getNumFaces i.baseobject
for f in 1 to num_faces collect polyOp.getFaceMatID i.baseobject f
)
--TEST: Assigns a random Material ID to each face of each obj in "PolyObjects"
for i in PolyObjects do
(
local num_faces = polyop.getNumFaces i.baseobject
for f in 1 to num_faces do
(
polyop.setfacematid i f (random 1 100)
)
)
--Supposed to Reassign the Material IDs originally stored in "InitialpolygonMatIds" but only works when
--objects have equal face count.
for i in PolyObjects do
(
for j in 1 to PolyObjects.count do
(
num_faces = polyop.getNumFaces i.baseobject
for f in 1 to num_faces do polyop.setfacematid i f InitialpolygonMatIds[j][f]
)
)
This works with only one object, or with multiple objects with an equal number of faces.
If you create two objects with disimilar face counts, and run this script you will get an error.
I have been over these lines of code more times than I can count, and it seems that it should work. What appears to be happening, is that the code is attempting to apply MatIDs to an object when it's face count is out of range for that object. At first, I thought it was a problem with the "num_faces" variable, but the error seems to suggests differently. For instance:
-- Error occurred in f loop
-- Frame:
-- f: 7
-- called in j loop
-- Frame:
-- num_faces: 512
-- j: 2
-- called in i loop
-- Frame:
-- i: $Editable_Poly:Sphere01 @ [-22.015244,54.452343,0.000000]
-- Unable to convert: undefined to type: Integer
Thanks for taking the time to read all that.
This is a part of my script that is restorative. I do a bunch of operations to the objects's matIDs because of a bug in max, and I later want to restore the user's material IDs. My first rule in creating this monster was to "Do no harm". I could omit this step, but I really think it can be done. Perhaps my loops are too complicated...I honestly am out of ideas.
Any thoughts?
-Dave
