set rect light target position via Python

Hi all,

I am trying to set a Rect light’s target at the world origin or specific coordinate in the world.

I first try to modify the mel code to Python. With moving a rect light’s target in the viewport, I got the code below as a starting point.
setAttr “VRayLightRectShape1.targetPos” -type double3 14.13 -108.221315 -203.228502 ;

However, when I execute this as MEL, the target isn’t moving at all.
setAttr “VRayLightRectShape1.targetPos” -type double3 0.0 0.0 0.0 ;

I have also tried anyway in Python the following code.
cmds.setAttr(‘VRayLightRectShape1.targetPos’, 0.0, 0.0, 0.0, type=“double3”)

There is no error but nor is the light’s target moving to the world origin.

Is there a way to access a Rect light’s target and set its translate or an efficient way to set a rect light pointing at the world origin?

Thanks!

Hey there!

I would just use the “move” command with the absolute flag, example:

//MEL

move -a 0 0 0 “VRayLightRect1”;

python

import maya.cmds as cmds

cmds.move( 0,0,0, ‘VRayLightRect1’,absolute=True)

Kind Regards
Pirmin

Hi Jason.

There is no way to access the target. At least none that I know of.

What we did for the target of VRay lights in Maya back when we added this is that we hooked it to a Maya feature. We added the button to make it more obvious. Otherwise, the ‘target’ manipulator is called with a keyboard hotkey ‘t’, or via menu in Modify > Transformation tools > Show manipulator tool. This calls a maya command ShowManipulatorTool;. We do something very similar to calling this command.

Generally, this ‘target’ tool just makes it easy to use, but I don’t know if there’s a way to control it in animation etc. So the preferred method there would be to

- create a locator (mel: spaceLocator -p 0 0 0;)

- add the light to the selection (the order of selecting is important - target first, light second)

- add an aim constraint.

Here’s a simple snippet for when the locator and light already exist:

select -r locator1 ;
select -tgl VRayLightRect1 ;
doCreateAimConstraintArgList 1 { “1”,“0”,“0”,“0”,“1”,“0”,“0”,“0”,“1”,“0”,“0”,“1”,“0”,“1”,“vector”,“”,“0”,“0”,“0”,“”,“1” };
aimConstraint -mo -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType “vector” -worldUpVector 0 1 0;

Practically, that’s the echo with a list of settings for offsets etc for doCreateAimConstrint.

Thanks guys!

After several attempts, I was able to get a workaround by following the steps below.
Through Python code:
1. create the rect light
2. translate it a bit on positive z. I did (0, 0, 1) via setAttr. (VRay rect light points to negative z as created)
3. do an aimConstraint with maintainOffset=True between the locator at the world origin and the rect light.

Just a note - this seems to be a maya thing. A good way to workaround it would be to never have the locator and light sharing the same coordinates when doing the aim constraint. It’s probably best to offset the locator, and then do the constraint.