CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (https://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [DesignModeler] DM's JScript: FPoint()'s GetPoint(i) function picks points backwards? (https://www.cfd-online.com/Forums/ansys-meshing/105086-dms-jscript-fpoint-s-getpoint-i-function-picks-points-backwards.html)

 ANT July 22, 2012 20:52

DM's JScript: FPoint()'s GetPoint(i) function picks points backwards?

Hey everyone,

There is not much documentation in the DesignModeler manual when it comes to scripting besides simple, one-line explanations and contrived examples here and there.

After successfully generating an FPoint() object containing pairs of points from a coordinate file and then creating a LinePt() object that contains edges between these pairs, I am trying to script the creation of a series of planes that are each centered at the start vertex of one of the lines (point #1 of the 2 used per group for the FPoint's coordinate file), and normal to the edge that connects the two points.

The planes are generated without issues, but have an incredibly strange bug... I noticed first that the planes were generated in the right order and normal to the desired line edge, but they are being generated at the wrong points.

The oddness arises when I took a look at exactly which points are being used by the buggy script. When using a coordinate file with 5 points (for simplicity), the first plane uses the edge between the first pair of points, and uses the point at the start of this first line (which is correct). However:
• The second plane uses the edge between the second set of points, but the start point of the fifth line.
• The third plane uses the edge between the third set of points, but the start point of the fourth line.
• The fourth line uses the edge between the fourth set of points, but the start point of the third line.
• Lastly, the fifth line uses the edge between the fifth set of points, but the start point of the second line.

The pairing basically goes (1, 1), (2, 5), (3, 4), (4, 3), (5, 2). The same pattern occurs when larger number of points are used; if I use 10 coordinate pairs, for example, it goes: (1, 1), (2, 10), (3, 9), (4, 8), (5, 7), (6, 6), (7, 5), (8, 4), (9, 3), (10, 2).

Basically, the first point is generated properly, and then the rest of the planes follow the pattern shown above (second plane uses point from last line, third plane uses point from second-last line, fourth plane uses point from third-last line, etc.)

The important parts of my script are below:

Code:

```//Import the points var fp1 = agb.FPoint(agc.FPointConstruction, agc.FPointCoordinateFile); fp1.Name = "coordinatePoints"; fp1.CoordinateFile = "C:\\Users\\Giraffe\\Coordinates.txt"; agb.Regen(); //Generate line bodies according to the sets of points from fp1 above LP1 = agb.LinePt(); LP1.Name = "FiberLines"; var i = 1; while (fp1.GetPoint(i, 1)) {                LP1.AddSegment(fp1.GetPoint(i, 1), fp1.GetPoint(i, 2), i);         i = i + 1; } agb.Regen();```
Up to here, everything is good; points are all generated and the segments between the points are all generated in the correct order/orientation and between the correct points. Now, I go on to generate the points:

Code:

```for (var j = 1; j < i; j++) {                 agb.ClearSelections();         //Generate plane         var fplane = agb.PlaneFromPointNormal(fp1.GetPoint(j, 1), LP1.GetEdge(j));         if (j < 10) {                 fplane.Name = planeName + "_0" + j;         }         else {                 fplane.Name = planeName + "_" + j;         }         agb.Regen(); }```
And I get planes that are generated using the incorrect Point assignment, although the Normal parameter is assigned to the correct edge. What am I doing wrong here? Anyone know why the points, after the first one, are being picked in exactly the opposite order?

I could fix the script by simply making GetEdge start at the last edge (after the first plane is generated) and have everything line up properly, but then I don't really learn anything and don't understand what is causing the bug.

Can anyone help?

 ANT July 23, 2012 03:58

I read over my first post and realized some clarification of my question was in order.

Basically, after creating an FPoint() object from a coordinate .txt file that is structured as follows:

Code:

``` 1  1  X1  Y1  Z1 1  2  X2  Y2  Z2 2  1  X1  Y1  Z1 2  2  X2  Y2  Z2 3  1  X1  Y1  Z1 3  2  X2  Y2  Z2 4  1  X1  Y1  Z1 4  2  X2  Y2  Z2 5  1  X1  Y1  Z1 5  2  X2  Y2  Z2 ... etc.```
And then creating a LinePt() object in which segments are added between the two points in each group (e.g. AddSegment(<FPointObjectName>.GetPoint(i, 1), <FPointObjectName>.GetPoint(i, 2)), the segments are generated between the correct points, but the GetEdge() call returns the segments in the wrong order.

So, if FP1 is the name of my FPoint object that is based on the coordinate file above and Line1 is the name of my LinePt() object (with segments added), the call

Code:

``` FP1.GetPoint(4, 1) ```
will correctly return the first point of the fourth group, but

Code:

``` Line1.GetEdge(4) ```
will *not* return the edge between the points in the fourth group, despite this being the fourth edge that has been created. Calling AddSegment with an identifier at the end as follows does not help at all either, or change the results at all:

Code:

``` AddSegment(Point1, Point2, ID#) ```
The peculiarity is that GetEdge(1) returns the edge between the points in the first group, but from GetEdge(2) onwards, the order of the edges returned is the *reversed* sequence; GetEdge(2) returns the last line in the sequence, GetEdge(3) returns the second-last line, and so on until GetEdge(<last point group>) will return the edge between the points in the second group.

Does anyone know why this is happening, and how to prevent it?

I'm thinking I may just create individual LinePt() objects for each line and store them in an array, so that way I can call GetEdge(1) for each object and know I'm getting the right edge, but this means for 100+ point-pair files, I'll have 100+ Line concepts sitting around (which I will also have to individually name, otherwise I'd have to click through 100 "Same Name Exists, adding number on end" popups in DesignModeler), but this is a backup plan...

 ANT July 23, 2012 15:25

Never mind; issue wasn't the GetPoint, it was an issue with getEdge() from the LinePt() object.

I simply did what I said I'd do in my backup plan, and everything came out working just fine:

var lines = new Array();
for (var i = 1; i < numPoints; i++) {
lines[i] = LinePt();
agb.Regen();
}

Then, I can also add the following loop to create an array with each element pointing at a new Named Selection for each LinePt() object I defined above. This is important if you want to use the LinePt() for something that requires a named selection to be chosen (such as the Sweep, Skin, Revolve functions listed in DesignModeler's Scripting API):

var NS_Lines = new Array();
var i = 1;
while(lines[i]) {
ag.gui.ClearSelect();
NS_Lines[i] = ag.gui.CreateSelectionSet();
i++;
}

Edit: It is also possible to name the Named Selections in this loop by simply adding the following bolded line:

var NS_Lines = new Array();
var i = 1;
while(lines[i]) {
ag.gui.ClearSelect();