Jump to content

Script to Get/Set Light Emitter

Recommended Posts

Major long-shot question here: does any one know of a way to use Vectorscript to get or set a Light object's "Use Emitter", "Brightness Value", and "Brightness Unit" settings?


I'm doing a fairly large exhibit light plot and am trying to do some renderings to realistically show the different fixture types.  Candlepower is a field of the Light Info Record, but as far as I can tell, this only affects how Photometer objects determine brightness and has no affect on intensity in renderings.  So I have been going through selecting each fixture type, right-clicking and selecting "Edit Light," and manually entering the emitter settings so that I can accurately render the light.


This wasn't so bad the first time, but as I make changes to the plot using Replace Lighting Device, it's a bummer to have to manually input the emitter settings when the data is already stored in the incoming Light Info Record.  So I'm hoping to write a script that will set the emitter settings for selected fixtures using the information in the Light Info Record.


So far, I have not been able to find a way to do this.  I tried seeing if I could pull the Light object's parametric record to get access to the field, but nope.  I looked through the function reference and appendix, but there doesn't appear to be object variables associated with the emitter settings or color temperature, nor does there appear to be a way to set the defaults of these at insertion of a Lighting Device object.


I'm guessing that it's straight up not possible, but if anyone has any ideas, I would greatly appreciate it.

Link to comment

If Lights are "normal" PIOs, then it should just be a matter of setting a Record.Field value. You can look up most PIO record fields using a Worksheet Report and see what field values it enters.


Or you can run the script I wrote a long time ago. You probably want to scan the entire thread for some tips. Please an object on a design layer, leave it selected and run the script. You get a worksheet showing every filed in the PIO parameter record as well as what the field type is.


Since you are scripting already, if these are not giving you the values you want, you might want to edit the H2:=GetRecord line to try other record numbers and see if the data is hidden somewhere.


Or @JBenghiat or @Sam Jones will pop in here and tell us exactly how to access.  ;-)

Link to comment

@Pat Stanford It seems that Lights are not standard PIOs, as this was exactly the first thing I tried (I typically try to use the Custom Selection with my criteria set to Field Value, as it lets me see what the field names are for any PIO in the drawing and failing that, I try to find the PIO in the Plug-in Manager to open up its Parameters list in the Edit Definition dialog).  I was not able to get any of that info for Light objects, so I wrote a quick script to count attached records, which returned 0.  So I tried pulling a parametric record and it returned NIL.  Indeed, running your script returns a single worksheet row: "Parameter Fields for PIO: none".


So I suspect that if there is a way to do this with VS, it will be one of those hidden object variables that doesn't appear in the appendix.  I'm writing a script that will let me set the intensity of the Light object embedded in the Lighting Device PIO based on the channel, but I'd love to be able to set the emitter settings based on fixture type.

Link to comment

Maybe this can help:


// Additional Light selectors
const short ovLightUseEmitter                            = 1620;    // Boolean
const short ovLightEmitterBrightness                    = 1621;    // double_gs - >= 0 values
const short ovLightBrightnessUnit                        = 1622;    // short - 0..3 - eLumens, eCandelas, eLux, eFootcandels
const short ovLightUseTemperature                        = 1623;    // Boolean
const short ovLightTemperature                            = 1624; // double_gs - >= 0 values
const short ovLightCausticPhotons                        = 1625; // Uint32 - kLightCausticNone = 0, kLightCausticLow = 10000, kLightCausticMedium = 100000, kLightCausticHigh = 1000000, kLightCausticVeryHigh = 10000000 
const short ovLightCausticOnly                            = 1626; // Boolean

  • Like 1
Link to comment

This one does work. You'll just need to reset the object after setting the value(s).

I noticed that after running the single-line script "SetObjectVariableBoolean(LSActLayer, 1620, TRUE)", the fact that the emitter was activated was only visible in the OIP after deselecting and reselecting the light object.



    _hObj: HANDLE;
    _b: BOOLEAN;

    _hObj := LSActLayer;
    _b := GetObjectVariableBoolean(_hObj, 1620);
    SetObjectVariableBoolean(_hObj, 1620, NOT(_b));

