HardCopy from Python script

I am using Coreform Cubit 2023.8 on Windows 10.
When I run the following Python script with Python, png file is not created.
When I run from the correponing journal file, then png file is generated.
I am expecting to do it from CLI.

import sys
sys.path.append(“C:/Program Files/Coreform Cubit 2023.8/bin”)
import cubit
cubit.init()
cubit.cmd(‘reset’)
cubit.cmd('create surface circle radius 5 zplane ')
cubit.cmd(‘hardcopy “test.png” png window 1’)

Hello,
have you already tried to run your script with the python that’s delivered with cubit?
you can usually find it in "..\Coreform Cubit 2023.8\bin\python3"

This should normally work and you can start scripting.

I will take a closer look at the problem and get back to you as soon as possible.

Hi @ksugahar – when you’re running from a Python script (or similar “no-graphics” modes) you’ll need to create a graphics window manually to then draw / render the model before hardcopy.

There are several graphics commands that will help you, but the minimal command is:

graphics window create <id>

As you can see in the GIF below, prior to creating the window I can’t hardcopy, as evidenced by test_1.png not existing, but when I create the window (with id=2) a window will pop up (briefly, but note the top of the window says Coreform Cubit 2023.10 (<id>)) and then the hardcopy command works.

Python-Hardcopy-1

The other commands which you may be interested in are:

Graphics WindowLocation <xlocation> <ylocation>
Graphics WindowSize <width_in_pixels> <height_in_pixels>
Graphics WindowSize Maximum
Graphics WindowSize Minimum
Graphics WindowSize Restore 
Graphics Window Create <number>
Graphics Window Active <number>
Graphics Window Delete <number>

Note that I got these commands by typing into the command line: graphics window ?. Note that when you run in a nogui or nographics mode I believe that your graphics & display preferences aren’t loaded. However, you can find all the graphics commands by typing graphics ? - which will help you reset some properties (and you may also be interested in color ? for background and default entity colors).

– Greg

1 Like

There is one other thing you can do if you don’t want a graphics window popping up.

cubit.init(['cubit', '-driver', 'offscreen'])

This should work except in a couple cases:

  1. Ssh into a mac machine and not being attached to the display.
  2. Ssh into a RHEL7 or older linux machine and not being attached to the display. RHEL8 and newer supports Cubit’s offscreen rendering, even without a display or graphics card.
1 Like

Thank you. It worked!!