Model Clipping

Create section views through complex assemblies to inspect internal components and clearances.

This tutorial demonstrates how to implement 3D model slicing using using interactive clipping planes.

Clipped view of Model.



# Import necessary modules

import sys  # Provides access to system-specific parameters and functions
from PySide6.QtWidgets import QApplication, QMainWindow  # Import Qt widgets for GUI application

# Import IGLGraphics modules for display context and viewer
from IGLGraphics.core.IGLDisplayContext import IGLDisplayContext
from IGLGraphics.graphics.IGLViewer import IGLViewer
from IGLGraphics.geometry.IGLImport import IGLImport

# Create the QApplication instance,
# which manages the application's control flow and main settings
app = QApplication(sys.argv)

# Create the main window of the application
win = QMainWindow()

# Set the title of the main window
win.setWindowTitle("IGLGraphics Test")  

# Create an instance of IGLViewer, which is a IGLViewer widget for 
# displaying models and handling user interactions

view = IGLViewer()

# Turn on clipping in the viewer to enable the use of clipping planes for slicing the model
view.SetClipping(True)

origin = [0,0,0] # at view center
normal = [1,0,0] # plane normal to x-axis

# Set Clip plane
view.SetClipPlane(origin, normal)

# Create an IGLDisplayContext associated with the viewer, for managing graphics rendering context

thecontext = IGLDisplayContext(view)

# Create an instance of IGLImport to handle importing geometry data from files
importer = IGLImport()
filename = 'Saddle.json'
is_valid, Assemblies = importer.ImportGeo(filename)

thecontext.AddAssembly(Assemblies)  # Add the imported assemblies to the display context

# Set the central widget of the main window to the IGLViewer
win.setCentralWidget(view)

# Resize the window to 800x600 pixels
win.resize(800, 600)

# Show the main window
win.show()

view.OnZoomFit()  # Adjust the view to fit the entire model in the viewport

# Start the application's event loop and exit when it finishes
sys.exit(app.exec())