View Full Version : looking for JScript for computing distance
gibby
04-21-2008, 05:30 PM
Hello,
I'm looking for a JScript that computes the distance between two points selected with the point select tool, preferably something that breaks it down into x, y, and z components. I could even write my own if someone could tell me how to refer to the two points in JScript and how to get at their x, y, and z coordinates.
Please and thanks.
scaron
04-21-2008, 07:13 PM
i would get the two point indices then use
x3dobject.activeprimitive.geometry.points(index).p osition
which is a vector type with x y and z properties
then use the subtract method of a vector to get the distance between this two indices...
http://softimage.wiki.avid.com/sdkdocs/Point.htm#Point
kim aldis
04-22-2008, 03:13 AM
try this (assumes you have a selection):
if ( selection(0).type != "pntSubComponent" ) {
logmessage( "Must select points" );
} else {
var oSel = selection(0).SubComponent.ComponentCollection;
if ( oSel.count != 2 ) {
logmessage( "Must select 2 points" );
} else {
var l = CalculateDistance( oSel );
logmessage( "Distance = " + l );
}
}
function CalculateDistance( oComponentCollection ) {
var oP1 = oComponentCollection (0).position;
var oP2 = oComponentCollection (1).position;
oP1.SubInPlace( oP2 );
//dx = oP1.x;
//dy = oP1.y;
//dz = oP1.z;
return oP1.length();
}
scaron
04-22-2008, 03:16 AM
use kim's way... that skips the point indice query and goes straight to what you need using the component collection.
i also left out the length method of a vector. subtracting alone wouldn't give you a scalar value you need.
s
gibby
04-22-2008, 11:57 AM
That's exactly what I need. Thanks, both of you.
I do have a follow up question though.
In testing this script, at first I tried selecting two points on two seperate objects (two cubes) but it seems that I can only select points on one object. If I select a point on the first cube and then another point on the next cube, it tells me "Must select 2 points". Anybody know why this would be?
Sorry if this seem obvious, but I'm new.
kim aldis
04-22-2008, 12:55 PM
XSI treats objects as separate selections, subelements on the same object are treated as single selections. You'll need to add a check for more than one object selected in the selection object (selection.count) and take appropriate action. Probably most of your code will end up being selection checking.
gibby
04-23-2008, 11:00 AM
OK, so I take it that my work will be mainly in the section
if ( selection(0).type != "pntSubComponent" ) {
logmessage( "Must select points" );
and instead of printing out an error message, I have to check for other objects, correct?
scaron
06-12-2008, 06:25 PM
is there an echo in here?
patrick.n
06-12-2008, 06:27 PM
There's an echo in a few threads now.
Bad Clint999! Stop it!
GeneCrucean
06-12-2008, 06:59 PM
I think that user is a spam (http://www.spam.com)bot.
This post... http://community.softimage.com/showthread.php?p=6180#post6180 is also a direct copy of an earlier one.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.