PDA

View Full Version : Lscript If command?


foxco
03-17-2006, 06:05 PM
Hey guys, new to lightwave and i wanted to figure out a quick few things about scripting so i can make Hide/unhide commands via Scaling 1 to 0 and back.

basicaly. I work with multiple scenes, some scenes have a corrector object that override this one object that is always in the scenes. SO i need the script to check if that object is there and if it is, then its the one that needs to be hidden via scaling, if its not in the scene, then the original object is the one that needs to be scaled

IF "object_01" exsists in the scene
(
SelectItem("object_01");
Scale(0,0,0);
)
else
(
SelectItem("object_02");
Scale(0,0,0);

thanks for any help, Cheers

fox

jeremyhardin
03-17-2006, 06:57 PM
Hey guys, new to lightwave and i wanted to figure out a quick few things about scripting so i can make Hide/unhide commands via Scaling 1 to 0 and back.

basicaly. I work with multiple scenes, some scenes have a corrector object that override this one object that is always in the scenes. SO i need the script to check if that object is there and if it is, then its the one that needs to be hidden via scaling, if its not in the scene, then the original object is the one that needs to be scaled

IF "object_01" exsists in the scene
(
SelectItem("object_01");
Scale(0,0,0);
)
else
(
SelectItem("object_02");
Scale(0,0,0);

thanks for any help, Cheers

fox

off the top of my head code:

if(getfirstitem("object_01")
{
EditObjects();
SelectItem("object_01");
//then do whatever you want to object_01 here
}
else
{
if(getfirstitem("object_02") //here i'm just making sure there is an object_02 first
{
EditObjects();
SelectItem("object_02");
//then do whatever you want to object_02 here
}
}

foxco
03-17-2006, 07:30 PM
thanks J,

When i paste and changed the names/scale commands and try to install is just says "Cant find command Generic_test"

i tried this and tried adding the
Generic
{
code
}
tags around the code but both gives me the same error


if(getfirstitem("Move_Corrector")
{
AutoKey();
SelectItem("Move_Corrector");
Scale(0,0,0);
AutoKey();
}
else
{
if(getfirstitem("Move")
{
AutoKey();
SelectItem("Move");
Scale(0,0,0);
AutoKey();
}
}



thanks again

jeremyhardin
03-17-2006, 08:52 PM
hmm. can you post the entire code here? if not, could you email it to me at

jeremyATlwidof.net

?

foxco
03-17-2006, 09:03 PM
heyo,

i tried this

Generic
{

if(getfirstitem("Move_Corrector")
{
AutoKey();
SelectItem("Move_Corrector");
Scale(0,0,0);
AutoKey();
}
else
{
if(getfirstitem("Move")
{
AutoKey();
SelectItem("Move");
Scale(0,0,0);
AutoKey();
}
}

}


I have been putting all little scripts in "Generic" until now ive never tried an if statement so i assume there is somethign different that i need to do?

Generic
{
code
}

jeremyhardin
03-17-2006, 09:07 PM
ah. you have to close the if parentheses.

if(getfirstitem("Move"))

that's the problem.

foxco
03-17-2006, 09:31 PM
oh man, the simple things... Thanks for your help again

i have an additional question, do you know if there is a command to actualy hide, rather than having to Scale zero and back?

cheers bro

-fox

jeremyhardin
03-17-2006, 10:03 PM
ItemVisibility(1);

1 is hidden. textured wire is 7. and you have everything in between.
:D

kevman3d
03-17-2006, 10:12 PM
A quicky piece of feedback here - If the Nulls need to be hidden, I wouldn't use keyframed scales at all (you don't want to start creating keyframes in your scene if you don't need them for animation).

I'd simply set the OpenGL visibility to 'Hidden' like so...

CommandInput("ItemVisibility 0");

After setting the object to invisible, just unselect it to make it disappear (or add a 'select' in your LScript to select the next item). To make it re-appear, just set the ItemVisibility back to, say, 3 (Wireframe)


Kev.

EDIT : Except I see Jeremy already popped in just before and said the same thing... Doh! :)

foxco
03-17-2006, 10:14 PM
Rockin! ill be sure to ask more questions when they arrise.

Cheers

Fox

foxco
03-17-2006, 10:17 PM
thats funny, we all posted at like the same time. anyways the autokey command in my script is to turn off autokeying and turn it back on, Im working on frame by frame tracking/matchmoving so autokey is always on BUT now that i know there is an actual command to change the visability i will be using that instead

thanks to both

-fox

kevman3d
03-17-2006, 10:28 PM
No worries - Actually fyi, you can poll an item for its visibility with the .visibility flag.

ie. object.visibility

The problem is that this value is 1 greater then the ItemVisibility value (for instance, an object that's hidden is 2 if you query the visibility flag, but the value you need to set is 1.)

Why would you need this? Well, you could create an LScript that simply 'flipped' the visibility like this:

theScene = Scene(); // Get scene object
theItem = getSelect() || error("Please select something!"); // Grab the select item(s)

if (item[1].visibility != 2) {
ItemVisibility(1);
info("Item now hidden");
} else {
ItemVisibility(7);
info("Item now unhidden");
}

(You'll have to test that code - Its a quicky 'off the top of my head' thing)

Kev.

jeremyhardin
03-17-2006, 10:49 PM
thats funny, we all posted at like the same time. anyways the autokey command in my script is to turn off autokeying and turn it back on, Im working on frame by frame tracking/matchmoving so autokey is always on BUT now that i know there is an actual command to change the visability i will be using that instead

thanks to both

-fox

no problem! and good tips Kevman!

another simple piece of advice...check the autokey status before toggling.

lwversion = integer(hostVersion());
if(lwversion < 8)
{
info("Um, Autokey needs to be on, but I can't check for you (since you have an older version of LW).");
}

//...some other code stuff here

if(lwversion >= 8)
{
auto_key = Scene().generalopts[7];
}
if(auto_key == 0) //turn autokey on if it's off.
{
AutoKey();
}

//...doing whatever it is that I need autokey on for
if(auto_key == 0) //the variable is still for the initial state, so i'll use this to turn it back on if we turned it off.
{
AutoKey();
}

kevman3d
03-17-2006, 10:57 PM
lol! With all these tips, I'm expecting XsiFox to release a cool new LScript to assist everyone in matchmoving! Hint! Hint! :applause:

foxco
03-17-2006, 11:05 PM
haha, well all i wanted to do was make a button that hides and unhides certain objects or what i have selected, Which is now no big deal at all because i had no idea you could script the visibility with a command since it was not showing up in the command history when you preform the action in the scene editor.

-fox

foxco
03-20-2006, 06:07 PM
i have another question to expand on what we were talking about before,

i would like to expand the script to hide then unhide, BUT when it unhides, it returns to what it had was set to before being hidden. regardless if it was shaded, wirframe or textured?

is this possible to retain that info? or am i stuck to hiding and unhiding to what i set the value.

On a second note, anyone know where i can find some more detailed documentation on lwScript commands. im ok when it comes to script syntax but i need to learn the script commands for lightwave a little better.

Cheers

-fox

jeremyhardin
03-21-2006, 06:56 PM
i have another question to expand on what we were talking about before,

i would like to expand the script to hide then unhide, BUT when it unhides, it returns to what it had was set to before being hidden. regardless if it was shaded, wirframe or textured?

is this possible to retain that info? or am i stuck to hiding and unhiding to what i set the value.
It is possible, but it's debateable whether it's worth the trouble or not. Basically you'd have to have the script be a Master Class script, so that it could stay running in the scene the whole time. Then when you 'run' the script, it could store the object you altered, what the visibility was before, and return to that later, then flush itself.
Another completely far too complicated option would be to output a text file in the temp folder of the users disk, then parse that when you want to return to the previous state.

On a second note, anyone know where i can find some more detailed documentation on lwScript commands. im ok when it comes to script syntax but i need to learn the script commands for lightwave a little better.

1. Lightwave 8 HTML help has an Lscript User manual and Lscript Reference docs included.
2. I have a tutorial online here: http://jeremy.lwidof.net/lscript/tutorial/
3. Layout Commands can be saved to a text file from Layout. Then to use them in Lscript, you use CommandInput("insert layout command here");
4. Lscript Release Notes here: http://www.newtek.com/lightwave/developer/LW80/8lwsdk/docs/lscript/index.html
5. LWSKD sometimes has commands that work in Lscript as well and aren't documented. You don't know until you try.
6. Blind guesses. Once you kind-of get the patterns in Lscript, you can guess what a command would be, and occasionally you're lucky.

CGTalk Moderation
03-21-2006, 06:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.