PDA

View Full Version : Need scripting help


Sbowling
02-11-2007, 01:16 PM
I have a script that creates a curve using some XYZ coordinates stored as an array, then creates clusters with centers on each of the points. I now want to duplicate the objects and move the Nulls around using other coordinates (pos4 for this example), but it doesn't work and the only way I can think of doing this is either to recreate each curve (which is slow) or storing each coordinate separately (which is a pain)

If anyone has a way to make this work, or a better way in general to do this kind of thing (as long as it is in VBScript) I would really appreciate it.



Function Create_Curve()
Pos1 = "0,1,2"

Pos2 = "1,2,3"

Pos3 = "3,4,5"

Pos4 = "-5.25,6.25,-7.23"

CreateCurve 1, 0, "(" & Pos1 & "),(" & Pos2 & "),(" & Pos3 & ")",FALSE, LinearNonInterpolated

SelectObj LinearNonInterpolated

End Function

Function Create_Cls_Null()

set oObj = selection(0)

set oPoints = oObj.activeprimitive.geometry.Points

for i = 0 to (oPoints.count -1)

SelectGeometryComponents oObj &".pnt[" & i & "]"





CreateClusterCenterWithNull



oNull = Selection (0)

SetValue oNull & ".null.primary_icon", 2

SetValue oNull & ".null.size", 0.25

SetValue oNull & ".display.wirecol", 126

Setvalue oNull &".name", "cvNull"& i





next



End Function

Create_Curve

Create_Cls_Null

'****This part doesn't work

Selectobj "cvNull0"

Translate, Pos4

5quid
02-11-2007, 03:38 PM
without trying your script in xsi i can see two major problems.

1 pos1,2,3 etc don't actually exist outside the function (it's called scope)

2. i'm almost 100% sure that the translate command doesn't accept strings for the vector.

________________________
pos1 = a vb array [0,1,2] <- can't for the life of me remember how to create an array in vb
..
...
functiion makeCurve
CreateCurve 1, 0, pos1, pos2 etc
..
end function

makeCure
translate pos4

-------------------------------------------
quick translation of your script to jscript :
var pos1 = [1,2,3]
var pos2 = [1,2,3]
var pos3 = [3,4,5]
var pos4 = [-5.25,6.25,-7.23] // why not make this a vector instead ?
var pos4v = XSIMath.CreateVector3(-5.25,6.25,-7.23);

var crvString = "(" + pos1 + "),(" + pos2 + "),(" + pos3 + ")"

// i didn't see the use of a one line function
var LinearNonInterpolated = CreateCurve(1, 0, crvString, false, null)(0)

var nulls = makeClusterNull(LinearNonInterpolated)

Translate(nulls[0], pos4v.x,pos4v.y, pos4v.z, siRelative, siView, siObj, siXYZ, null, null, null, null, null, null, null, null, null, 0, null);


function makeClusterNull(crv)
{

var retArr = []; // store our nulls here
var i;
var pts = crv.ActivePrimitive.Geometry.Points

for(i=0; i < pts.count; i++)
{
SelectGeometryComponents(crv +".pnt[" + i + "]")
CreateClusterCenterWithNull();
var oNull = Selection(0)
retArr.push(oNull)
SetValue( oNull + ".null.primary_icon", 2)
SetValue( oNull + ".null.size", 0.25 )
SetValue( oNull + ".display.wirecol", 126)
Setvalue( oNull + ".name", "cvNull" + i)

}
return retArr
}

i tried to keep it as similar as your original script, but, it really isn't the way i'd do it
:)

If i was to be transforming nulls into various spaces then i'd never deal with arrays for storing coordinates. go straight for the vectors. it'll save you much heartache later on.

Sbowling
02-11-2007, 09:57 PM
without trying your script in xsi i can see two major problems.

1 pos1,2,3 etc don't actually exist outside the function (it's called scope)

2. i'm almost 100% sure that the translate command doesn't accept strings for the vector.



In case it's not already obvious, I'm still learning scripting. :rolleyes: Anyway, I did have the variables decared in my original script, but I let it out on this small example. As for 2, well that is why I'm here. :)


i tried to keep it as similar as your original script, but, it really isn't the way i'd do it
:)

If i was to be transforming nulls into various spaces then i'd never deal with arrays for storing coordinates. go straight for the vectors. it'll save you much heartache later on.

Awsome! Vectors is exactly what I was looking for, but I didn't quite get it by looking through the docs. You example made it all come together and it works great!

Thank you very much! :bounce:

EDIT: Wow, that's a lot faster. Went from about 3.3 sconds for the script down to under 2 seconds and I can probably shave more time off using vectors in a few other places.

kimaldis
02-13-2007, 07:20 AM
turn off history logging, it'll be even faster.

Sbowling
02-14-2007, 10:56 AM
turn off history logging, it'll be even faster.

Awesome! I turned everythign off and al my objects just pop on screen after a slight delay. If I turn on logmessages only I get a time of just over 1 second for a much more complex version of my script. Thaks a lot Kim!

I've also figured out that by using vectors to create stuff for one sime of my object, I can do the same thing on the other side by adding a - in front of the vector. Fro example, instead of using myvectorpos.x I can use -myvectorpos.x to get the "mirrored" value, so positive will be negative, or negative will be positive. That has saved me a ton of typing.

I think I'm starting to become a scripting junkie. :eek:

Atyss
02-15-2007, 02:07 AM
If I can suggest a slight speed-up:

Replace
SetValue( oNull + ".null.primary_icon", 2)
SetValue( oNull + ".null.size", 0.25 )
SetValue( oNull + ".display.wirecol", 126)
Setvalue( oNull + ".name", "cvNull" + i)

by

oNull.name = "cvNull" + i;

var oPrim = oNull.activeprimitive;
oPrim.parameters( "primary_icon" ).value = 2;
oPrim.parameters( "size" ).value = 0.25;

var oNullProp = oNull.addproperty( "Diplay Property", false );
oNullProp.parameters( "wirecol" ).value = 126;


The object model is your friend.


Cheers
Bernard

Sbowling
02-15-2007, 03:26 AM
Thanks for the tips Bernard. I've actually rewritten this script about 3 times now and it's gone from simple cut and paste to something that roughly resembles code and is over 300 lines at the moment. I've been working on learning the object model, but couldn't figure out how to do a few things in it on my own.

Anyway, I plan on going through Getting Started with Scripting again over the weekend and seeing if I can optimize my code even more. So far I've been having a blast with scripting and may even try moving to Jscrip in the future.

Thanks again for the help. I really appreciate it.

CGTalk Moderation
02-15-2007, 03:26 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.