|
[Sponsors] |
[DesignModeler] DM's JScript: FPoint()'s GetPoint(i) function picks points backwards? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 22, 2012, 21:52 |
DM's JScript: FPoint()'s GetPoint(i) function picks points backwards?
|
#1 |
New Member
Join Date: Jun 2012
Posts: 17
Rep Power: 14 |
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 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(); 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(); } 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? |
|
July 23, 2012, 04:58 |
|
#2 |
New Member
Join Date: Jun 2012
Posts: 17
Rep Power: 14 |
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. 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) Code:
Line1.GetEdge(4) Code:
AddSegment(Point1, Point2, ID#) 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... |
|
July 23, 2012, 16:25 |
|
#3 |
New Member
Join Date: Jun 2012
Posts: 17
Rep Power: 14 |
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(); lines[i].addSegment(fp1.GetPoint(i, 1), fp1.GetPoint(i, 2)); 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(); ag.b.AddSelectEdgeID(i); 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(); ag.b.AddSelectEdgeID(i); NS_Lines[i] = ag.gui.CreateSelectionSet(); NS_Lines[i].Name = "Kangaroo" + i; //<----- This line gives the Named Selection a name. i++; } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] mesh airfoil NACA0012 | anand_30 | OpenFOAM Meshing & Mesh Conversion | 13 | March 7, 2022 18:22 |
channelFoam for a 3D pipe | AlmostSurelyRob | OpenFOAM | 3 | June 24, 2011 14:06 |
Passing Values in Multiple points by 1 CEL Function | Araz | CFX | 0 | May 5, 2011 17:06 |
[blockMesh] BlockMesh FOAM warning | gaottino | OpenFOAM Meshing & Mesh Conversion | 7 | July 19, 2010 15:11 |
[blockMesh] BlockMeshmergePatchPairs | hjasak | OpenFOAM Meshing & Mesh Conversion | 11 | August 15, 2008 08:36 |