ScriptSpot

Forum topic · ScriptSpot How To

trouble with lights

By dwilliamsbehrend · 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)

trouble with lights

dwilliamsbehrend · 2015-10-18

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?

barigazy · 2015-10-18

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

turn on the lights

dwilliamsbehrend · 2015-10-19

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.

barigazy · 2015-10-19

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.

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

dwilliamsbehrend · 2015-10-20

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

barigazy · 2015-10-20

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

lights

dwilliamsbehrend · 2015-10-20

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?

script ?

vusta · 2015-10-18

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