PDA

View Full Version : Scale object with a TXT file



JML
12-17-2009, 10:25 AM
Hello,

For a new project, I need to scale objects for a diagram.

but because there are going to have like 500+ objects, I
was hoping the scale of each object would be in reference to
a single TXT file to know how much it should scale that object by.

I'm guessing there is nothing in LW that could do that so
I'm thinking it has to be a lscript.
anybody knows how hard it would be to do that ?


Thanks

JML
12-17-2009, 10:28 AM
The best would be actually to have the script create keyframes using
that txt file attached.

So for oranges,
frame 0 = 5000
frame 100 = 6000
frame 200 = 3052

(dependng on the interval value)

Svenart
12-17-2009, 10:58 AM
this is possible, but if you are not familar with lscript, it could take at least a few hours, maybe more. Check out the lscript documentation, it has all informations you need. I dont have so much time to help you much now, but if you have specific questions I can help you.

JML
12-17-2009, 11:42 AM
Yes, I'm looking on how to do it right now, I'm pretty sure it will take me a few hoursss, at least :)
should be interesting.

Thanks

JML
12-17-2009, 02:03 PM
The thing I'm trying to find out right now is how to read a specific line inside a txt file.
let's say I want to read the info on line5 inside list_a.txt.

Inside the script in the begining, I do
list_a = File(/list_a.txt,r);

that read the whole file I guess.

Then I guess I'll need some kind of syntax later to use only the information of line 5 of that list..

Svenart
12-17-2009, 02:16 PM
here a little examplecode...

filename = getfile("Load settings","*.txt",0,1) || error("no file selected!");

f = File(filename,"r") || error("no file selected!");


line1var = f.read();
line2var = f.read();
line3var = f.read();
line4var = f.read();
line5var = f.read();

f.close();

the 5. time f.read is line5... this is the easiest way i guess..

instead of f.read() you can also use f.readNumber() for example..

If you use f.read(), maybe you must convert the value with:

line5var=number(line5var);

JML
12-17-2009, 02:32 PM
thanks a lot,

I'll check it out now

xchrisx
12-17-2009, 04:52 PM
i had a few minutes so i thought i would give it a try. it should easily be modifiable to make it work with setting scale on different keyframes but I didnt have the time to spend on doing it. however it should be a good starting point if you get stuck. also note there isnt a lot of error checking in it. i also attached the script with an example scene to test it on. hope it helps. oh yeah, and make sure autokey is ON when running it.

-c



@warnings
@version 2.2
@name ScaleViaTxt

x;
scaleValue;
itemName;
f;
generic
{
filename = getfile("Load settings","*.txt",0,1) || error("no file selected!");

f = File(filename,"r") || error("no file selected!");
x=1;
while(!f.eof())
{
linevar = parse(" ",f.read());
itemName[x] = linevar[1];
scaleValue[x] = linevar[2];
x++;
}
f.close();

for(i=1; i<x; i++)
{
if(itemName[i] != " " || itemName[i] != nil)
{
SelectItem(itemName[i]);
Scale(int(scaleValue[i]),int(scaleValue[i]),int(scaleValue[i]));
}
}
}

JML
12-17-2009, 06:00 PM
Thanks guys :)

I have the first part of the script working.

Right now, I have 3 lists, list A,B and C into 3 txt files.
I select object 1 , run the script and it create keyframes using
the first line of each list with an interval of X (30 frames right now)
(so frame0=0, frame30=line1 of listA, frame60=line1 of listB,etc..)


The second part is to make it automatic since I'll have to do that on
at least 100 objects..

So it automatically select the object 2 then applys line 2 of each lists.
then select object 3, then applys line 3 of each lists, then etc...



also, small question, when you "CreateKey (30)" , it's in seconds by default, is there a way to do CreateKey by using frames instead ?

Thanks for you help

xchrisx
12-18-2009, 12:48 AM
try something like using Scene().fps:

actualFrame = frameNumber / Scene().fps;
CreateKey(actualFrame);

JML
12-18-2009, 08:13 AM
try something like using Scene().fps:

actualFrame = frameNumber / Scene().fps;
CreateKey(actualFrame);

Thanks, that make sense.

JML
12-22-2009, 09:46 AM
i'm trying to find out how to select a specific object in the scene..
it has to do with select() I'm guessing..

let's say I have 3 objects, orange.lwo,banana.lwo and berry.lwo,
any of you know how do I code so it select banana.lwo ?

thanks a lot

Svenart
12-22-2009, 10:37 AM
i have not tested this, but it should work...

obj = Mesh();
while(obj)
{
if (obj.name == "Banana") SelectItem(obj.id);
obj = obj.next();
}

hope this helps...

JML
12-22-2009, 11:41 AM
Ok, thanks, I'll try that,
I was hoping it would have been something a little easier, like :
select(banana);

:)

