Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • VTK VTK
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 831
    • Issues 831
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 233
    • Merge requests 233
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • VTKVTK
  • VTKVTK
  • Issues
  • #18042
Closed
Open
Issue created Nov 02, 2020 by bistek@bistek

set/get FieldData with numpy_interface.dataset_adapter

Hello, I am doing experiments, trying to set and get FieldData on e.g. a PolyData, UnstructuredGrid, etc., with numpy_interface.dataset_adapter. I am particularity interested in string FieldData, used to store various attributed of a vtk object, but also in numeric arrays.

However if I try to use the same syntax as for Points, I always get errors.

import vtk
from vtk.numpy_interface import dataset_adapter as dsa
import numpy as np

my_polydata = vtk.vtkPolyData()
# add some points and cells to my_polydata here..

my_polydata_dsa = dsa.WrapDataObject(my_polydata)

# set string example
my_polydata_dsa.FieldData["key_1"] = "string_1"

>>> TypeError: 'DataSetAttributes' object does not support item assignment

# numeric example
my_polydata_dsa.FieldData["key_2"] = [1.0, 2.0, 3.0]

>>> TypeError: 'DataSetAttributes' object does not support item assignment

# get examples (do not work due to previous errors)
print(my_polydata_dsa.FieldData["key_1"])
print(my_polydata_dsa.FieldData["key_2"])

I also tried with .FieldData.keys(), .FieldData.values(), .FieldData.append(), but I cannot understand the right syntax.

Thanks very much!

Assignee
Assign to
Time tracking