GMS-575
10-09-2008, 11:10 AM
Hi Folks,
i wrote a small script with a dynamic UI. The script shows all the VrayMtls with reflections and let you change the reflection subdivs of the material. The script generates one main spinner to change all the subdivs at once and spinners to change the subdivs for each VrayMtl. But whenever i evalluate the script the first time i get a error message, the second time everything works fine.
I know that it has to do something with my function to update the main spinner, but i cant find the problem.
Maybe some of you maxscript masters can help me out and show me some tricks.
Cheers Georgios
---------------------------------------------------
-- V-Ray subdiv-O-mat
-- 01.10.2008 GEORGIOS MOUROUSSIDIS
-- v1.0
---------------------------------------------------
-- works only with VrayMtls and VrayMtls in
-- multimaterials
---------------------------------------------------
-- FUNCTIONS
---------------------------------------------------
-- GM_getVrayMaterials
-- GM_getVrayRefMaterials
-- GM_updateSpinnerValues
-- GM_getVrayMatsUI
---------------------------------------------------
---------------------------------------------------
fn GM_getVrayMaterials =
---------------------------------------------------
-- get all vraymaterials VrayMtl
-- return materials
---------------------------------------------------
(
local vrayMultiMats = #()
local vraySingleMats = #()
local vraySceneMats = #()
local sceneMats = ( for o in scenematerials where classof o == vraymtl or classof o == multimaterial collect o ) -- GET ALL VrayMtl MATERIALS
local z = 0
local y = 0
for i = 1 to sceneMats.count do
(
if classof sceneMats[i] == multimaterial then
for x = 1 to sceneMats[i].count do
if classof sceneMats[i][x] == vraymtl then
vrayMultiMats [z+=1] = sceneMats[i][x]
if classof sceneMats[i] == vraymtl then
vraySingleMats[y+=1] = sceneMats[i]
)
vraySceneMats = vraySingleMats + vrayMultiMats
vraySceneMats
)
---------------------------------------------------
fn GM_getVrayRefMaterials =
---------------------------------------------------
-- get all vraymaterials with reflections
-- return materials
---------------------------------------------------
(
local sceneVrayMaterials = GM_getVrayMaterials()
local vrayRefMaterials = #()
local z = 0
for i = 1 to sceneVrayMaterials.count do -- FILTER DOUBLE VALUES IN ARRAY
for j = sceneVrayMaterials.count to i + 1 by -1 do
if sceneVrayMaterials[i] == sceneVrayMaterials[j] do
deleteItem sceneVrayMaterials j
for i = 1 to sceneVrayMaterials.count do -- FILTER REFLECTIV MATERIALS
if sceneVrayMaterials[i].reflection != color 0 0 0 then
vrayRefMaterials [z+=1] = sceneVrayMaterials[i]
vrayRefMaterials
)
---------------------------------------------------
fn GM_updateSpinnerValues GM_rolloutName =
---------------------------------------------------
-- update spinners in the ui
---------------------------------------------------
(
local rolloutName = GM_rolloutName
local vrayMaterials = GM_getVrayRefMaterials()
local rolloutControls = rolloutName.controls
local rolloutSpinner = #()
local z = 0
for i = 1 to rolloutControls.count do -- FILTER ALL SPINNERS
if classOf rolloutControls[i] == SpinnerControl and rolloutControls[i].name != "GM_spinnerAll" then
rolloutSpinner[z+=1] = rolloutControls[i]
for i = 1 to rolloutSpinner.count do -- UPDATE ALL SPINNERS WITH THE spinnerAll VALUE
if rolloutSpinner[i].value != vrayMaterials[i].reflection_subdivs then
rolloutSpinner[i].value = vrayMaterials[i].reflection_subdivs
)
---------------------------------------------------
fn GM_getVrayMatsUI =
---------------------------------------------------
-- build up the main ui
---------------------------------------------------
(
global mainVrayOmatRolloutFloater -- NAME OF THE rolloutFloater
global spinnerArray = GM_getVrayRefMaterials()
local mainRollout = "rolloutMain"
local subRolloutOne = "rolloutOne"
local subRolloutTwo = "rolloutTwo"
local subRolloutAbout = "rolloutAbout"
local spinnerName = "GM_spinner"
local spinnerArrayFiltered = #()
local spinnerValue = 0
local z = 0
local rolloutFloaterHeight = 250
if spinnerArray.count >= 2 then
rolloutFloaterHeight = 250 + spinnerArray.count * 20
try ( closeRolloutFloater mainVrayOmatRolloutFloater ) catch()
mainVrayOmatRolloutFloater = newRolloutFloater "V-Ray subdiv-O-mat" 300 rolloutFloaterHeight
StringStreamRollout = stringStream ""
for i = 1 to spinnerArray.count do
spinnerArrayFiltered[z+=1] = filterString (spinnerArray[i] as string) ":"
format "rollout % \"set all reflection subdivs\" \n" subRolloutOne to:StringStreamRollout
format "(\n" to:StringStreamRollout
format "label GM_label1 \"subdivs\" across:2 align:#left offset:[10,0] \n" to:StringStreamRollout
format "spinner GM_spinnerAll \"\" range:[1,64,8] type:#integer align:#right fieldwidth: 30 \n" to:StringStreamRollout
format "on GM_spinnerAll changed val do for x = 1 to spinnerArray.count do ( spinnerArray[x].reflection_subdivs = val \n GM_updateSpinnerValues(%) ) \n" subRolloutTwo to:StringStreamRollout
format ")\n" to:StringStreamRollout
format "rollout % \"set reflection subdivs\"\n" subRolloutTwo to:StringStreamRollout
format "(\n" to:StringStreamRollout
format "group \"\"\n" to:StringStreamRollout
format "(\n" to:StringStreamRollout
for i = 1 to spinnerArray.count do
(
spinnerValue = spinnerArray[i].reflection_subdivs
format "label GM_spinnerLabel% \"%\" across:2 align:#left offset:[10,0] \n" i spinnerArrayFiltered[i][1] to:StringStreamRollout
format "spinner %% \"\" range:[1,64,%] type:#integer align:#right fieldwidth: 30 " spinnerName i spinnerValue to:StringStreamRollout
)
format ")\n" to:StringStreamRollout
format "label GM_label3 \"\" offset:[-10,-7] \n" to:StringStreamRollout
format "label GM_label4 \"\" offset:[-10,-7] \n" to:StringStreamRollout
for i = 1 to spinnerArray.count do
format "on %% changed value do spinnerArray[%].reflection_subdivs = value\n" spinnerName i i to:StringStreamRollout
format ")\n" to:StringStreamRollout
format "rollout % \"about\"\n" subRolloutAbout to:StringStreamRollout
format "(\n" to:StringStreamRollout
format "label GM_label5 \"\xa9 2008 Georgios Mouroussidis\"\n" to:StringStreamRollout
format "label GM_label6 \"v1.0\"\n" to:StringStreamRollout
format ")\n" to:StringStreamRollout
format "addRollout rolloutOne mainVrayOmatRolloutFloater\n" to:StringStreamRollout
format "addRollout rolloutTwo mainVrayOmatRolloutFloater\n" to:StringStreamRollout
format "addRollout rolloutAbout mainVrayOmatRolloutFloater\n" to:StringStreamRollout
format "rolloutAbout.open = false\n" to:StringStreamRollout
execute( StringStreamRollout as string )
StringStreamRollout = undefined
)
GM_getVrayMatsUI()
i wrote a small script with a dynamic UI. The script shows all the VrayMtls with reflections and let you change the reflection subdivs of the material. The script generates one main spinner to change all the subdivs at once and spinners to change the subdivs for each VrayMtl. But whenever i evalluate the script the first time i get a error message, the second time everything works fine.
I know that it has to do something with my function to update the main spinner, but i cant find the problem.
Maybe some of you maxscript masters can help me out and show me some tricks.
Cheers Georgios
---------------------------------------------------
-- V-Ray subdiv-O-mat
-- 01.10.2008 GEORGIOS MOUROUSSIDIS
-- v1.0
---------------------------------------------------
-- works only with VrayMtls and VrayMtls in
-- multimaterials
---------------------------------------------------
-- FUNCTIONS
---------------------------------------------------
-- GM_getVrayMaterials
-- GM_getVrayRefMaterials
-- GM_updateSpinnerValues
-- GM_getVrayMatsUI
---------------------------------------------------
---------------------------------------------------
fn GM_getVrayMaterials =
---------------------------------------------------
-- get all vraymaterials VrayMtl
-- return materials
---------------------------------------------------
(
local vrayMultiMats = #()
local vraySingleMats = #()
local vraySceneMats = #()
local sceneMats = ( for o in scenematerials where classof o == vraymtl or classof o == multimaterial collect o ) -- GET ALL VrayMtl MATERIALS
local z = 0
local y = 0
for i = 1 to sceneMats.count do
(
if classof sceneMats[i] == multimaterial then
for x = 1 to sceneMats[i].count do
if classof sceneMats[i][x] == vraymtl then
vrayMultiMats [z+=1] = sceneMats[i][x]
if classof sceneMats[i] == vraymtl then
vraySingleMats[y+=1] = sceneMats[i]
)
vraySceneMats = vraySingleMats + vrayMultiMats
vraySceneMats
)
---------------------------------------------------
fn GM_getVrayRefMaterials =
---------------------------------------------------
-- get all vraymaterials with reflections
-- return materials
---------------------------------------------------
(
local sceneVrayMaterials = GM_getVrayMaterials()
local vrayRefMaterials = #()
local z = 0
for i = 1 to sceneVrayMaterials.count do -- FILTER DOUBLE VALUES IN ARRAY
for j = sceneVrayMaterials.count to i + 1 by -1 do
if sceneVrayMaterials[i] == sceneVrayMaterials[j] do
deleteItem sceneVrayMaterials j
for i = 1 to sceneVrayMaterials.count do -- FILTER REFLECTIV MATERIALS
if sceneVrayMaterials[i].reflection != color 0 0 0 then
vrayRefMaterials [z+=1] = sceneVrayMaterials[i]
vrayRefMaterials
)
---------------------------------------------------
fn GM_updateSpinnerValues GM_rolloutName =
---------------------------------------------------
-- update spinners in the ui
---------------------------------------------------
(
local rolloutName = GM_rolloutName
local vrayMaterials = GM_getVrayRefMaterials()
local rolloutControls = rolloutName.controls
local rolloutSpinner = #()
local z = 0
for i = 1 to rolloutControls.count do -- FILTER ALL SPINNERS
if classOf rolloutControls[i] == SpinnerControl and rolloutControls[i].name != "GM_spinnerAll" then
rolloutSpinner[z+=1] = rolloutControls[i]
for i = 1 to rolloutSpinner.count do -- UPDATE ALL SPINNERS WITH THE spinnerAll VALUE
if rolloutSpinner[i].value != vrayMaterials[i].reflection_subdivs then
rolloutSpinner[i].value = vrayMaterials[i].reflection_subdivs
)
---------------------------------------------------
fn GM_getVrayMatsUI =
---------------------------------------------------
-- build up the main ui
---------------------------------------------------
(
global mainVrayOmatRolloutFloater -- NAME OF THE rolloutFloater
global spinnerArray = GM_getVrayRefMaterials()
local mainRollout = "rolloutMain"
local subRolloutOne = "rolloutOne"
local subRolloutTwo = "rolloutTwo"
local subRolloutAbout = "rolloutAbout"
local spinnerName = "GM_spinner"
local spinnerArrayFiltered = #()
local spinnerValue = 0
local z = 0
local rolloutFloaterHeight = 250
if spinnerArray.count >= 2 then
rolloutFloaterHeight = 250 + spinnerArray.count * 20
try ( closeRolloutFloater mainVrayOmatRolloutFloater ) catch()
mainVrayOmatRolloutFloater = newRolloutFloater "V-Ray subdiv-O-mat" 300 rolloutFloaterHeight
StringStreamRollout = stringStream ""
for i = 1 to spinnerArray.count do
spinnerArrayFiltered[z+=1] = filterString (spinnerArray[i] as string) ":"
format "rollout % \"set all reflection subdivs\" \n" subRolloutOne to:StringStreamRollout
format "(\n" to:StringStreamRollout
format "label GM_label1 \"subdivs\" across:2 align:#left offset:[10,0] \n" to:StringStreamRollout
format "spinner GM_spinnerAll \"\" range:[1,64,8] type:#integer align:#right fieldwidth: 30 \n" to:StringStreamRollout
format "on GM_spinnerAll changed val do for x = 1 to spinnerArray.count do ( spinnerArray[x].reflection_subdivs = val \n GM_updateSpinnerValues(%) ) \n" subRolloutTwo to:StringStreamRollout
format ")\n" to:StringStreamRollout
format "rollout % \"set reflection subdivs\"\n" subRolloutTwo to:StringStreamRollout
format "(\n" to:StringStreamRollout
format "group \"\"\n" to:StringStreamRollout
format "(\n" to:StringStreamRollout
for i = 1 to spinnerArray.count do
(
spinnerValue = spinnerArray[i].reflection_subdivs
format "label GM_spinnerLabel% \"%\" across:2 align:#left offset:[10,0] \n" i spinnerArrayFiltered[i][1] to:StringStreamRollout
format "spinner %% \"\" range:[1,64,%] type:#integer align:#right fieldwidth: 30 " spinnerName i spinnerValue to:StringStreamRollout
)
format ")\n" to:StringStreamRollout
format "label GM_label3 \"\" offset:[-10,-7] \n" to:StringStreamRollout
format "label GM_label4 \"\" offset:[-10,-7] \n" to:StringStreamRollout
for i = 1 to spinnerArray.count do
format "on %% changed value do spinnerArray[%].reflection_subdivs = value\n" spinnerName i i to:StringStreamRollout
format ")\n" to:StringStreamRollout
format "rollout % \"about\"\n" subRolloutAbout to:StringStreamRollout
format "(\n" to:StringStreamRollout
format "label GM_label5 \"\xa9 2008 Georgios Mouroussidis\"\n" to:StringStreamRollout
format "label GM_label6 \"v1.0\"\n" to:StringStreamRollout
format ")\n" to:StringStreamRollout
format "addRollout rolloutOne mainVrayOmatRolloutFloater\n" to:StringStreamRollout
format "addRollout rolloutTwo mainVrayOmatRolloutFloater\n" to:StringStreamRollout
format "addRollout rolloutAbout mainVrayOmatRolloutFloater\n" to:StringStreamRollout
format "rolloutAbout.open = false\n" to:StringStreamRollout
execute( StringStreamRollout as string )
StringStreamRollout = undefined
)
GM_getVrayMatsUI()
