ColMatrix
10-23-2009, 10:58 AM
Hi everyone,
I am having a few issues which worked when testing but when trying to do it issues arrised and I have no idea how to solve it and what I have read I do not understand. Any adivce is greatly appreciate. Note I am new, please excuse the code if it is no optimized, I will attempt this later when it works.
Task
We have made many max files containing the same aircraft and each has different animations and other objects inside. We wish to take this aircraft change the textures and re-render the files again. Since I will be applying this script to the same aircraft containing the same 'named objects' I decided to use this as a means of removing and applying the materials.
Code
--Function that removes all materials applied to the geometry in the array.
fn matRemoval =
(
--Array containing the aircraft geometry
objArray = #($tail01,$tail_support02,$landing_gear_door_rear06,$chassis01,$wing_rear02,$tail_support03,$window_frame_front02,$window_frame_side02,$window_frame_rear02,$landing_gear_door_rear07,$tail_rudder01,$wing_flap_rear02,$wing_flap_rear03,$navigation_light02,$turbine_holder02,$turbine02,$p_turbine_fan02,$flap_movable_rear11,$flap_front18,$flap_front19,$flap_front20,$flap_front21,$flap_front22,$flap_front23,$flap_front24,$p_flap_support02,$turbine_holder03,$turbine03,$flap_front25,$landing_gear_door_rear08,$p_landing_gear_parts_rear02,$door_suspention02,$suspention_hinge10,$p_hinge_pivot04,$suspention_hinge11,$landing_gear_upper_rear02,$suspention_hinge12,$p_hinge_parts03,$suspwntion_hinge02,$p_hinge_pivot05,$landing_gear_lower_rear02,$tyre_rear08,$tyre_rear09,$rim_rear08,$rim_rear09,$rim_rear10,$rim_rear11,$p_landing_gear_parts_lower02,$p_hinge_rod02,$suspention_hinge13,$p_hinge_parts04,$tyre_rear10,$tyre_rear11,$suspention_hinge14,$flap_front26,$flap_front27,$flap_front28,$flap_front29,$flap_front30,$flap_front31,$flap_front32,$p_flap_support03,$p_winglet_points02,$winglet02,$navigation_light03,$flap_movable_rear12,$flap_movable_rear13,$flap_movable_rear14,$flap_movable_rear15,$flap_front33,$window_frame_front03,$window_frame_rear03,$window_frame_side03,$wiper02,$wiper03,$turbine_exhaust02,$turbine_exhaust03,$wing_rear03,$wing_lines03,$p_turbine_fan03,$wing_front02,$flap_movable_front04,$wing_front03,$flap_movable_front03,$p_wing_hinges_front03,$flap_movable_rear16,$wing_lines04,$winglet03,$p_winglet_points03,$p_wing_hinges_front02,$landing_gear_door_rear05,$p_landing_gear_parts_rear01,$door_suspention01,$suspention_hinge05,$p_hinge_pivot02,$suspention_hinge06,$landing_gear_upper_rear01,$suspention_hinge07,$p_hinge_parts01,$suspwntion_hinge01,$p_hinge_pivot03,$landing_gear_lower_rear01,$tyre_rear04,$tyre_rear05,$rim_rear04,$rim_rear05,$rim_rear06,$rim_rear07,$p_landing_gear_parts_lower01,$p_hinge_rod01,$suspention_hinge08,$p_hinge_parts02,$tyre_rear06,$tyre_rear07,$suspention_hinge09,$landing_gear_door_front_small03,$landing_gear_door_front_small02,$landing_gear_door_front02,$landing_gear_door_front03,$landing_gear_front01,$p_headlight_cone02,$p_headlight_glass02,$p_headlight_chrome02,$p_headlight_glass03,$p_headlight_chrome03,$p_headlight_cone03,$shocker_front01,$p_landing_gear_parts_front01,$tyre_front02,$tyre_front03,$rim_front02,$rim_front03)
--Wipes all the materials from the objects in the array.
for i=1 to objArray.count do
(
objArray[i].material = undefined
)
)
--Function that applies new materials
fn applyNewMats =
(
--Arrays containing objects that are to have the same material applied to them.
matEngineOuterCasing = #($turbine02,$turbine03)
matTires = #($tyre_rear08,$tyre_rear09,$tyre_rear10,$tyre_rear11,$tyre_rear04,$tyre_rear05,$tyre_rear06,$tyre_rear07,$tyre_front02,$tyre_front03)
matBaseColour = #($landing_gear_door_rear06,$landing_gear_door_rear07,$wing_flap_rear02,$wing_flap_rear03,$turbine_holder02,$flap_movable_rear11,$turbine_holder03,$flap_front25,$landing_gear_door_rear08,$p_winglet_points02,$winglet02,$flap_movable_rear12,$flap_movable_rear13,$flap_movable_rear14,$flap_movable_rear15,$flap_front33,$wing_front02,$wing_front03,$flap_movable_rear16,$winglet03,$p_winglet_points03,$landing_gear_door_rear05,$landing_gear_door_front_small03,$landing_gear_door_front_small02,$landing_gear_door_front02,$landing_gear_door_front03)
matGrey = #($tail_support02,$tail_support03,$flap_front18,$flap_front19,$flap_front20,$flap_front21,$flap_front22,$flap_front23,$flap_front24,$flap_front26,$flap_front27,$flap_front28,$flap_front29,$flap_front30,$flap_front31,$flap_front32)
matMainBase = #($chassis01)
matSlats = #($flap_movable_front04,$flap_movable_front03)
matEngineExterior = #($p_turbine_fan02,$landing_gear_upper_rear02,$suspention_hinge12,$suspwntion_hinge02,$landing_gear_lower_rear02,$suspention_hinge13,$suspention_hinge14,$turbine_exhaust02,$turbine_exhaust03,$p_turbine_fan03,$landing_gear_front01,$p_landing_gear_parts_front01)
mat_2164 = #($wing_rear02,$wing_rear03)
matTails = #($tail_rudder01,$tail01)
matGlass = #($p_headlight_glass02,$p_headlight_glass03)
matCanadianBase = #($shocker_front01)
matBlank15 = #($window_frame_front02,$window_frame_side02,$window_frame_rear02,$window_frame_front03,$window_frame_rear03,$window_frame_side03)
mat_1521 = #($suspention_hinge09,$suspention_hinge08,$suspwntion_hinge01,$suspention_hinge07,$landing_gear_upper_rear01)
matMetal_1 = #($p_flap_support02,$p_hinge_pivot04,$p_suspention_cable05,$p_suspention_cable06,$p_hinge_pivot05,$p_flap_support03,$p_wing_hinges_front03,$p_wing_hinges_front02,$p_hinge_pivot02,$p_suspention_cable04,$p_suspention_cable03,$p_hinge_pivot03,$p_headlight_chrome02,$p_headlight_chrome03)
matMetal_2 = #($rim_front03,$rim_front02,$p_headlight_cone03,$p_headlight_cone02,$rim_rear07,$rim_rear06,$rim_rear05,$rim_rear04,$suspention_hinge06,$suspention_hinge05,$door_suspention01,$rim_rear11,$rim_rear10,$rim_rear09,$rim_rear08,$suspention_hinge11,$suspention_hinge10,$door_suspention02)
mat_1658 = #($p_landing_gear_parts_rear02,$p_hinge_parts03,$p_landing_gear_parts_lower02,$p_hinge_rod02,$p_hinge_parts04,$p_landing_gear_parts_rear01,$p_hinge_parts01,$p_landing_gear_parts_lower01,$p_hinge_rod01,$p_hinge_parts02)
mat_24 = #($wing_lines03,$wing_lines04)
mat_1132 = #($p_landing_gear_parts_front01)
mat_1788 = #($landing_gear_lower_rear01)
mat_1036 = #($landing_gear_front01)
matBlack = #($wiper03,$wiper02)
mat_08 = #($navigation_light02, $navigation_light03)
--Load a material Library from the specified location
loadMaterialLibrary "R:\MaterialLibraryFile.mat"
--Assign the named material from the current library to the array
matTires.material = currentMaterialLibrary["tires"]
matEngineOuterCasing.material = currentMaterialLibrary["Luftwaffe Engine_Outer_Casing"]
matBaseColour.material = currentMaterialLibrary["Luftwaffe base Colour"]
matGrey.material = currentMaterialLibrary["Luftwaffe _Grey"]
matMainBase.material = currentMaterialLibrary["Luftwaffe main Base"]
matSlats.material = currentMaterialLibrary["Luftwaffe Slats"]
matEngineExterior.material = currentMaterialLibrary["Luftwaffe_Engine_Exterior"]
mat_2164.material = currentMaterialLibrary["Material #2164"]
matTails.material = currentMaterialLibrary["Luftwaffe Tails"]
matCanadianBase.material = currentMaterialLibrary["Canadian_Base"]
matGlass.material = currentMaterialLibrary["glass"]
matBlank15.material = currentMaterialLibrary["Blank 15"]
mat_1521.material = currentMaterialLibrary["Material #1521"]
matMetal_1.material = currentMaterialLibrary["metal_1"]
matMetal_2.material = currentMaterialLibrary["metal_2"]
mat_1658.material = currentMaterialLibrary["Material #1658"]
mat_24.material = currentMaterialLibrary["material24"]
mat_1132.material = currentMaterialLibrary["Material #1132"]
mat_1788.material = currentMaterialLibrary["Material #1788"]
mat_1036.material = currentMaterialLibrary["Material #1036"]
matBlack.material = currentMaterialLibrary["black"]
mat_08.material = currentMaterialLibrary["08 - Default"]
)
--executing the functions
matRemoval()
applyNewMats()
I would like to thank everyone in advance for your help.
Col
I am having a few issues which worked when testing but when trying to do it issues arrised and I have no idea how to solve it and what I have read I do not understand. Any adivce is greatly appreciate. Note I am new, please excuse the code if it is no optimized, I will attempt this later when it works.
Task
We have made many max files containing the same aircraft and each has different animations and other objects inside. We wish to take this aircraft change the textures and re-render the files again. Since I will be applying this script to the same aircraft containing the same 'named objects' I decided to use this as a means of removing and applying the materials.
Code
--Function that removes all materials applied to the geometry in the array.
fn matRemoval =
(
--Array containing the aircraft geometry
objArray = #($tail01,$tail_support02,$landing_gear_door_rear06,$chassis01,$wing_rear02,$tail_support03,$window_frame_front02,$window_frame_side02,$window_frame_rear02,$landing_gear_door_rear07,$tail_rudder01,$wing_flap_rear02,$wing_flap_rear03,$navigation_light02,$turbine_holder02,$turbine02,$p_turbine_fan02,$flap_movable_rear11,$flap_front18,$flap_front19,$flap_front20,$flap_front21,$flap_front22,$flap_front23,$flap_front24,$p_flap_support02,$turbine_holder03,$turbine03,$flap_front25,$landing_gear_door_rear08,$p_landing_gear_parts_rear02,$door_suspention02,$suspention_hinge10,$p_hinge_pivot04,$suspention_hinge11,$landing_gear_upper_rear02,$suspention_hinge12,$p_hinge_parts03,$suspwntion_hinge02,$p_hinge_pivot05,$landing_gear_lower_rear02,$tyre_rear08,$tyre_rear09,$rim_rear08,$rim_rear09,$rim_rear10,$rim_rear11,$p_landing_gear_parts_lower02,$p_hinge_rod02,$suspention_hinge13,$p_hinge_parts04,$tyre_rear10,$tyre_rear11,$suspention_hinge14,$flap_front26,$flap_front27,$flap_front28,$flap_front29,$flap_front30,$flap_front31,$flap_front32,$p_flap_support03,$p_winglet_points02,$winglet02,$navigation_light03,$flap_movable_rear12,$flap_movable_rear13,$flap_movable_rear14,$flap_movable_rear15,$flap_front33,$window_frame_front03,$window_frame_rear03,$window_frame_side03,$wiper02,$wiper03,$turbine_exhaust02,$turbine_exhaust03,$wing_rear03,$wing_lines03,$p_turbine_fan03,$wing_front02,$flap_movable_front04,$wing_front03,$flap_movable_front03,$p_wing_hinges_front03,$flap_movable_rear16,$wing_lines04,$winglet03,$p_winglet_points03,$p_wing_hinges_front02,$landing_gear_door_rear05,$p_landing_gear_parts_rear01,$door_suspention01,$suspention_hinge05,$p_hinge_pivot02,$suspention_hinge06,$landing_gear_upper_rear01,$suspention_hinge07,$p_hinge_parts01,$suspwntion_hinge01,$p_hinge_pivot03,$landing_gear_lower_rear01,$tyre_rear04,$tyre_rear05,$rim_rear04,$rim_rear05,$rim_rear06,$rim_rear07,$p_landing_gear_parts_lower01,$p_hinge_rod01,$suspention_hinge08,$p_hinge_parts02,$tyre_rear06,$tyre_rear07,$suspention_hinge09,$landing_gear_door_front_small03,$landing_gear_door_front_small02,$landing_gear_door_front02,$landing_gear_door_front03,$landing_gear_front01,$p_headlight_cone02,$p_headlight_glass02,$p_headlight_chrome02,$p_headlight_glass03,$p_headlight_chrome03,$p_headlight_cone03,$shocker_front01,$p_landing_gear_parts_front01,$tyre_front02,$tyre_front03,$rim_front02,$rim_front03)
--Wipes all the materials from the objects in the array.
for i=1 to objArray.count do
(
objArray[i].material = undefined
)
)
--Function that applies new materials
fn applyNewMats =
(
--Arrays containing objects that are to have the same material applied to them.
matEngineOuterCasing = #($turbine02,$turbine03)
matTires = #($tyre_rear08,$tyre_rear09,$tyre_rear10,$tyre_rear11,$tyre_rear04,$tyre_rear05,$tyre_rear06,$tyre_rear07,$tyre_front02,$tyre_front03)
matBaseColour = #($landing_gear_door_rear06,$landing_gear_door_rear07,$wing_flap_rear02,$wing_flap_rear03,$turbine_holder02,$flap_movable_rear11,$turbine_holder03,$flap_front25,$landing_gear_door_rear08,$p_winglet_points02,$winglet02,$flap_movable_rear12,$flap_movable_rear13,$flap_movable_rear14,$flap_movable_rear15,$flap_front33,$wing_front02,$wing_front03,$flap_movable_rear16,$winglet03,$p_winglet_points03,$landing_gear_door_rear05,$landing_gear_door_front_small03,$landing_gear_door_front_small02,$landing_gear_door_front02,$landing_gear_door_front03)
matGrey = #($tail_support02,$tail_support03,$flap_front18,$flap_front19,$flap_front20,$flap_front21,$flap_front22,$flap_front23,$flap_front24,$flap_front26,$flap_front27,$flap_front28,$flap_front29,$flap_front30,$flap_front31,$flap_front32)
matMainBase = #($chassis01)
matSlats = #($flap_movable_front04,$flap_movable_front03)
matEngineExterior = #($p_turbine_fan02,$landing_gear_upper_rear02,$suspention_hinge12,$suspwntion_hinge02,$landing_gear_lower_rear02,$suspention_hinge13,$suspention_hinge14,$turbine_exhaust02,$turbine_exhaust03,$p_turbine_fan03,$landing_gear_front01,$p_landing_gear_parts_front01)
mat_2164 = #($wing_rear02,$wing_rear03)
matTails = #($tail_rudder01,$tail01)
matGlass = #($p_headlight_glass02,$p_headlight_glass03)
matCanadianBase = #($shocker_front01)
matBlank15 = #($window_frame_front02,$window_frame_side02,$window_frame_rear02,$window_frame_front03,$window_frame_rear03,$window_frame_side03)
mat_1521 = #($suspention_hinge09,$suspention_hinge08,$suspwntion_hinge01,$suspention_hinge07,$landing_gear_upper_rear01)
matMetal_1 = #($p_flap_support02,$p_hinge_pivot04,$p_suspention_cable05,$p_suspention_cable06,$p_hinge_pivot05,$p_flap_support03,$p_wing_hinges_front03,$p_wing_hinges_front02,$p_hinge_pivot02,$p_suspention_cable04,$p_suspention_cable03,$p_hinge_pivot03,$p_headlight_chrome02,$p_headlight_chrome03)
matMetal_2 = #($rim_front03,$rim_front02,$p_headlight_cone03,$p_headlight_cone02,$rim_rear07,$rim_rear06,$rim_rear05,$rim_rear04,$suspention_hinge06,$suspention_hinge05,$door_suspention01,$rim_rear11,$rim_rear10,$rim_rear09,$rim_rear08,$suspention_hinge11,$suspention_hinge10,$door_suspention02)
mat_1658 = #($p_landing_gear_parts_rear02,$p_hinge_parts03,$p_landing_gear_parts_lower02,$p_hinge_rod02,$p_hinge_parts04,$p_landing_gear_parts_rear01,$p_hinge_parts01,$p_landing_gear_parts_lower01,$p_hinge_rod01,$p_hinge_parts02)
mat_24 = #($wing_lines03,$wing_lines04)
mat_1132 = #($p_landing_gear_parts_front01)
mat_1788 = #($landing_gear_lower_rear01)
mat_1036 = #($landing_gear_front01)
matBlack = #($wiper03,$wiper02)
mat_08 = #($navigation_light02, $navigation_light03)
--Load a material Library from the specified location
loadMaterialLibrary "R:\MaterialLibraryFile.mat"
--Assign the named material from the current library to the array
matTires.material = currentMaterialLibrary["tires"]
matEngineOuterCasing.material = currentMaterialLibrary["Luftwaffe Engine_Outer_Casing"]
matBaseColour.material = currentMaterialLibrary["Luftwaffe base Colour"]
matGrey.material = currentMaterialLibrary["Luftwaffe _Grey"]
matMainBase.material = currentMaterialLibrary["Luftwaffe main Base"]
matSlats.material = currentMaterialLibrary["Luftwaffe Slats"]
matEngineExterior.material = currentMaterialLibrary["Luftwaffe_Engine_Exterior"]
mat_2164.material = currentMaterialLibrary["Material #2164"]
matTails.material = currentMaterialLibrary["Luftwaffe Tails"]
matCanadianBase.material = currentMaterialLibrary["Canadian_Base"]
matGlass.material = currentMaterialLibrary["glass"]
matBlank15.material = currentMaterialLibrary["Blank 15"]
mat_1521.material = currentMaterialLibrary["Material #1521"]
matMetal_1.material = currentMaterialLibrary["metal_1"]
matMetal_2.material = currentMaterialLibrary["metal_2"]
mat_1658.material = currentMaterialLibrary["Material #1658"]
mat_24.material = currentMaterialLibrary["material24"]
mat_1132.material = currentMaterialLibrary["Material #1132"]
mat_1788.material = currentMaterialLibrary["Material #1788"]
mat_1036.material = currentMaterialLibrary["Material #1036"]
matBlack.material = currentMaterialLibrary["black"]
mat_08.material = currentMaterialLibrary["08 - Default"]
)
--executing the functions
matRemoval()
applyNewMats()
I would like to thank everyone in advance for your help.
Col
