Python Forum
Unable to create vtu file from python
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to create vtu file from python
#1


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
Reply
#2
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)
Reply
#3
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/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a Table to a PNG file amanajosh 0 1,091 Aug-11-2022, 02:54 AM
Last Post: amanajosh
  Fatal Python error: initfsencoding: unable to load the file system codec gauravbhardwajee 12 28,187 Apr-30-2020, 07:45 PM
Last Post: barrpath

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020