Trying to write a simple script. :)

Tim Parsons

New member
As the title says I'm trying to write a simple Lscript and I've got a question. :) So far I've got a simple script that will select my environment light and toggle the "Effect Specular". I got that to work pretty easy but I want it to select the previous selected item once it selects the environment light and does its thing. I thought it would be as simple as this:

@warnings

generic
{
SelectItem("EnvLight");
AffectSpecular();
SelectPreviousSelectedItem();
}

but to avail. Any help would be appreciated.
 
Thanks Denis. Yeah I had tried that but that just selects the previous item in the scene editor. So if I'm moving the camera around and trigger this script I want the camera to still be selected afterwards. The same if I am moving an object around, I'd like that object to still be selected afterwards instead of selecting the previous item in the scene editor whatever that might be.
 
So if I'm moving the camera around and trigger this script I want the camera to still be selected afterwards. The same if I am moving an object around, I'd like that object to still be selected afterwards instead of selecting the previous item in the scene editor whatever that might be.
You need to store currently selected item (to temp variable), do your stuff, restore previous state..
ps. Actually it is a lot harder: there can be multiple items selected at a time.. I have special framework to do it in one instruction, in my plugins, but it's all C/C++.
 
I think you want to try:

currentItems = Scene().getSelect();
If(nil != currentItems) {
// verify currentItems.count() >= 1
// use item #1:
// currentItems[1].name
// currentItems[1].id
// etc
}
 
Here is the scene and script.
 

Attachments

  • 2020_StartScene_10-19-21.zip
    8.1 KB · Views: 206
  • ToggleEnviroLightSpecular.zip
    275 bytes · Views: 216
...oh, let's just not stop there.

How about one that will toggle Glossy Reflections and Raytrace EVERYTIME a PBR material is applied?

Or, one that will Toggle Affect Volumetrics EVERYTIME a light is added from the default of ON to OFF?
 
Here is the scene and script.
Okay I made a script for you that works. I sent you a private message on facebook

The script does the following:

It changes the AffectSpecular of the EnvLight Only no matter what you have selected even if you have another light selected it will not change the affect specular for that light.

It goes back to the previous selection you had selected before you used the Script

Thanks,
Jason
 
...oh, let's just not stop there.

How about one that will toggle Glossy Reflections and Raytrace EVERYTIME a PBR material is applied?

Or, one that will Toggle Affect Volumetrics EVERYTIME a light is added from the default of ON to OFF?
I can probably get my script to do the 2nd option you suggested.
 
That'd be a start certainly. Give it a shot.

And actually it's broader than just PBR surfaces.
 
That'd be a start certainly. Give it a shot.

And actually it's broader than just PBR surfaces.
Here you go. Just copy the script below and paste it into notepad. Then save it as a .ls file

@warnings

generic
{
AddDistantLight("Distant");
VolumetricLighting();
}


Add it as a plugin and place it where ever you want in your menu. When you click on the button it will add a Distant light to your scene and turn of Affect Volumetrics. If you want to do it for all the other lights just replace the AddDistantLight("Distant"); above with one of the following lines below: Hope this is what you are looking for.

AddAreaLight("<name>");
AddDistantLight("<name>");
AddLinearLight("<name>");
AddPointLight("<name>");
AddSpotlight("<name>");



For example:

@warnings

generic
{
AddAreaLight("Area");
VolumetricLighting();
}

Thanks,
Jason
 
Last edited:
This way it will fail with items, bones, lights..
Not sure what you mean, no confusion with Lscript.

camera = scene.firstSelect();//get current selection
id = camera.id;//The camera id
//...Here the script select something else
SelectItem(camera.id);//select again

Denis.
 
Not sure what you mean, no confusion with Lscript.
That's obvious what I meant...

camera = scene.firstSelect();//get current selection
id = camera.id;//The camera id
..and who said the first item selected is the camera?
//...Here the script select something else
SelectItem(camera.id);//select again
If he is in Camera Mode, and will use his script, it will work OK, (there can be only one camera selected at a time)
But if he is in Object, Bones, Light Mode, and has MULTIPLE items selected, and will use his script (or above one),
will lose item selection, and instead unwanted camera will be selected... SINGLE item != MULTIPLE items..
 
I replied to Tim, who said the Camera was selected first, that's all,
in Lscript ID is not dependant of Selection mode.

Obviously with script in general, which is essentially a macro tool,
you can always imagine another scenario,
and having to add something, that's the game,
especially with this kind of question,
without any kind of context.

There's a isSelected() function in Lscript,
so a multiple selection array can be build with an iteration
of all items.



Denis.
 
Last edited:
There's a isSelected() function in Lscript, so a multiple selection array can be build with an iteration of all items.
And that's what should be done at the beginning, and restored at the end of the script execution, so that you don't accidentally lose your selection...
 
So for a simple lscript and one current item selected (whatever)

scene = getfirstitem(SCENE);
item = scene.firstSelect();//get current selection
previous = item.id;//The item id

//...Here the script do something like adding an Item (whatever)and loose the (single) previous selection

SelectItem(previous);//select again
 
Back
Top