PDA

View Full Version : Lscript General Questions


foxco
03-24-2006, 05:34 PM
Hey all, it seems to be no secret that lscript documentation is lacking. Id like to use this thread for anyone to post general inquiries for info they cant find in documents. :)

my first 4

1.Generalops <num>, the documentation lists 1-6. Though i know 7 is autosave.. but its not documented, Is there somewhere i can find a list of General ops number fuctions, cause... theres gotta be more?

2.Veiwport Visibility. I would like to make a script to change the Veiwports visibility. ive done some guessing and checking to what that command might be, but to no avail. if someone knows the command for this function that would be great!

3. Wildcards. How can i write a command to select all objects that have, lets say *body* anywhere in their name

4. Command to remove background images

Thanks in advance, I invite anyone to drop in and ask questions here.

-Fox

Freak!!
03-24-2006, 09:58 PM
1) - Generalopts only has [7] booleans i'm aware of...
The 7th is AutoKey on/off and it is actually listed in Bob's 2.6 Lscript HTML docs...

2) - I'm not sure you can do what you want easily, but check all the docs on viewports
including the html notes. Also a friend of mine, Carl Looper wrote a tutorial on writing a viewport object agent you can download the files and tutorial here http://www.clandestine.com.au/Carl/zip/Viewport.zip And see if that will help you.

3) - I don't have tiime right now to check the docs, iv'e done it modeler before,
do you mean Layout or Modeler.... (

4) - I don't think there is one, (could be wrong) you may be able delete the image completely,
and then reload it..... And another workaround or two... I've never tried to sorry...

Sorry for brief reply, i'll edit it later if i get a chance.... Must go replace 1GB ram now before shops shut.... :)

jeremyhardin
03-25-2006, 01:37 AM
2.Veiwport Visibility. I would like to make a script to change the Veiwports visibility. ive done some guessing and checking to what that command might be, but to no avail. if someone knows the command for this function that would be great!

If it's nowhere else, it's in the scene file. So you can always treat it like a text file and get the info you want. I'll see if I can knock up a function for this for you. If you want to give it a go yourself, Make Ortho Camera (http://jeremy.lwidof.net/lscript/#make_ortho_camera) does something similiar with viewport information.

jeremyhardin
03-25-2006, 01:45 AM
3. Wildcards. How can i write a command to select all objects that have, lets say *body* anywhere in their name

off the top of my head for this one..., you'd cycle through the objects in the scene, checking each object's name. you'd add names that match conditions into an array (one at a time as you cycle).

you'd get the size of the array, then set up a looping statement that, for as long as you stayed within the size of the array, would loop through the object names in the array and use
CommandInput("AddToSelection " + the_object_name_variable_here);

jeremyhardin
03-25-2006, 01:59 AM
4. Command to remove background images

none documented. once again, if you want you can edit the scene file as a text file, you can strip that info out, save it as a copy, and load the new edited scene file (but is it worth that? i don't think so).

You can detect it with a scene object agent though. So perhaps you should detect it, and if it's there, prompt the user to remove it.

jeremyhardin
03-25-2006, 04:39 AM
here's a custom function (in an example script) that get's the viewport visibility level for you and acts accordingly. enjoy!


@warnings
@script generic

//here i'm storing the variables that will be called from more than one function.
//their values need to be remembered. so i'm making them global like so.

var visLevel;
var visLevelstr;


generic
{

//call the custom function that will return a number from 0 to 6.
//the function is below the generic portion of the script.
ViewPortVis();


//do what we want, based on the info gathered in the function
if(visLevel == 0)
{
visLevelstr = "Bounding Box";
}
if(visLevel == 1)
{
visLevelstr = "Vertices";
}
if(visLevel == 2)
{
visLevelstr = "Wireframe";
}
if(visLevel == 3)
{
visLevelstr = "Front Faced Wireframe";
}
if(visLevel == 4)
{
visLevelstr = "Shaded Solid";
}
if(visLevel == 5)
{
visLevelstr = "Texture Shaded Solid";
}
if(visLevel == 6)
{
visLevelstr = "Texture Shaded Solid Wireframe";
}

info("Display level is currently: ",visLevelstr);


//end of generic portion of script here
}

ViewPortVis
{

//save the temp scene and parse it for info
AutoConfirm(1);
content_dir = getdir("Content");
temp_dir = getdir("Temp");
chdir(temp_dir);
SaveSceneCopy("vis_level_bak.lws");
scenefile = File("vis_level_bak.lws","r");


//where in the scene is the view level information?
//we'll use a search regular expression to find it.
InputString = s~^ViewLevel.*~;
desiredline = nil;
linenumber = 1;
while(desiredline != InputString)
{
scenefile.line(linenumber);
lineread = scenefile.read();
desiredline = lineread;
linenumber++;
}

//the while went one line too far, so let's go up one to the right info.
scenefile.line(linenumber - 1);


//and now read the info into an array. we do this because we'll be getting
//the size of the array in a moment in order to separate the text from the
//number
linearray[1] = scenefile.read();


//store the view level info by measuring the number characters in the array
//then subtracting the number of letters and spaces before the number
n = sizeof(linearray[1]) - 10;

//and we use that to count from the right of the string we read
//the right number of spaces, effectively separating the number into
//it's own variable
visLevel = number(strright(linearray[1],n));


//close the input file and go back to the content directory
scenefile.close();
filedelete("vis_level_bak.lws");
chdir(content_dir);
AutoConfirm(0);




//end custom function here
}

foxco
03-25-2006, 06:05 AM
Thanks J and Freak!

you have been extrodinary help, but i wont lie, this isnt the last of my questions:)