Run (test);

Link to comment

There is also these procedures which will get and set the brightness:


GetLightInfo(h : HANDLE; VAR lightType, brightness : INTEGER; VAR isOn, castShadow : BOOLEAN);
SetLightInfo(h : HANDLE; lightType, brightness : INTEGER; isOn, castShadow : BOOLEAN);


I think you can also do this using Get/SetObjectVariableReal() using 51.


  • Like 1
Link to comment

@Julian Carr I found all of those procedures earlier, but need more control of the emitter settings.


Using the object variable 51 sets the dimmer %, but does not affect the actual brightness of the emitter.  As an example, I'm using track head fixtures with some LED retrofit PAR lamps.  Some of these are lamped with a 9deg spot lamp with a peak candela 23,680.  Some of these are lamped with 25deg lamps with a peak candela of 6900.  Both of these could have object variable 51 set to 100%, but the spot would in reality be much, much, much brighter.  To set that, you would need to set the brightness value to match the peak candela of the lamp, and, at least in the vanilla VS function reference, there is no listed object variable to get to those settings.


@Peter Vandewalle I figured out the ResetObject thing while I was futzing around with adjust the brightness of the lights.  The issue I was running into, is that this trick seems to only work on VW2021, running your script in 2019 or 2020 results in nothing happening, so these object variables must be a very recent addition.  I primarily drive VW2019, so those scripts didn't work when I was testing and writing my scripts.  Unfortunately for me, the client I'm working with on this project only has VW2019, so unless I want to keep back-saving drawings for them, I'm back to setting the emitters manually.


But I do most appreciate you sharing those object variables with me.  They are now tucked away in my Vectorscript Reference files.

Edited by Jesse Cogswell
Link to comment

This only works for 2021. If you're looking to set the brightness for an embedded light in a Lighting Device, the process is a little more complicated, as you have to access the profile group of the Lighting Device and find the light object.


FYI, BeamViz 6 will create a render light based on candlepower, standalone or linked to a Lighting Device.

  • Like 1
Link to comment

I reverse engineered the naming convention for the embedded Light object in Lighting Devices and used GetObject to get the handle to great success.


BeamViz looks awful fancy, can it render elliptical beam spreads in RW?  That's something that's killing me at the moment because I often utilize linear diffusion for lighting exhibits, and RW can't properly render them.

Link to comment
38 minutes ago, Jesse Cogswell said:

BeamViz looks awful fancy, can it render elliptical beam spreads in RW?  That's something that's killing me at the moment because I often utilize linear diffusion for lighting exhibits, and RW can't properly render them.

BeamViz will create a mask to simulate elliptical beams — basically the equivalent of having an elliptical-shaped gobo. You don't quite get the falloff of a PAR, but you get an idea of the correct shape.

To truly render what you want, you need to set the light type to custom and load an .ies file for the light source. BeamViz will keep this edit, though the Lighting Device doesn't seem to. Neither seems to allow for specifying the beam rotation — that's only available with a stand-alone render light. There also isn't currently a way to load the .ies file via script.

  • Like 1
Link to comment

I had attempted using IES files before, but if the light is embedded in a Lighting Device, it can only be a Spot type.  If you select Custom and set an IES file, it reverts back to Spot when you close the dialog.  I then tried using shutters with Soft Shadows enabled, but that didn't work either.  I didn't think about using a gobo, that's a pretty clever way around it.

Link to comment

@JBenghiat Thank you so much for mentioning the profile group.  I ported by Set Light Levels by Channel script over to VW2021 to start working on the emitter script, only to realize that they completely changed the embedded light naming convention and my previous script completely broke.  I was having a hell of a time trying to get a handle to the embedded light trying FInGroup and FInSymDef to no avail.  Looking back at your post, I saw the profile group comment and looked up GetCustomObjectProfileGroup, which worked like a charm.  But if I just had the Function Reference to go off of, which only mentions the function in relation to path objects and CreateExtrudeAlongPath, I would never have found it.



Edited by Jesse Cogswell
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...