# Explicitly set transform matrix values in Python

**URL:** https://discourse.paraview.org/t/explicitly-set-transform-matrix-values-in-python/13737
**Category:** Development
**Tags:** python
**Created:** [January 18, 2024, 7:34pm UTC](https://discourse.paraview.org/t/explicitly-set-transform-matrix-values-in-python/13737 "2024-01-18T19:34:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jgrime](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jgrime](https://discourse.paraview.org/u/jgrime)
#### Post date: [January 18, 2024, 7:34pm UTC](https://discourse.paraview.org/t/explicitly-set-transform-matrix-values-in-python/13737/1 "2024-01-18T19:34:56Z")

</div>

What I’d like to do is fairly simple: explicitly set the elements of the 4x4 matrix that is somehow lurking in the Transform class.

The following code lets me do this (hat tip to [Reshma](https://discourse.paraview.org/t/custom-transformation-matrix-in-paraview/2906), whose post I found while searching):

```auto
from paraview.simple import *
from paraview import servermanager
t = servermanager.CreateProxy("transforms", "Transform")
tp = servermanager._getPyProxy(t)
tp.Matrix=[1,0,0, 10,0,1,0,10, 0, 0, 1, 10, 0 ,0, 0, 1]
a = Transform()
a.Transform = tp

```

However, attempting to set the “Matrix” property without first recovering some sort of proxy object from the `servermanager` fails, as in the following:

```auto
from paraview.simple import *
from paraview import servermanager

# Assign transform matrix to specified input source.
target = FindSource('model.stl')

# Print type of Transform instance, and whatever the assigned "Matrix" data may be
a = Transform(registrationName='test', Input=target)
print('Type of a is', type(a))
print('a "Matrix" property is', a.GetProperty('Matrix'))

# Attempt to set Matrix property
a.Matrix = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]

```

Which produces the following:

```auto
Type of a is <class 'paraview.servermanager.Transform'>
a "Matrix" property is None
Traceback (most recent call last):
  File "C:\Program Files\ParaView 5.11.1\bin\Lib\site-packages\paraview\servermanager.py", line 476, in __setattr__
    setter = getattr(self. __class__ , name)
AttributeError: type object 'Transform' has no attribute 'Matrix'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\ParaView 5.11.1\bin\Lib\site-packages\paraview\servermanager.py", line 482, in __setattr__
    _bc.setattr(self, name, value)
  File "C:\Program Files\ParaView 5.11.1\bin\Lib\site-packages\paraview\_backwardscompatibilityhelper.py", line 411, in setattr
    raise AttributeError()
AttributeError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 10, in <module>
  File "C:\Program Files\ParaView 5.11.1\bin\Lib\site-packages\paraview\servermanager.py", line 489, in __setattr__
    raise AttributeError("Attribute %s does not exist. " % name +
AttributeError: Attribute Matrix does not exist. This class does not allow addition of new attributes to avoid mistakes due to typos. Use add_attribute() if you really want to add this attribute.

```

This seemed strange to me, so I tried the following to double check the “transform” object returned by the `servermanager.CreateProxy() / _getPyProxy()` combination was the same as that returned by creating a new `Transform`. I also try using a newly created `Transform` with `_getPyProxy()` to see if that helps:

```auto
from paraview.simple import *

t = servermanager.CreateProxy("transforms", "Transform")
tp = servermanager._getPyProxy(t)
print('Type of t is', type(t))
print('Type of tp is', type(tp))
print('tp "Matrix" property is', tp.GetProperty('Matrix'))

target = FindSource('model.stl')
a = Transform(registrationName='test', Input=target)
print('Type of a is', type(a))
print('a "Matrix" property is', a.GetProperty('Matrix'))

b = servermanager._getPyProxy(a)
print('Type of b is', type(b))
print('b "Matrix" property is', b.GetProperty('Matrix'))

```

Which produces the following output:

```auto
Type of t is <class 'paraview.modules.vtkRemotingServerManager.vtkSMProxy'>
Type of tp is <class 'paraview.servermanager.Transform'>
tp "Matrix" property is [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Type of a is <class 'paraview.servermanager.Transform'>
a "Matrix" property is None
Type of b is <class 'paraview.servermanager.Transform'>
b "Matrix" property is None

```

So in all cases, the transform object seems to be of type `paraview.servermanager.Transform` - but only when retrieved via `servermanager.CreateProxy() / _getPyProxy()` does it contain the `Matrix` property.

The `servermanager._getPyProxy()` call seems as if it may be deprecated, or at least it’s not easy to find any information about it anywhere.

**Therefore: what’s the correct way to set the elements of a 4x4 transform in ParaView for assignment to an object?**

---

<div class="post-metadata">

### Author: ![jgrime](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jgrime](https://discourse.paraview.org/u/jgrime)
#### Post date: [January 18, 2024, 8:33pm UTC](https://discourse.paraview.org/t/explicitly-set-transform-matrix-values-in-python/13737/2 "2024-01-18T20:33:27Z")

</div>

There are kinda-related issues such as the post from Reshma (Nov. '19) linked previously, and another approach via [Yuxiang Wang](https://discourse.paraview.org/t/animation-of-a-series-of-4x4-matrix-transformations-using-programmable-filters/4350) (May '20), but neither of these requests for help were actually answered as far as I can see.

Do the Kitware devs read these forums? Is there a better way for us to ask technical questions?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 19, 2024, 8:08am UTC](https://discourse.paraview.org/t/explicitly-set-transform-matrix-values-in-python/13737/3 "2024-01-19T08:08:02Z")

</div>

Hi @jgrime

Your post requires some reading, which is maybe why it was not answered in the **one** hour between your first and second post 🙂 .

> Do the Kitware devs read these forums?

On your other questions, it was mostly Kitware engineers answering your questions, so I think you already know the answer to this question 🙂

> Is there a better way for us to ask technical questions?

Of course! If you are looking for professional support, you may want to reach out to Kitware directly:  
[https://www.kitware.com/industry/support/](https://www.kitware.com/industry/support/)