JML
12-22-2009, 12:31 PM
Hmm, it works but it seem I can not select a second object after...

After the 'banana' code, I'm trying to select the 'orange' object to do the same thing with 'oranges' values, but it doesn't select it...
and instead stays on the 'banana'..
I'm going to try to figure it out,
any idea ?

----------------------------------
while(obj)
{
if (obj.name == "Bananas") SelectItem(obj.id);
obj = obj.next();
}

GoToFrame (0);
Scale(1,1,1);
CreateKey(scene.currenttime);

GoToFrame (spacing);
Scale(1,line1avar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*2);
Scale(1,line1bvar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*3);
Scale(1,line1cvar,1);
CreateKey(scene.currenttime);

GoToFrame (0);


while(obj)
{
if (obj.name == "Oranges") SelectItem(obj.id);
obj = obj.next();
}

// orange code added later

---------------------------------------

JML
12-22-2009, 12:48 PM
that seem to work but I get "invalid object reference" on line 85. should I just ignore the message?


----------------------------------------------------
while(obj)
{
if (obj.name == "bananas") SelectItem(obj.id);
{obj = obj.next();

GoToFrame (0);
Scale(1,1,1);
CreateKey(scene.currenttime);

GoToFrame (spacing);
Scale(1,line1avar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*2);
Scale(1,line1bvar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*3);
Scale(1,line1cvar,1);
CreateKey(scene.currenttime);

GoToFrame (0);
}


if (obj.name == "oranges") SelectItem(obj.id); <<<<<<<< LINE 85
{obj = obj.next();

GoToFrame (0);
Scale(1,1,1);
CreateKey(scene.currenttime);

GoToFrame (spacing);
Scale(1,line2avar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*2);
Scale(1,line2bvar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*3);
Scale(1,line2cvar,1);
CreateKey(scene.currenttime);

GoToFrame (0);
}

}
-----------------------------------------------------------

Svenart
12-22-2009, 12:54 PM
check, if the 2nd time the script can find "Oranges"

like this...

if (obj.name == "Oranges") info ("found:"+obj.name);

if it can find it, try to use another name than obj... obj2 for example

JML
12-22-2009, 12:58 PM
Ok, I'll try,
it seems the data are mixed up between the fruits.. I'm going to try to give specifc obj names as you say to see if that helps..

thanks

Svenart
12-22-2009, 12:59 PM
maybe you used wrong brace (brackets) here:

while(obj)
{
if (obj.name == "bananas") SelectItem(obj.id);
{obj = obj.next();


both brackest are equal?

Svenart
12-22-2009, 01:05 PM
I think I found the problem... try this :

while(obj)
{

if (obj.name == "bananas")
{

SelectItem(obj.id);

GoToFrame (0);
Scale(1,1,1);
CreateKey(scene.currenttime);

GoToFrame (spacing);
Scale(1,line1avar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*2);
Scale(1,line1bvar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*3);
Scale(1,line1cvar,1);
CreateKey(scene.currenttime);

GoToFrame (0);
}


if (obj.name == "oranges")
{
SelectItem(obj.id);
GoToFrame (0);
Scale(1,1,1);
CreateKey(scene.currenttime);

GoToFrame (spacing);
Scale(1,line2avar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*2);
Scale(1,line2bvar,1);
CreateKey(scene.currenttime);

GoToFrame (spacing*3);
Scale(1,line2cvar,1);
CreateKey(scene.currenttime);

GoToFrame (0);
}

obj = obj.next();

}

JML
12-22-2009, 01:06 PM
that bracket was on purpose..
because right now, I have "while(obj)" at the begining,
then after I have 3 "IF" conditions for each fruit under it.

I tried at first to have 3 "while(obj)" but then it would select only the first
one..

JML
12-22-2009, 01:08 PM
let me try that right now

JML
12-22-2009, 01:14 PM
Thanks a lot, that Works ! :)


by the way why is " obj=obj.next(); " so important at the end ?
(it crash if I remove it)

there is selectitem(obj.id) on top, I wonder why obj.next is needed with it..

Svenart
12-22-2009, 02:17 PM
with " obj=obj.next(); " it is cycling through all your objects... otherwise, it would ... well .... dont know it precisely ... always checking your first obj I think...

and if it would not cycle... selectitem(obj.id) would always be the same id...

xchrisx
12-22-2009, 11:08 PM
SelectItem basically starts a new selection each time it is called. if you want to select more items us the AddToSelection(itemname) command.

JML
12-23-2009, 11:03 AM
Thanks a lot both of you !
it was kind of fun, and it will make things a little bit easier on that project.

The script is working fine now on 3 elements, I just need to copy the code for 100 elements, that will take a little bit of time..

There is a way I could automate it more, and I roughly know how
it would work, but creating the code for it is another story..
maybe I'll try to do it later to get better at it.

Happy holidays