Python Forum

Full Version: Unable to create vtu file from python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


Dear python users,

I need to create vtu file from python so I can use paraview on it.I am using python version 3.6 but I have tried and ended up with the same error with python-2.7 -"No module named 'vtk'". This is the code I found on internet and that I am currently using (btw I installed vtk 7.1.1 and I am using windows 7):

###############
import pygmsh
import numpy as np
import meshio


geom = pygmsh.built_in.Geometry()

# Draw a cross.
poly = geom.add_polygon([
[0.0, 0.5, 0.0],
[-0.1, 0.1, 0.0],
[-0.5, 0.0, 0.0],
[-0.1, -0.1, 0.0],
[0.0, -0.5, 0.0],
[0.1, -0.1, 0.0],
[0.5, 0.0, 0.0],
[0.1, 0.1, 0.0]
],
lcar=0.05
)

axis = [0, 0, 1]

geom.extrude(
poly,
translation_axis=axis,
rotation_axis=axis,
point_on_axis=[0, 0, 0],
angle=2.0 / 6.0 * np.pi
)

points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)

meshio.write('test.vtu', points, cells, cell_data=cell_data)
##################


Can anyone help me? It seems to be very hard but I believe in python forum programmers Smile
re-posting the code:

import pygmsh
import numpy as np
import meshio


geom = pygmsh.built_in.Geometry()

# Draw a cross.
poly = geom.add_polygon([
[0.0, 0.5, 0.0],
[-0.1, 0.1, 0.0],
[-0.5, 0.0, 0.0],
[-0.1, -0.1, 0.0],
[0.0, -0.5, 0.0],
[0.1, -0.1, 0.0],
[0.5, 0.0, 0.0],
[0.1, 0.1, 0.0]
],
lcar=0.05
)

axis = [0, 0, 1]

geom.extrude(
poly,
translation_axis=axis,
rotation_axis=axis,
point_on_axis=[0, 0, 0],
angle=2.0 / 6.0 * np.pi
)

points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)

meshio.write('test.vtu', points, cells, cell_data=cell_data)
This is a stab in the dark, but perhaps there's something of use here: https://pypi.python.org/pypi?%3Aaction=s...mit=search
referenced by: http://www.elmerfem.org/blog/uncategoriz...alization/