ScriptSpot home

Forum topic · ScriptSpot How To

trouble with lights

By Darren Williams · 2015-10-16

Description

I am placing a target light in my scene with a simple maxscript script.

I have set the light "enable" to "on" but the light won't turn on unless
I manually open the modify panel and check the "light type" "on" button.

Would like to do this with maxscript.

Any help would be appreciated.

Comments (8)
Darren Williams

trouble with lights

Here is my code...mylight won't turn on until I open Modifier Panel and click
the "light type" "on" button. I can also turn the button on manually by
typing in command line

select $sunlight
max modify mode
$.on = true

or

$.enabled = on

mylight = Targetspot pos:[c1*earth.pos.x,c1*earth.pos.y,c1*earth.pos.z] \
target: (TargetObject pos:[c2*earth.pos.x,c2*earth.pos.y,c2*earth.pos.z]) \
name:"sunlight" enabled:true

Why doesn't the light turn on using the above statement?

Reply to Darren Williams
Branko Živković

Try this FN

fn turnOnOffLight nodes turn: = if nodes.count != 0 do
(
--clearselection()
for node in nodes where isKindOf node Light do
(
--select node ; max modify mode
if (isProperty node #enabled) do node.enabled = turn
if (isProperty node #on) do node.on = turn
)
)
turnOnOffLight (selection as array) turn:off --turn off the lights

Reply to Branko Živković
Darren Williams

turn on the lights

Thanks for your code...but I seem to be doing something wrong.
I copied your function into my script as is...but I'm wondering if I
need to modify anything to get this working...because it's not working as is.

Sigh.

Reply to Darren Williams
Branko Živković

You need to post your script here. Maybe you have problem with your tool. My code works with standard, photometric, mentalray and vray lights. I not have other engines to test it.

Reply to Branko Živković
Darren Williams

here is my code ---why doesn't my light turn on?

resetMaxFile #noprompt --reset the scene
viewport.setLayout #layout_1
viewport.setType #View_persp_user
viewport.SetRenderLevel #smoothhighlights
actionMan.executeAction -844228238 "1" --set viewport to "realistic" shading
actionMan.executeAction -844228238 "6" -- Viewport Lighting and Shadows: Illuminate with Scene Lights
viewport.setGridVisibility 1 false
backgroundColor = color 0 0 0 --Set Environment Background Color to Black
actionMan.executeAction 0 "619" --Use Environment Background Color in Viewport
--create star
sun = Sphere segs:128 mapcoords:true pos:[0,0,0] radius: 5.0 name:"sun"
--create planet
planet = Sphere segs:128 mapcoords:true pos:[100,0,0] radius: 3.0 name:"planet"
--add light
c1 = 0.6
c2 = 1.5
mylight = Targetspot pos:[c1*planet.pos.x,c1*planet.pos.y,c1*planet.pos.z] \
target: (TargetObject pos:[c2*planet.pos.x,c2*planet.pos.y,c2*planet.pos.z]) \
name:"sunlight" enable:true

fn turnOnOffLight nodes turn: = if nodes.count != 0 do
(
--clearselection()
for node in nodes where isKindOf node Light do
(
--select node ; max modify mode
if (isProperty node #enabled) do node.enabled = turn
if (isProperty node #on) do node.on = turn
)
)
turnOnOffLight (selection as array) turn:on --turn on the lights

Reply to Darren Williams
Branko Živković

Your lights are not selected. That's why your code not works
You have two options here:
#1 After you run your code use my function like this


turnOnOffLight (lights as array) turn:on

#2 Or you can put your two lights variables inside array


turnOnOffLight #(sun,mylight) turn:on
Reply to Branko Živković
Darren Williams

lights

Hi. First, thanks for your help. Second, I did what you said. The light
is created but I still have to manually turn it on using the modify panel.

I've tried this on a different computer and I get the same thing.

Any other ideas?

vusta

script ?

maybe if you show the script then ppl can see the bug much quicker...