How to set VTK result display Mode by python code?

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
johnwang
Posts: 584
Joined: Sun Jan 27, 2019 12:41 am

How to set VTK result display Mode by python code?

Postby johnwang » Thu Jun 04, 2020 2:05 am

Hi,

I am trying to set the Mode and Filed of display options by program when import the VTK result file.

I want to set Mode = 'Surface'. But it doesn't work. Also tried Mode=1.

And there is no property called Field.

Need run update()? Or this function is not exposed to python?

Regards,

John
dis.jpg
dis.jpg (21.34 KiB) Viewed 279 times

Code: Select all

import FreeCAD,FreeCADGui
import Fem
import os, os.path

import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *

inipath=FreeCAD.getHomePath()

try:
	path = QFileDialog.getExistingDirectory(None,QString.fromLocal8Bit("Select Directory"),inipath) # PyQt4
except Exception:
	path =  str(PySide.QtGui.QFileDialog.getExistingDirectory(None,str("Select Directory"),inipath)) #PySide

print (path)

grpVTK =FreeCAD.ActiveDocument.getObject('vtkResults')
if grpVTK==None:
	grpVTK = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup",'vtkResults')
	
	for name in os.listdir(path): 

		if name[len(name)-4:len(name)]=='.vtu' or name[:len(name)]=='.vtk':
			#print (name)
			ivtk_result_obj = FreeCAD.ActiveDocument.addObject("Fem::FemPostPipeline",name)
			ivtk_result_obj.read( path+"/"+name)
			ivtk_result_obj.touch()
			ivtk_result_obj.Mode=1
			#ivtk_result_obj.field=1
			
			grpVTK.addObject(ivtk_result_obj)

			FreeCAD.ActiveDocument.recompute()
			FreeCADGui.SendMsgToActiveView("ViewFit")

print ('Import results done.')
Last edited by johnwang on Thu Jun 04, 2020 11:53 am, edited 2 times in total.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
bernd
Posts: 11096
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: How to set VTK result display Mode by python code?

Postby bernd » Thu Jun 04, 2020 5:48 am

create a vtk pipeline and set modes:

Code: Select all

app_home = FreeCAD.ConfigGet("AppHomePath")
doc = FreeCAD.open(app_home + "data/examples/FemCalculixCantilever3D.FCStd")
doc.WarpVector.ViewObject.hide()
import ObjectsFem
vtkres = ObjectsFem.makePostVtkResult(doc, doc.CCX_Results)
doc.recompute()
vtkres.ViewObject.DisplayMode = 'Surface' 
vtkres.ViewObject.Field = 'Displacement'

get object properties:

Code: Select all

vtkres.PropertiesList
vtkres.ViewObject.PropertiesList
output:

Code: Select all

>>> 
>>> vtkres.PropertiesList
['Data', 'ExpressionEngine', 'Filter', 'Functions', 'Label', 'Label2', 'Mode', 'Placement', 'Visibility']
>>> vtkres.ViewObject.PropertiesList
['DisplayMode', 'Field', 'OnTopWhenSelected', 'SelectionStyle', 'ShowInTree', 'Transparency', 'VectorMode', 'Visibility']
>>> 
>>> 
User avatar
johnwang
Posts: 584
Joined: Sun Jan 27, 2019 12:41 am

Re: How to set VTK result display Mode by python code?

Postby johnwang » Fri Jun 05, 2020 4:07 am

bernd wrote:
Thu Jun 04, 2020 5:48 am

Code: Select all

vtkres.ViewObject.DisplayMode = 'Surface' 
vtkres.ViewObject.Field = 'Displacement'
Thanks. All good now.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)