How to stop a viewport from refreshing?

How to stop a viewport from refreshing?

danielWNW3M
Contributor Contributor
908 Views
6 Replies
Message 1 of 7

How to stop a viewport from refreshing?

danielWNW3M
Contributor
Contributor

Hello, I am currently working on a project that requires me to export images of each component/occurence in my designs. I would like to grab an iso, top, front, and right image of each, to export, and I'm doing so with the code below.

Functionally, this seems to sort-of work (the images seem to drift off the bodies a bit sometimes). The biggest problem though, and the reason for this post, is that each time I adjust the camera and reassign it to the viewport, the viewport updates in the ui while the script is running. This makes the whole program wait while the viewport transitions on-screen for me, and slows down the program considerably, especially when I have a file with many components.

 

With the goHome command I can set transitions to false to avoid this problem, is there any way to do it here as well, or am I screwed with long processing times?

def export_as_image(occ, path, uuid):
    app = adsk.core.Application.get()

    if os.path.exists(path+"/design-package/payload/components/" + uuid) == False:
        os.mkdir(path+"/design-package/payload/components/" + uuid) 
    os.mkdir(path+"/design-package/payload/components/" + uuid + "/images")
        
    # isolate the occurence requested
    occ.isIsolated = True
    vp = app.activeViewport
    camera = app.activeViewport.camera

    # grab images at different angles and save them
    vp.goHome(False)
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/iso.png", 720, 720)
    
    camera.viewOrientation = adsk.core.ViewOrientations.TopViewOrientation
    camera.isFitView = True
    vp.camera = camera
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/top.png", 720, 720)

    camera.viewOrientation = adsk.core.ViewOrientations.RightViewOrientation
    camera.isFitView = True
    vp.camera = camera
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/right.png", 720, 720)

    camera.viewOrientation = adsk.core.ViewOrientations.FrontViewOrientation
    camera.isFitView = True
    vp.camera = camera
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/front.png", 720, 720)
    
    # unisolate the occurence
    occ.isIsolated = False

 

Thanks a bunch for any help

0 Likes
Accepted solutions (1)
909 Views
6 Replies
Replies (6)
Message 2 of 7

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

I don't think there could be an option to not to render the UI to the desidered view before saving the image.

 

I have two points that could be part the reason about that:

1) The Viewport.saveAsImageFile has this description:

Jorge_Jaramillo_0-1722471035465.png

2) Since the Viewport.saveAsImageFile() is a photo of UI it needs to be rendered.

 

I don't know another option to the Veiwport.saveAsImageFile() method.

 

Regards,

Jorge Jaramillo

 

Message 3 of 7

danielWNW3M
Contributor
Contributor

Thank you for the help! If the viewport must refresh I think that's okay. Is there anyway to stop the transition (like with the goHome() function) though? That's the part that really slows things down.

0 Likes
Message 4 of 7

kandennti
Mentor
Mentor
Accepted solution
Message 5 of 7

danielWNW3M
Contributor
Contributor

That did it! Don't know how I missed that in the camera object documentation. Thanks again for the help!

Message 6 of 7

Jorge_Jaramillo
Collaborator
Collaborator
Did you check the images generated?
In my case the elapsed time reduced but the images are the same in the 4 taken, since de UI is not refreshed between camera orientations settings. It refreshes only at the end of the screen, even if I call adsk.doEvents() between them.
Message 7 of 7

danielWNW3M
Contributor
Contributor

I did, and I did find I needed to refresh the viewport for it to work, but without the slow animation of the transitions it's still much faster than it was before. Here's my code in full for grabbing the iso from the home view and then three sides: 

# isolate the occurence requested
    occ.isIsolated = True
    vp = app.activeViewport
    camera = app.activeViewport.camera
    camera.isSmoothTransition = False

    # grab images at different angles and save them    
    vp.goHome(False)
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/iso.png", 720, 720)

    camera = app.activeViewport.camera
    camera.viewOrientation = adsk.core.ViewOrientations.FrontViewOrientation
    camera.isSmoothTransition = False
    camera.isFitView = True
    vp.camera = camera
    vp.refresh()
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/front.png", 720, 720)

    camera = app.activeViewport.camera
    camera.viewOrientation = adsk.core.ViewOrientations.RightViewOrientation
    camera.isSmoothTransition = False
    camera.isFitView = True
    vp.camera = camera
    vp.refresh()
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/right.png", 720, 720)

    camera = app.activeViewport.camera
    camera.viewOrientation = adsk.core.ViewOrientations.TopViewOrientation
    camera.isSmoothTransition = False
    camera.isFitView = True
    vp.camera = camera
    vp.refresh()
    vp.saveAsImageFile(path+"/design-package/payload/components/" + uuid + "/images/top.png", 720, 720)

    # unisolate the occurence
    occ.isIsolated = False

 

Thank you for double checking regardless though, it's appreciated.