  | | | Running scripts are slow - newbie | Running scripts are slow - newbie 2005-05-25 - By kim aldis
Back Vbscript you don't have to declare variables unless you set some kind of strange option thing in the script. In Jscript you don't either but it's a good habit to get into, partially for clarity but also because it ensures localisation of variables which in turn prevents nasty overwriting of things like loop variables outside of functions. Consider:
Function foo() {
for ( var i=0; i<10; i++ ) { far(); }
} Function far() { for ( var i=0; i<10; i++ ) { logmessage( "far" ); } }
Without the 'var' declaration, the I loop in far() would overwrite the I variable in foo.
-- --Original Message-- -- From: owner-xsi@(protected) [mailto:owner-xsi@(protected)] On Behalf Of Scott McGinley Sent: 25 May 2005 02:17 To: XSI@(protected) Subject: Re: Running scripts are slow - newbie
hey I've got a question about this script. I'm very much a novice at scripting as well. I see that a few times in the script you use a variable that as far as I can tell wasn't declared.
> >Tframe = 31
> >xPos = oCube.posX.Value > >yPos = oCube.posZ.Value
I was under the impersion that you had to do something like the following
dim Tframe TFrame = 31
I know this is a super beginner question to ask, but could someone elaborate on what the difference is.
scott
--- Rafe Sacks <rafes@(protected)> wrote:
> In general...Avoid selecting anything or running XSI Commands more > times then you have to. > > 1) CreateImageClip should either return the image clip for use so > you don't have to use SelectObj(), or there should be another > version which does. For instance (just removing this one > SelectObj() > should yield a sizable improvement) > > for each oCube in oColl > selectObj oCube > > oCube is already an object. Why select it? > > > > 2) If you are adding the same material to 100+ objects, you should > be able to do it to all objects at once rather then for each > object. > Most commands take a collection or object list. > It takes a LOT less > precessing time to manipulate strings then to run an XSI Command. > Instead of... > > CreateImageClip > "...\Mosaic_test_mdb\Pictures\keith.pic" > SelectObj "Clips.keith_pic" > set oImageClip = Selection(0) > > n Can you do?... > > > set oImageClip = CreateImageClip > "...\Mosaic_test_mdb\Pictures\keith.pic" > > > > > > > These 2 ideals will increase the speed of your code /dramatically/. > > Good luck! > > -- > > __ ____ ____ ____ ____ ____ ____ > R A F E S A C K S > Lead Character TD - Technical > Animal Logic Film > +612 9383 - 4800 > > > > > Jeff McFall wrote: > > >Well it took a bit longer than an evening ;) but I > think Ive mostly made the transition to the object model for at least > parts of this. > >This is my first real XSI script let alone > something using the OM so Im pretty happy with the results - that it > even works) > >Ive learned a ton - thanks to Kim and Bernard for > their tips. > > > >In researching this I am prety sure there are some > additional ways to streamline this. > >Still takes about 4 minutes on my machine to do the > 1500 odd objects. > > > >Much thanks > > > >Jeff > > > > > > > >CreateImageClip > "...\Mosaic_test_mdb\Pictures\keith.pic" > > > >SelectObj "Clips.keith_pic" > > > > > >set oImageClip = Selection(0) > > > >set oImage = oImageClip.GetImage > > > >' set the keyframe # > >Tframe = 31 > > > >set oColl = createobject( "XSI.Collection" ) > > > >' wild card select of everything cube!!! > >oColl.Items = "Cube*" > > > >for each oCube in oColl > > > > selectObj oCube > > > > > >xPos = oCube.posX.Value > >yPos = oCube.posZ.Value > > > > > >' objects X and Z positions must be within the > bounds of the resolution of the image being used > >' my example uses an image of 720 x 540 > > > > xImagepos = CInt(720 - (xPos*100)) > > yImagepos = CInt(540 - (yPos*100)) > > > > > >' read the texture and apply the material > > > > > > set oPixelColor = oImage.GetPixel (xImagepos , > yImagepos) > > > > oCube.AddMaterial( "Phong") > > > > Set oPhong = oCube.Material.Shaders( "Phong" ) > > > > set MatDifRed = oPhong.diffuse.red.AddFCurve() > > set MatDifgreen = > oPhong.diffuse.green.AddFCurve() > > set MatDifblue = oPhong.diffuse.blue.AddFCurve() > > > > > MatDifRed.AddKey Tframe, oPixelColor.Red > > MatDifRed.AddKey Tframe, oPixelColor.Green > > MatDifRed.AddKey Tframe, oPixelColor.Blue > > > > set MatAmbRed = oPhong.ambient.red.AddFCurve() > > set MatAmbgreen = > oPhong.ambient.green.AddFCurve() > > set MatAmbblue = oPhong.ambient.blue.AddFCurve() > > > > > MatDifRed.AddKey Tframe, oPixelColor.Red > > MatDifGreen.AddKey Tframe, oPixelColor.Green > > MatDifBlue.AddKey Tframe, oPixelColor.Blue > > > > > > > >' lift them > > > > height = ((oPixelColor.Red + oPixelColor.blue + > oPixelColor.green) * 1.5) > > > > set lift = oCube.posY.AddFCurve() > > lift.Addkey Tframe, height > > > >' size them * I bet there is a way to do this > with 1 command > > > > > > size = (oPixelColor.Red + oPixelColor.blue + > oPixelColor.green) > > > > set bigness = oCube.sclx.AddFCurve() > > bigness.Addkey Tframe, size > > > > set bigness = oCube.scly.AddFCurve() > > bigness.Addkey Tframe, size > > > > set bigness = oCube.sclz.AddFCurve() > > bigness.Addkey Tframe, size > > > >next > > > > > > > > > > > > > > > > > > > > > > > > > > > >-- --Original Message-- -- > >From: owner-xsi@(protected) > [mailto:owner-xsi@(protected)] On Behalf Of kim aldis > >Sent: Monday, May 23, 2005 5:11 PM > >To: XSI@(protected) > >Subject: RE: Running scripts are slow - newbie > > > >Here's another tip: > > > >For I = 1 to 1567 > > > >Is a bit specific and you probably had to go to > work === message truncated === --- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |