-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield_outputs.py
46 lines (39 loc) · 1.13 KB
/
field_outputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python2
# -*- coding: iso-8859-1 -*-
import csv
import io
import odbAccess
ODB_PATH = "Z:\\database.odb"
ODB_STEP = "Step-1"
ODB_FRAME = -1
ODB_INSTANCE = "CONCRETE-1"
CSV_PATH = "Z:\\enriched.csv"
odb = odbAccess.openOdb(ODB_PATH)
frame = odb.steps[ODB_STEP].frames[ODB_FRAME]
instance = odb.rootAssembly.instances[ODB_INSTANCE]
# Read the enriched CSV.
csvfile = open(CSV_PATH)
reader = csv.reader(csvfile)
names = next(reader)
csv_data = [[] for _ in names]
for row in reader:
for i in range(len(row)):
if i == 0:
csv_data[i].append(int(row[i]))
else:
csv_data[i].append((float(row[i]),))
csvfile.close()
# For each new list of numbers, add a new field output.
for i, name in enumerate(names):
if i == 0: continue
if name in frame.fieldOutputs.keys(): continue
new_field_output = frame.FieldOutput(name=name,
description=name,
type=odbAccess.SCALAR)
new_field_output.addData(
position = odbAccess.NODAL,
instance = instance,
labels = csv_data[0],
data = csv_data[i])
odb.save()
odb.close()