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, whose post I found while searching):
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:
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:
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:
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:
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?