Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Script Python - Change View and Take Screenshot Automatic

Discussion in 'Pixyz' started by CDMAdmin, Jun 26, 2023.

  1. CDMAdmin

    CDMAdmin

    Joined:
    Oct 20, 2018
    Posts:
    2
    Hi everyone,
    I would like to know if there is a script that can help me to automatic take 4 screenshot in all different views of my model imported in PiXYZ Studio.
    I'd like to get the .png file for front, back, top and bottom view in an automatic python script.

    Thank you for your help

    Francesco
     
  2. laurent-milon

    laurent-milon

    Unity Technologies

    Joined:
    Nov 30, 2022
    Posts:
    14
    Hi @CDMAdmin , thanks for joining the Unity Pixyz forum!
    Hum, I don't have that precise script in hands but here is a good starting point for you:

    OUTPUT_FILE = r'C:\Users\LaurentMilon\Desktop/screenshot.png'
    WIDTH = 2000
    HEIGHT = 1000
    # this variable corresponds to a specific viewer view. Get the one you like by printing view.getViewerMatrices(-1) in Pixyz Studio
    viewerMatrices = {
    'views': [[[0.69, 0, 0.71, 0.0], [0.44, 0.78, -0.43, 0.0], [-0.56, 0.62, 0.54, -2794], [0.0, 0.0, 0.0, 1.0]]],\
    'projs': [[[1.73, 0.0, 0.0, 0.0], [0.0, 3.5, 0.0, 0.0], [0.0, 0.0, -1.6, -3430], [0.0, 0.0, -1.0, 0.0]]],\
    'clipping': pxz.geom.Point2(1317, 5675)\
    }
    # Choose your output picture resolution here. Depends on viewerMatrices.
    viewer = view.createViewer(WIDTH, HEIGHT)
    view.addRoot(scene.getRoot(), viewer) # add model to viewer
    view.showLines(False, viewer) # don't display lines
    # view.fitView(viewer) # fit view on model (not mandatory if you use your specific view matrices)
    view.setViewerMatrices(viewerMatrices['views'], viewerMatrices["projs"], viewerMatrices["clipping"], viewer)
    view.refreshViewer(viewer, forceUpdate=True) # refresh viewer, otherwise modifications won't be taken into account (addRoot, showLines...)
    view.takeScreenshot(OUTPUT_FILE, viewer)


    All you'll have to adjust is the "viewerMatrices" and replace the values using Front, Back, ... or any other POV you'd like to capture.

    Note: don't forget to change the output file path of course
     
    CDMAdmin likes this.