Hello all,
I am very new to Paraview and am trying to export a mesh created with openfoam as a Nastran file to be used in ICEM CFD for a project at school. After some searching I found a post that had a python script written that could be used in the Programmable filter section. This is the infomraiton of the mesh I am trying to export:
It looked like the person was trying to do exactly what I am but I did not get it to work. When I tried running the script I got an error.

This the code I tried running:
output_file = ‘H:\ME5143 CFD\Final_proj/output.nas’
input = self.GetInput()
f = open(output_file, ‘w’)
f.write(‘{:80}\n’.format(‘ Generated by ToNastran program'))
f.write('{:80}\n'.format(' Nastran input deck’))
f.write(‘{:80}\n’.format(‘SOL 103’))
f.write(‘{:80}\n’.format(‘CEND’))
f.write(‘{:80}\n’.format(‘'))
f.write('{:80}\n'.format('BEGIN BULK'))
f.write('{:80}\n'.format('’))
f.write(‘{:80}\n’.format(‘$ grid data 0’))
print(‘number of points in input is ’ + str(input.GetNumberOfPoints()))
for i in range(input.GetNumberOfPoints()):
point = input.GetPoint(i)
id = i + 1
f.write(‘GRID*{:>19}{:>16} {:<15f}{:<16f}{:>7}\n’.format(id,0,point[0],point[1],id))
f.write('{:>7}{:>12f}{:>20}{:>32}{:8}\n’.format(id,point[2],0,0,’'))
materialName = ‘BlockIdScalars’
materialArray = input.GetCellData().GetArray(materialName)
print(materialArray)
mats = {}
for i in range(input.GetNumberOfCells()):
material = int(materialArray.GetTuple1(i))
mats.setdefault(material, []).append(i)
id = 0
for mat in mats:
f.write(‘{:80}\n’.format(‘$ Volume element data for family’))
f.write(‘{:6}{:10}{:64}\n’.format(‘PSOLID’,mat,’ 0 0 0’))
for i in mats[mat]:
id += 1
cell = input.GetCell(i)
cellType = cell.GetCellType()
pntIds = cell.GetPointIds()
if cellType == vtk.VTK_TETRA:
f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:24}\n'.format('CTETRA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,''))
elif cellType == vtk.VTK_HEXAHEDRON:
f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CHEXA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(5)+1,''))
f.write('{:6}{:>10}{:>8}{:56}\n'.format('',pntIds.GetId(6)+1,pntIds.GetId(7)+1,''))
elif cellType == vtk.VTK_WEDGE:
f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CPENTA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(5)+1,''))
elif cellType == vtk.VTK_PYRAMID:
f.write(‘{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8 {:8}\n’.format(‘CHEXA’,id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(4)+1,‘’))
f.write(‘{:6}{:>10}{:>8}{:56}\n’.format(‘’,pntIds.GetId(4)+1,pntIds.GetId(4)+1,‘’))
f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CPENTA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(4)+1,''))
f.write(‘{:80}\n’.format(‘ Geometry defaults data'))
f.write('{:80}\n'.format(' Material Properties’))
f.write(‘{:80}\n’.format(‘ Analysis type data'))
f.write('{:80}\n'.format(' Load defaults data’))
f.write(‘{:80}\n’.format(‘$ Coordinate systems’))
f.write(‘{:80}\n’.format(‘ENDDATA’))
f.close()
Can anyone tell me what needs to be changed to get this to work?