output picture from saved results using saveSnapshot

Asked by gaoxuesong

I have saved a list of results by using O.save during the calculation. Now i want to load each result and output a picture. The function i use is saveSnapshot(). The following codes work,

  O.load(file)
  qtr = qt.Renderer()
  qtr.bgColor = [1,1,1]
  v = qt.View()
  outpath = path+'/plot/'
  v.saveSnapshot(str(O.time)[:4]+'.jpg')

But when i put these codes into a for loop, it fails with 'not support a secondary view'. Then i put a v.close() at the end of each loop, but it does not work. The following is my whole codes,

import os
from yade import qt

path = os.getcwd()
os.mkdir(path+'/plot')

for file in os.listdir(path):
    if os.path.isdir(file):
        continue
    O.load(file)
    qtr = qt.Renderer()
    qtr.bgColor = [1,1,1]
    v = qt.View()
    outpath = path+'/plot/'
    v.saveSnapshot(str(O.time)[:4]+'.jpg')
    v.close()

I open a terminal in the directory consisting of the saved results and copy my codes into it and hit Enter.

Question information

Language:
English Edit question
Status:
Expired
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Robert Caulk (rcaulk) said :
#1

Hello,

Consider copying and pasting the error here.

Cheers,

Robert

Revision history for this message
gaoxuesong (260582472-9) said :
#2

Yes. The errors are,
    "Secondary views not supported. "

This is the screenshot,
https://drive.google.com/file/d/1O4bQeGykuW9xMnZiEX_0RG-XyqcfHGZP/view?usp=sharing

Revision history for this message
gaoxuesong (260582472-9) said :
#3

I find that there is a delay for the window to render the image. So maybe the codes are not executed by the original order. The codes to snapshot the window may be executed before the window renders the image.
I find the debug sentence can be used to make them synchronization. The modified codes is as followings,

import os
from yade import qt
import pdb

path = os.getcwd()
os.mkdir(path+'/plot')
qtr = qt.Renderer()
qtr.bgColor = [1,1,1]
v = qt.View()
outpath = path+'/plot/'

for file in os.listdir(path):
    if os.path.isdir(file):
        continue
    O.load(file)
    pdb.set_trace()
    v.saveSnapshot(str(O.time)[:4]+'.jpg')

When it pauses at the break point, just enter 'c' to make it continue.

Revision history for this message
Launchpad Janitor (janitor) said :
#4

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Jérôme Duriez (jduriez) said :
#5

Hi,

Calling several times
qt.View()
(without closing the qt window inbetween calls) is not supported/expected by YADE.

You may just remove this line from the for loop