PDA

View Full Version : Lscript capability query......



TheMightySpud
12-11-2012, 12:02 PM
Hi all,

I'm hoping someone can provide an answer and hopefully point me in the right direction if it is possible.

Is it possible to create an lscript which creates a list of all objects (ignoring anything that isn't an lwo) inside a specified folder and displays said list in a window in Layout?

I do have further questions on this subject but I'll wait until this one has been answered, because if the answer is no, they'll all be pointless :)

Just to note, I'm very new to lScript, but have done some vb.net coding before.

Thanks
TheMightySpud

sami
12-11-2012, 12:56 PM
Can you clarify? lwo's are objects - so what do you mean? Lights cameras etc are not stored in folders as files - they are saved in the .lws scene file. Need to know what you mean before I can say...

TheMightySpud
12-11-2012, 01:09 PM
Okay, sorry if it wasn't clear.

What I want is a window which lists all the lwo files in a specified folder

sami
12-11-2012, 10:37 PM
Yes totally possible and somewhat trivial. I'll throw something together next time I am back at my desk.

TheMightySpud
12-12-2012, 02:38 AM
Excellent stuff thanks :)

TheMightySpud

sami
12-12-2012, 08:56 AM
Here ya go (not the cleanest code - but I slapped it together super quick):

109782

This is a Modeler script:
109783

Edit:
This is the same thing for Layout (just changed "main" to "generic" if you look at the code)
109784

TheMightySpud
12-12-2012, 09:07 AM
That is absolutely outstanding. Thank you so much. I'm going to take a look and take some time to dissect the script to learn something, but I have no doubt I'll have some more questions soon :)

Again, thanks
TheMightySpud

TheMightySpud
12-12-2012, 09:13 AM
Actually thinking about it, and I'm not looking for you to write the code for this one, just a pointer in the right direction....

Is it possible using that same method to get a list of folders and then the lwo's in those folders?

so it display kinda like.....

Folder 1
-- Object1.lwo
-- Object2.lwo
Folder 2
-- Object3.lwo
-- Object4.lwo

etc.

Kinda like the 'Add Plugins' window

Thanks
TheMightySpud

sami
12-12-2012, 09:29 AM
the data is easy. the controls get a bit tricky because there is no collapsible listbox built in - so either you'd have to roll your own which is a big deal, or you'd have to live with just filling the folder & object names as a regular row and just indenting the Object rows with spaces in the text put into the listbox. Then on top of that you'd have to parse the text of the selected row to determine if you've selected a folder or a file. But sure anything's possible. The code is not super clean - but i made a few comments and named things like you'll be familiar with from vb.

TheMightySpud
12-12-2012, 09:33 AM
Okay, yeah I noticed some familiarity :) Thanks, quite considerate :)

The collapsible way seems a bit contrived so I was thinking how about 2 list boxes? One with Folders, and one with Files, so you select a folder from the first listbox and the second list box updates with the files in that folder.

I'm finding this a little frustrating because in vb.net it would take me about 10 minutes to do everything I want to do. lol.

Thanks
TheMightySpud

sami
12-12-2012, 09:53 AM
Fair enough, but in vb.net it would also take you 3 years to make a renderer ;-)


And yes. 2 list boxes would work. Just remember that Lscript is not an event driven heaven. The callbacks you get are rudimentary but powerful if you think creatively.

TheMightySpud
12-12-2012, 10:01 AM
lol...true, thankfully I'm not making a renderer :-D

My biggest stumbling block at the moment is getting past the non-event driven nature of LScript. LOL.

Thanks for the help :) I will become more and more annoying as the days go by btw. lol.

TheMightySpud

nickdigital
02-12-2013, 11:09 AM
sami,

In your example how do you get the user selection? If I do getvalue on the cltlistbox I get a number but if I plug that value into the array of items it says it's an invalid index item. As a test I've tried string and number math on the value and both come back as invalid for that data type. I would expect an integer to be returned but that doesn't seem to be what I'm getting back.

xchrisx
02-12-2013, 11:31 AM
He is using the lst_event udf which in this case handles the selection. Hopefully this clarifies it http://mikegreen.name/Lscript/Source/Control_Commands.htm#ctllistbox

Setups up the count for the list, the list name, and what happens when something gets clicked in the listbox
lst_AvailableLWOs = ctllistbox("Available LWO files :",300,90, "lst_count", "lst_name", "lst_event");

