WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   screenshots using a loop (https://forum.worldviz.com/showthread.php?t=2254)

krimble 09-09-2009 03:45 AM

screenshots using a loop
 
Hi all,

can somebody help me? I have troubles with my program.
I'm busy writing a small script which is basically a loop where an object rotates in after the rotation it has to make a screenshot of it and store it on the disk with the objects name and rotation degree.

The loop works perfectly it prints out what it has to save on the disk but it doesn't save (well it saves only the last screenshot).

Do I have to approach this differently?

Thanks for your help!

Code:

import viz

viz.go()

viz.clearcolor(.4,.4,.4)

view = viz.get(viz.MAIN_VIEWPOINT)
view.translate(12.416062355041504, 4.3263897895812988, 0)
view.rotate(-90,0,0)

s = viz.add(r"scissors.wrl")
co = viz.add(r"canopener.ive")
c1 = viz.add(r"cubes_01.wrl")
c2 = viz.add(r"cubes_02.wrl")
c3 = viz.add(r"cubes_03.wrl")

objects = [s,co,c1,c2,c3]
objectStrings = ["scissors","canOpener","cubes01","cubes02","cubes03"]

for i in objects :
        i.visible(0)

degreesY = [0,60,120,180,240,300]
degreesZ = [0,60,300]
degreesX = [0,180]


for obj in objects :
        if obj == s :
                object = objectStrings[0]
        elif obj == co :
                object = objectStrings[1]
        elif obj == c1 :
                object = objectStrings[2]
        elif obj == c2 :
                object = objectStrings[3]
        elif obj == c3 :
                object = objectStrings[4]
        obj.visible(1)
        for degree in range(0, len(degreesX)) :
                for i in range(0, len(degreesZ)) :
                        for j in range(0, len(degreesY)) :
                                obj.rotate(degreesX[degree], degreesY[j], degreesZ[i])
                                viz.window.screenCapture('pictures\\' + object + '_' + str(degreesX[degree]) + '_' + str(degreesY[j]) + '_' + str(degreesZ[i]) + '.bmp')
                                print "Created: " + object + "_" + str(degreesX[degree]) + "_" + str(degreesY[j]) + "_" + str(degreesZ[i]) + ".bmp"


farshizzo 09-09-2009 12:12 PM

You should use the viztask module to generate screenshots within a loop. Simply yield one frame in between screenshots and they should all be saved correctly. Here is a sample script:
Code:

import viz
import viztask
viz.go()

model = viz.add('vcc_female.cfg',pos=(0,1,3))

def ScreenShotTask():
       
        for x in range(10):
               
                #Rotate model
                model.setEuler(x*36,0,0)
               
                #Request screen capture at end of frame
                viz.window.screenCapture('image%02d.bmp'%(x))
               
                #Wait for frame
                yield None
       
viztask.schedule( ScreenShotTask() )


krimble 09-14-2009 02:20 AM

Thank you so much, this saves a tons of time!


All times are GMT -7. The time now is 05:17 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC