• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Simufact
  3. Issues with scripting in simufact

Following Cadence Design Systems’ acquisition of the Design & Engineering (D&E) business, the D&E Community Forum on the Nexus Community Center has been migrated in the Cadence Physical System Simulation Community. For more details and if you have any questions, please refer to the FAQ.

Stats

  • State Not Answered
  • Replies 4
  • Subscribers 2
  • Views 21
  • Members are here 0
More Content

Issues with scripting in simufact

asam
asam over 1 year ago

Hello all,

 I am trying to save my results contours as images with the predefined saved view and applying it to all of them using the below script but not able to get the saved view apply to all of them: 

import os
import traceback

# === Configuration ===
save_directory = r'C:\Users\ecslogin\OneDrive - Wright State University\PhD\Writing\IMECE 2025 Paper\V1\Results'
os.makedirs(save_directory, exist_ok=True)

# Define what to extract
result_value_list = [('EFFPLS', [0, 1]), ('TEMPTURE', 'AutomaticAllIncrements')]
increment_list = [('Forming', 100.0)]
save_images = True
save_animations = False
duration_value = 10
animation_mode_value = 'default'
process_names = []

# === Project Setup ===
project = current_project()
base_view_settings = project.result_view_settings('SavedViewA')
if base_view_settings is None:
    raise RuntimeError("X Error: 'SavedViewA' result view settings not found in project.")

# === Process Collection ===
process_list = [project.process(name=pn) for pn in process_names] if process_names else list(project.all_processes)

if not process_list:
    raise RuntimeError("X No processes found to run analysis on.")

print("Open file folder Processes found:", [p.name for p in process_list])

# === Main Loop ===
for process in process_list:
    try:
        print(f"\nArrows counterclockwise Starting: {process.name}")

        # Run analysis if not already done
        if process.results is None:
            print(f"Hourglass flowing sand Running analysis for: {process.name}")
            analysis = process.start_analysis()
            analysis.wait()
            print(f"White check mark Analysis complete for: {process.name}")

        # Open result view for this process (default view only)
        result_view = process.open_result_view()

        for result_value, legend_bounds in result_value_list:
            result_value_name = result_value[0]

            # Clone settings from SavedViewA
            settings = base_view_settings.copy()
            settings.set_result_value(result_value=result_value_name, legend_bounds=legend_bounds)

            for loadcase_name, loadcase_percent in increment_list:
                settings.increment_loadcase = loadcase_name
                settings.increment_percent = loadcase_percent

                if save_images:
                    filename = os.path.join(
                        save_directory,
                        f"{process.name}_{result_value_name}_{loadcase_name}_{loadcase_percent}.png"
                    )
                    print(f"Camera with flash Saving image: {filename}")
                    result_view.save_to_image(filename=filename, settings=settings)

                if save_animations:
                    anim_file = os.path.join(
                        save_directory,
                        f"{process.name}_{result_value_name}.avi"
                    )
                    print(f"Film frames️ Saving animation: {anim_file}")
                    result_view.save_animation(
                        filename=anim_file,
                        duration=duration_value,
                        animation_mode=animation_mode_value,
                        settings=settings
                    )

            # Clean up cloned settings object
            project.delete_result_view_settings(settings)

        result_view.close()
        print(f"Heavy check mark Finished: {process.name}")

    except Exception as e:
        print(f"X Error in {process.name}: {e}")
        traceback.print_exc()

print("\nWhite check mark Script completed for all processes.")
  • Sign in to reply
  • Cancel
  • asam
    0 asam over 1 year ago

    But when I use the following script after fixing the issue my software closes after my first process simulation, can someone please help with this issue?

    import os
    import traceback

    # === Configuration ===
    save_directory = r'C:\Users\ecslogin\OneDrive - Wright State University\PhD\Writing\IMECE 2025 Paper\V1\Results'
    os.makedirs(save_directory, exist_ok=True)

    # Define which result types and loadcases you want images for
    result_value_list = ['EFFPLS', 'TEMPTURE']
    increment_list = [('Forming', 100.0)]

    save_images = True
    save_animations = False
    duration_value = 10
    animation_mode_value = 'default'
    process_names = []

    # === Project Setup ===
    project = current_project()
    base_view_settings = project.result_view_settings('SavedViewA')
    if base_view_settings is None:
        raise RuntimeError("X Error: 'SavedViewA' result view settings not found in project.")

    # === Process Collection ===
    process_list = [project.process(name=pn) for pn in process_names] if process_names else list(project.all_processes)

    if not process_list:
        raise RuntimeError("X No processes found to run analysis on.")

    print("Open file folder Processes found:", [p.name for p in process_list])

    # === Main Processing Loop ===
    for process in process_list:
        try:
            print(f"\nArrows counterclockwise Processing: {process.name}")

            # Run analysis if needed
            if process.results is None:
                print(f"Hourglass flowing sand Running analysis for: {process.name}")
                analysis = process.start_analysis()
                analysis.wait()
                print(f"White check mark Analysis complete for: {process.name}")

            # Open result view using SavedViewA (template style)
            result_view = process.open_result_view(base_view_settings)

            for result_value in result_value_list:
                for loadcase_name, loadcase_percent in increment_list:
                    # Use the SavedViewA settings as-is without modifications
                    # Just apply it to each image you save
                    if save_images:
                        filename = os.path.join(
                            save_directory,
                            f"{process.name}_{result_value}_{loadcase_name}_{loadcase_percent}.png"
                        )
                        print(f"Camera with flash Saving image: {filename}")
                        result_view.save_to_image(filename=filename, settings=base_view_settings)

                    if save_animations:
                        anim_file = os.path.join(
                            save_directory,
                            f"{process.name}_{result_value}.avi"
                        )
                        print(f"Film frames️ Saving animation: {anim_file}")
                        result_view.save_animation(
                            filename=anim_file,
                            duration=duration_value,
                            animation_mode=animation_mode_value,
                            settings=base_view_settings
                        )

            result_view.close()
            print(f"Heavy check mark Finished: {process.name}")

        except Exception as e:
            print(f"X Error in {process.name}: {e}")
            traceback.print_exc()

    print("\nWhite check mark Script completed for all processes.")
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • M B
    0 M B over 1 year ago in reply to asam
    Unknown said:
    result_view.save_to_image(filename=filename, settings=base_view_settings)

    Hello Asam,

    I tested the code you provided her on my side.

    it looks like there is a bug with the python command in the line I quoted. I will report this to the development team. Please use the command

    save_result_view_to_image(process="UpsettingFe3D", filename=r'D:\image.png', resolution=(1920, 1080), settings=settings_obj) instead.
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • asam
    0 asam over 1 year ago in reply to M B

    I was able to run it but i couldn't find any images in the location: 


    White check mark Script completed for all processes.
    >>> Run: C:/Users/ecslogin/OneDrive - Wright State University/PhD/Writing/IMECE 2025 Paper/V1/Results/Test_run_all.py
    Open file folder Processes found: ['ForgingFe3D-2', 'ForgingFe3D-4', 'ForgingFe3D-6', 'ForgingFe3D-7', 'ForgingFe3D-9', 'ForgingFe3D-10', 'ForgingFe3D-10-fric0-1', 'ForgingFe3D-10-fric0-2', 'ForgingFe3D-10-fric0-4']

    Arrows counterclockwise Processing: ForgingFe3D-2
    Camera with flash Saving image: C:\Users\ecslogin\OneDrive - Wright State University\PhD\Writing\IMECE 2025 Paper\V1\Results\ForgingFe3D-2_EFFPLS_Forming_100.0.png
    Camera with flash Saving image: C:\Users\ecslogin\OneDrive - Wright State University\PhD\Writing\IMECE 2025 Paper\V1\Results\ForgingFe3D-2_TEMPTURE_Forming_100.0.png
    Heavy check mark Finished: ForgingFe3D-2

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • asam
    0 asam over 1 year ago in reply to asam

    Its working now i had to change my process line command 

    save_result_view_to_image(process=process.name , filename=filename, resolution=(1920, 1080), settings=base_view_settings)
    thank you! 
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2026 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information