On click even it automatically gets passed a array of the selection
lst_event: items
{
// 'items' will be received from listbox as an array of integer index values, or 'nil'

if(items == nil)
{
// do nothing
}
else
{
info("You selected: "+items[1]);
}
selectedListItems = items;
}

nickdigital
02-12-2013, 11:58 AM
Ah ok, thanks. That makes sense.

nickdigital
02-12-2013, 02:06 PM
On click even it automatically gets passed a array of the selection


xchrisx, you wanna throw me another bone? So it's passing the selection but from there how can I do something based on the selection? How would I do something to the file that the user selected?

xchrisx
02-12-2013, 02:47 PM
Based off sami's example heres one way to approach it. I added a button to the UI called Do Something. If you select multiple items (or even a single item) and click the Do Something button, it will display your selected items. Either their entry number or object name in this case.111466

nickdigital
02-12-2013, 02:50 PM
I click on "Do something" and it says I have no object selected even though I do have a selection made in the list box.

xchrisx
02-12-2013, 02:54 PM
Hmm thats odd. its working fine here. What version of LW you running?

nickdigital
02-12-2013, 03:11 PM
Hmm thats odd. its working fine here. What version of LW you running?

I tested this in 11.5.

xchrisx
02-12-2013, 04:14 PM
Ah I think i know why. Either disable the info box in the event udf, or turn your alert level to Low. Some reason it doesnt like the info alert and its causing it to trip up.


lst_event: items
{
// 'items' will be received from listbox as an array of integer index values, or 'nil'

if(items == nil)
{
// do nothing
}
else
{
// info("You selected: "+items[1]);
}
selectedListItems = items;
}

sami
02-12-2013, 05:25 PM
cool. it seems you got this under control. :)

If you are using the Layout version of this script and a higher alert level, that could be it. If the info alert is making a Layout dialog pop up that will mess with the timing of the lst_event_udf which gets the selected items. When I tested this I was using info as a status bar text thing - so it was writing the "You selected.." into the status bar which is not a "blocking" or modal action by the UI. When info is an alert dialog it messes up timing and does not give an accurate reflection of what happens with the UI events timing-wise.

see the new thread I'm about to create for a hint on how to better debug (i.e. don't use info to debug)...

nickdigital
02-14-2013, 12:38 PM
Based off sami's example heres one way to approach it. I added a button to the UI called Do Something. If you select multiple items (or even a single item) and click the Do Something button, it will display your selected items. Either their entry number or object name in this case.111466

I think I found a bug in your script. If I select an item(s) and click "Do something" it only returns the item(s) in the list starting from the top, not my actually selected item.

sami
02-14-2013, 04:31 PM
You are probably right. I slapped that together quickly to demonstrate the listbox and file stuff. That demo actually only works for a single select not a multi- select cuz it probably only returns the first item from the selected items array. I'll have a peek when I'm back at my desk but it is a simple fix if you need multiselect capabilities.

nickdigital
02-14-2013, 04:47 PM
Thanks sami,

For now this is more about learning and with code not working it makes it even hard to figure out what is lack of knowledge and bad code. :D

sami
02-14-2013, 06:06 PM
nickdigital, I misunderstood what you said. I checked and my code was fine, xchrisx's code has a slight bug. The mistake is because the selectedListItems array only contains just the numerical indices of the selected items in the list box, while the availableLWOs_listItems array contains all the text string items in the entire list. This fix to his DoSomething click callback will fix that:

names += " " + availableLWOs_listItems[selectedListItems[j]];



doSomething
{
if(selectedListItems != nil)
{
itemNum = "";
names = "";
for(j=1; j<= size(selectedListItems); j++)
{
itemNum += " " + selectedListItems[j];
// Change this next line to this:
names += " " + availableLWOs_listItems[selectedListItems[j]];
}
info("Selected: " + itemNum);
info("Selected: " + names);

}
else
{
info("No object is selected.");
}
}

nickdigital
02-14-2013, 06:17 PM
Oh right, it was xchrisx's code. Sorry for the confusion.

Thanks for posting the fix though. 8)

xchrisx
02-14-2013, 09:53 PM
thats what i get for coding too fast. must have missed that :) good catch sami glad its all sorted out.