I have to say.... thats harsh if it requires all that just to find the viewport vis, but i learned a few tricks from reading it. Using the string line -10 chars to get the number, great ouside the box thinking.

New question!

how can i create a prompt to continue running the script or not(i have lots of buttons so, say you click a tool you didnt mean to, i'd like to ask "are you sure you want to run script so and so") It will return a True or false,, or 0,1 im guessing and ill run an If/else to continue or not

Cheers

Fox

jeremyhardin
03-25-2006, 06:20 PM
one of two ways off the top of my head. you could put it into the script doing the running, or in the scripts being run.

either way, you could use something like this.
if this is in the script doing the running, have the button run a function. but whereever you put the script being run...have an 'are you sure prompt' with a yes/no choice or something like that. then have a statement after the prompt that reads the variable from the yes/no choice and act's accordingly. something like...

if(YesNo == 1)
{
//run the script or do what you want here.
}
else
{
info("Script has been cancelled.");
}

foxco
03-26-2006, 06:02 PM
haha, i think you mis-read my Q, or i may have not written it clearly. I understand the if/else and variables, but i didnt understand how to create a button to output a value to the variable :), Thanks all the same though.

I found this requester snippet in a scritp i was reading, then looked in the docs for more info, i didnt find a couple things though, check code for the comments



if(reqisopen())
reqend();
{

reqbegin("Run Script(name)?");

reqsize(200,100);

c1 = ctlbutton("Yes",?,?); // i learned that the first argument is the name,
c2 = ctlbutton("No",?,?); // but i dont know what the next arguments are?

ctlposition(c1,10,10);
ctlposition(c2,55,10);

reqopen();
}



Cheers

-fox

jeremyhardin
03-26-2006, 06:55 PM
i see. this one is in the Lscript user manual.
ctlbutton
ctlbutton() is a "do-something-now" button that triggers a predefined, user-defined function within the script. The width is expressed in pixels.

prototype: <Control Object Agent> ctlbutton(label,
width, action_udf)

label string; the label of the control.

width integer; the width of the control.

action_udf string; the udf to be called when the button is pressed.

example:

@version 2.1
@warnings
c1..2;

generic
{
reqbegin("Testing");
c1 = ctlbutton("Increment",50,"addcount");
c2 = ctlinteger("Count",1);
reqpost();
}

addcount
{
setvalue(c2,getvalue(c2) + 1);
}

foxco
03-26-2006, 07:54 PM
thanks jeremy, I will make a point of looking harder next time since i should have found this info while i was searching.

I do appreciate your patience with all my questions. if the tables were turned, i would do the same.

-fox

jeremyhardin
03-27-2006, 05:51 AM
no problem fox. wasn't even worried about it. :thumbsup:

foxco
03-28-2006, 03:00 AM
Heyo, so i figured out how to get the req to return a true or false, and got the script working like this


@warnings
@name run_prompt

generic
{

reqbegin("Run Script?");
ctltext("","Run script?");

if(reqpost())
{

info("Running script.");
//my commands

}
else
info("Canceled script.");
return;

reqend();

}


Works for what i need, so next i have a few more questions.

1. i made a requester with 3 of my own buttons, (Tool1) (too2) (tool3) so that when i pressed one of the tools it would go to its user defined function, its working, but i cant figure out how to get the requester to close once you press one of the tools, is it possible?.

heres what i worked up so far.


@warnings
@script generic

generic
{

reqbegin("tools");

reqsize(200,100);

c1 = ctlbutton("tool1",50,"func1");
c2 = ctlbutton("tool2",50,"func2");
c3 = ctlbutton("tool3",50,"func3");

ctlposition(c1,10,10);
ctlposition(c2,70,10);
ctlposition(c3,10,35);

reqpost();
}

func1
{

info("User has pressed tool1");

}

func2
{

info("User has pressed tool2");

}

func3
{

info("User has pressed tool3");

}


2. under Window>image processing. do you know the command to change the Dither Intensity?

Cheers

-fox

jeremyhardin
03-28-2006, 03:22 AM
for the closing window under generic, why can't they just press ok or cancel? but you can have the functions close it by using reqabort(); in the function.

And I'm afraid I don't know how to change the dither intensity.

foxco
03-28-2006, 04:13 AM
ok thanks man. there is no particular reason why a person wouldnt have to click Cancel/ok, I asked out of pure curiosity for now and can think of a couple uses for it later :)

cheers

-fox

CGTalk Moderation
03-28-2006, 04:13 AM
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.