How to Capture Viewport Content as an Image Using Allplan PythonParts API?


Hello Allplan Community,

I am currently working with the Allplan PythonParts API and I aim to output some dimension lines and 2D shapes. I am writing a script to automatically generate drawings, and I would like to capture some of the drawing content as images for use in automatically generated reports.

Has anyone done this before or is there a built-in function within the PythonParts API that supports this? Any guidance or code examples would be greatly appreciated.

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Zitiert von: Wangzhonglei
Hello Allplan Community,
I am currently working with the Allplan PythonParts API and I aim to output some dimension lines and 2D shapes. I am writing a script to automatically generate drawings, and I would like to capture some of the drawing content as images for use in automatically generated reports.
Has anyone done this before or is there a built-in function within the PythonParts API that supports this? Any guidance or code examples would be greatly appreciated.

Hi,

I think the function you are looking for, will be available in 2025 which is not released yet. But you can already test it, if you have access to Beta version of Allplan.

The function you are looking for is the SaveWindowToImageFile. It saves the content of the currently active viewport to an image file. Here is an example.
If you want to zoom to a specific content in the viewport, you can use the ZoomService. Here is an example.

However, I am not sure whether this approach will meet your requirements. You are not able to tell, what viewport is active. You can tell, whether the viewport shows the ground view of the model, but you can't make it show the ground view (user has to do it). And while your PythonPart will zoom to various elements to make a snapshot of them, the screen will flicker so I don't know if this is a nice UX. But you can give it a try.

Best,
Bart

Zitiert von: Wangzhonglei
Hello Allplan Community,
I am currently working with the Allplan PythonParts API and I aim to output some dimension lines and 2D shapes. I am writing a script to automatically generate drawings, and I would like to capture some of the drawing content as images for use in automatically generated reports.
Has anyone done this before or is there a built-in function within the PythonParts API that supports this? Any guidance or code examples would be greatly appreciated.

Hi,

I think the function you are looking for, will be available in 2025 which is not released yet. But you can already test it, if you have access to Beta version of Allplan.

The function you are looking for is the SaveWindowToImageFile. It saves the content of the currently active viewport to an image file. Here is an example.
If you want to zoom to a specific content in the viewport, you can use the ZoomService. Here is an example.

However, I am not sure whether this approach will meet your requirements. You are not able to tell, what viewport is active. You can tell, whether the viewport shows the ground view of the model, but you can't make it show the ground view (user has to do it). And while your PythonPart will zoom to various elements to make a snapshot of them, the screen will flicker so I don't know if this is a nice UX. But you can give it a try.

Best,
Bart