GeometryView as image in code

Description of the limitation and why it is relevant to address

The geometry view can be view from within the UI, however I can’t use this image in a word report or output file like with plotly.to_image() or matplotlib fig.savefig()

Is there an option to turn a GeometryView into an image? With a possible input being viewpoint, default = axo and fit to screen? Or something simular. It would be great to add this view to a Word Report

It is now possible a manual option, however this isn’t available in the backend

Hi Johan, thanks for providing this feedback.
This request has been raised before and i will add your usecase.

1 Like

Hello both,

I think the topic is very interesting too !

Please let us know progress about it :slight_smile:

Hi @matthijs

Do you have good news about this topic ?

Thank you,
BR

Hi BR,

No there’s no current update, i will raise the internal ticket with your request.

kind regards,
Matthijs

@matthijs You pointed me here, but it has been silent on this request for a while. Can you give an update if this is planned in any way?

Just updated the status to “in-discussion” since it is not yet planned and we are gathering usecases / priority. Linked it from your request not because this can now be solved, but to make it easier to find the feature request and for us to be able to determine how many people want this.

Similar to Mark, we need this!
We have a existing app where the users want to be able to download a full report of the whole structure for wich we are using the viktor word template route. Therefore the visuals that explain the structure in the ui, are also needed to show the client (opdrachtgever) what the structure looks like. So hopefully we can get this feature soon!

Hi LM_vin, I saw this request, you can now vote for it, it might help to speed things up…

1 Like

Agreed, this would make the autogenerated reports much more useful for us!

I saw another topic by @guido.bongers about this as well, pinging you here so that you can add your vote Guido! :wink:

1 Like

Updated the post to also include how to use it in a published app

It is possible to export the geometry as image using trimesh. Try it here.

In order to do so add the following dependencies to your requirements.txt file:

trimesh
pyglet<2.0.0
scipy

The following snippet can be used to export a TransformableObject to a trimesh scene, rotate the camera and save as image. Please note that you can also use it on a Group if you want to export a larger assembly.

def download_screenshot(self, params, **kwargs):
    beam = RectangularExtrusion(width=10,
                                height=10,
                                line=Line(Point(0, 0, 0), Point(50, 0, 0)),
                                material=Material(color=Color.green()))

    scene = beam._to_trimesh()
    corners = np.concatenate(list(scene.bounds_corners.values()))
    r_e = trimesh.transformations.euler_matrix(
        math.radians(45),
        math.radians(-45),
        math.radians(0),
        "ryxz",
    )
    transform = scene.camera.look_at(points=corners, distance=100, rotation=r_e)
    scene.camera_transform = transform
    png = scene.save_image(resolution=[1920, 1080], visible=False)
    return DownloadResult(File.from_data(png), "screenshot.png")

You will need to do some additional modifications to be able to run this snippet in a published application. Add the following lines to the top of your imports to force pyglet to run in headless mode.

import pyglet
pyglet.options["headless"] = True

Additionally, you need the following dependencies to be installed during the publishing process by adding the following line to viktor.config.toml

packages = ["libglu1-mesa", "libegl1-mesa-dev"]

Please note that the _to_trimesh() method is private, which means that it might change in a new SDK version without notice. Since this is an often requested feature, I didn’t want to wait sharing it with you. I am curious to hear if and how you are going to use it!

Regards,

Raoul

4 Likes

Good to see that there is a workaround. I solved my case in another very app-specific way. However I still think it is preferable if a view can be exported from Viktor directly for use in automatic reporting