General Category > ASL Scripts

GetNumEdges() function gone wrong?

(1/2) > >>

Kubajzz:
Try out this simple script:

--- Code: ---#command("object");

file $file;
string $output;
shape $shape[0];

project.curObject.GetShapes($shape);

$output = PrintToString("edges: %d", $shape[0].GetNumEdges());
$file.open("$console", "w");
$file.print("-------\n\n"+$output+"\n\n-------\n");
$file.close;
--- End code ---

You must have only one mesh in your object...
Run the script and you will get a console output which should contain the number of edges in that mesh... but the number in the console will allways be (number of edges + 1)!

Why does this happen? Is it a bug?

I found this problem accidentally and it scared me pretty much, because I've been using the GetNumEdges function without any problems until now...

NickE:
I ran into this issue a while back. 

I added a little to your code to try to flesh out the problem:

--- Code: ---#command("object");

file $file;
string $output;
shape $shape[0];

int $i;

project.curObject.GetShapes($shape);

$output = PrintToString("edges: %d", $shape[0].GetNumEdges());


$file.open("$console", "w");
$file.print("-------\n\n"+$output+"\n\n-------\n");

for $i=1 to $shape[0].GetNumEdges() do
{
  $file.print("Edge: %d Point1: %d Point2: %d\n",$i,$shape[0].GetEdgeIndex0($i),$shape[0].GetEdgeIndex1($i));


$file.close;

--- End code ---

I just drew a cube and converted to mesh for a test shape.  The output:

--- Code: ---begin script "F:\anim8or_v097b_preview\scripts\edgecounttest.txt
-------

edges: 13

-------
Edge: 1 Point1: 0 Point2: 4
Edge: 2 Point1: 4 Point2: 6
Edge: 3 Point1: 2 Point2: 6
Edge: 4 Point1: 0 Point2: 2
Edge: 5 Point1: 1 Point2: 3
Edge: 6 Point1: 3 Point2: 7
Edge: 7 Point1: 5 Point2: 7
Edge: 8 Point1: 1 Point2: 5
Edge: 9 Point1: 2 Point2: 3
Edge: 10 Point1: 0 Point2: 1
Edge: 11 Point1: 4 Point2: 5
Edge: 12 Point1: 6 Point2: 7
Edge: 13 Point1: 0 Point2: 0
exit script "F:\anim8or_v097b_preview\scripts\edgecounttest.txt"
--- End code ---

It appears that the last edge is from point 0 to point 0.  You can probably work around this by just using GetNumEdges()-1.  That is what I have done.

Kubajzz:
I did exactly the same when I was trying to find out why my script doesn't work... And I found the same thing:

--- Quote from: NickE ---It appears that the last edge is from point 0 to point 0.
--- End quote ---
I think the point numbers "0, 0" don't mean the starting and ending point in this case, it just means that edge #13 does not not exist (and has no point data...); you will get the same output if you try to get the data for edge number 0, which also doesn't exist... Also if you try to click Options>Info, you'll see that your mesh really has only 12 edges, there cannot be edge number 13...

I know there's an easy way to go around (using "GetNumEdges()-1" instead of "GetNumEdges()") but what if this is really a bug and it will be fixed in the next version? The scripts wouldn't work then... That's why I wanted to ask about it...

Steve:
I will fix GetNumEdges().  It should return 12 for a cube.

Kubajzz:
Thanks Steve!

I found an easy way how to write a script that would work in the current version of Anim8or and it would still work correctly in the next versions. Something from the ASL specification:


--- Quote from: ASL specification ---Predefined Variables

string version;
  The version of Anim8or is available in version.

--- End quote ---

I always thought "version" variable is one of the most useless features... But it's going to be extremely useful here :)

Navigation

[0] Message Index

[#] Next page

Go to full version