Contrib:Dbpatankar/HT1
How to extract a value from a table using python
Say you performed some calculation with your model and extracted your results in a table using POST_RELEVE_T. Lets say that table is named TBL.
This table is table of coordinate points and displacement values at nodes.
The table is something like :
NOEUD | X | Y | Z | DX | DY | DZ |
---|---|---|---|---|---|---|
N64 | 1.19966E+00 | -1.15865E-05 | -1.63838E-03 | 1.81394E-03 | -2.07795E-03 | 1.04842E-02 |
N113 | 1.49962E+00 | -1.11233E-05 | -2.36240E-03 | 2.05956E-03 | -3.07869E-03 | 1.53553E-02 |
N159 | 9.11231E-23 | 1.27977E-22 | -1.81301E-23 | 0.00000E+00 | 0.00000E+00 | 0.00000E+00 |
N270 | 2.69957E+00 | -1.25319E-05 | -5.68127E-03 | 2.48677E-03 | -7.80872E-03 | 3.84270E-02 |
N346 | 1.79960E+00 | -1.15171E-05 | -3.14862E-03 | 2.24653E-03 | -4.18034E-03 | 2.07363E-02 |
N372 | 2.09958E+00 | -1.14958E-05 | -3.97566E-03 | 2.37691E-03 | -5.36016E-03 | 2.64737E-02 |
N425 | 8.99711E-01 | -1.07778E-05 | -1.00118E-03 | 1.51058E-03 | -1.22664E-03 | 6.28355E-03 |
N461 | 2.99957E+00 | -1.31310E-05 | -6.54018E-03 | 2.50928E-03 | -9.04506E-03 | 4.44634E-02 |
N500 | 2.39957E+00 | -1.20486E-05 | -4.82397E-03 | 2.44765E-03 | -6.57507E-03 | 3.24065E-02 |
N770 | 5.99787E-01 | -1.29910E-05 | -4.84976E-04 | 1.07209E-03 | -5.34566E-04 | 2.96552E-03 |
N851 | 2.99877E-01 | -1.43431E-05 | -1.34048E-04 | 6.04560E-04 | -7.56027E-05 | 7.79659E-04 |
Task : To extract DZ value at node N425.
1. Create a table using POST_RELEVE_T having required values(as shown above). Say that table is TBL.
TBL = POST_RELEVE_T(Blah Blah Blah....);
2. Now extract this table into a variable say VAR, by
VAR = TBL.EXTR_TABLE();
3. This variable VAR will have many attributes, 'values' attribute is the one which is of our interest for this case.
VAR.values() is actually a python dictionary. For the above table, VAR.values() will look like :
VAR.values() = {'NOEUD': ['N64 ', 'N113 ....],'X':[1.19......],'Y':[........],'Z':[.........],'DX':[........],'DY'[........],'DZ':[.........]}
Now I will call 'NOEUD', 'X', 'Y', 'Z', 'DX', 'DY', 'DZ' as properties of the table.
4. Now if I want to access DZ component of node N425 then,
(VAR.values().['DZ'])[6]; This will give me value 6.28355E-03, which is what I want.
5. So now I can assign any variable name to it :
myvar = (VAR.values().['property'])[index]; will do the necessary trick.
6. Now one can use for loop in python and assign every single DZ value to different variables(if one wishes so).