View Full Version : XSI Scripting curve length?
MasterZ 11-07-2006, 05:54 AM I have been using particles to get a PathLength that's useful to me, but after deforming particles the pathLength is invalid.
I have generated paths from objects (actual nulls attached to particles) and I want to know the curves length, alas I'm kinda having trouble asking a curve what it's length is.
GetLength or maybe Length seemed to be things a curve should respond to but I can't seem to get the most obvious data out of them I need.
Please explain my/our options to determine the length of a curve.
|
|
kimaldis
11-07-2006, 06:14 AM
from the documentation - look under NurbsCurve, properties:
set oObject = Application.ActiveProject.ActiveScene.Root.AddGeometry("Arc","NurbsCurve")set oNurbsCurveList = oObject.ActivePrimitive.Geometryset oNurbsCurve = oNurbsCurveList.Curves(0)logmessage oNurbsCurve.Length
MasterZ
11-07-2006, 07:13 AM
Oh ya try to use the # button for code wrapping it's helpful.
I tried that and got errors, I found this too under Length (NurbsCurveList)
In XSI 5.11 they all return Errors like semi-colon expected, but it's more serious then that.
Also there are typos etc. and after extensive tests I don't get the results expected.
Working in JScript currently as well, seems to be if examples lack JScript it's buggy or unsupported maybe not sure why it's missing at times.
You'd think there examples like this one below would work?
NewScene
CreatePrim "Arc", "NurbsCurve"
set oObj = selection(0)
FreezeObj oObj
set oNurbsCurveList = oObj.ActivePrimitive.Geometry
oNurbsCurveList.curves(0).Get _
siSiNurbs, _
aControlVertex, _
aKnots,_
bClosed,_
lDegree,_
eParameterization
'Translate every controlvertex of the new curve from 5 in x
for i = lbound(aControlVertex,2) to ubound(aControlVertex,2)
aControlVertex(0,i) = aControlVertex(0,i) + 5
next
call oNurbsCurveList.AddCurve( _
aControlVertex,_
aKnots,_
bClosed,_
lDegree,_
eParameterization,_
siSiNurbs)
logmessage "Curve 0 Length : " & oNurbsCurveList.Curves(0).Length
logmessage "Curve 1 Length : " & oNurbsCurveList.Curves(1).Length
logmessage "CurveList Lenght: " & oNurbsCurveList.Length
MasterZ
11-07-2006, 07:26 AM
Although I'm using a JScript Plugin lets look at this expample run in the script window...
First make a Modelling Create Curve Draw Cubic by CVs
Actual code doesn't matter...
SICreateCurve("crvlist", 3, 0);
SIAddPointOnCurveAtEnd("crvlist", -1.41700126449543, 4.82687055924962, 0, false, 0, null);
SIAddPointOnCurveAtEnd("crvlist", -0.953418613329148, 4.84342584719889, 0, false, 0, null);
SIAddPointOnCurveAtEnd("crvlist", -1.06103601449275, 3.8501085702425, 0, false, 0, null);
SIAddPointOnCurveAtEnd("crvlist", -1.4252795261234, 3.67627804677513, 0, false, 0, null);
SelectObj("crvlist", null, true);
Then run this part you'd expect to work in the script window..
var lengthVal;
selection(0).GetLength(lengthVal)
LogMessage("Length? : " + lengthVal)
Error returned
//ERROR : Object doesn't support this property or method - [line 2]
Is this a JScript issue? What's wrong with it? Should it be made to work this way anyway?
It really should work to simply say this ...
LogMessage("Length? : " + selection(0).Length)
Also interesting if you try this...
LogMessage("Length? : " + crvlist.length)
It says...
//ERROR : 'crvlist' is undefined - [line 1]
which is really not the functionality one would expect from a useful implimentation. Is it?
kimaldis
11-07-2006, 08:46 AM
your understanding of how scripting and the object model works seems to be lacking:-
1. where do you get the method GetLength() from? There is no such method.
2. using just a selection isn't enough. The curve is a member of the curvelist which in turn is a property of the object's geometry. Try this:
var oCirc = CreatePrim("Circle", "NurbsCurve", null, null);var oCrv = oCirc.ActivePrimitive.Geometry.curves(0);
logmessage( oCrv.length );
3. you're getting crvlist undefined because it's, well, undefined. You've neither declared it nor assigned it.
4. Jscript doesn't support return values in arguments, so even if GetLength was a valid method of the selection nothing could be returned in it's argument.
you seem to be making random stabs in the dark then complaining that it doesn't work. It was me I'd spend some time working through the documentation and it's examples.
one of the most productive things you can do if you're going to be doing a lot of this is to become familiar with the documentation; learn to use it well and efficiently.
:-) K.
kimaldis
11-07-2006, 08:50 AM
var oCirc = CreatePrim("Circle", "NurbsCurve", null, null);
var oCrv = oCirc.ActivePrimitive.Geometry.curves(0);
logmessage( oCrv.length );
sorry
MasterZ
11-07-2006, 08:55 AM
Yes this is working correctly for me thanks for the help.
var obj = ActiveSceneRoot.findChild("TheCurve");
var crvlist = obj.ActivePrimitive.Geometry;
var curve = crvlist.curves(0);
logmessage(curve.length);
Mic_Ma
11-07-2006, 09:02 AM
Don't know much about the subject but I made a little test. Make a curve and select, then run this VBScript
set oLeng = selection(0)
set oNurbsCurveList = oLeng.ActivePrimitive.Geometry
LogMessage oNurbsCurveList.length
CGTalk Moderation
11-07-2006, 09:02 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.