Skip to content

Commit 43ab206

Browse files
fix: bugs and docs
1 parent d85217f commit 43ab206

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,14 +946,24 @@ def add_text(
946946
**kwargs
947947
)
948948
elif len(position) == 3:
949-
# 3D world coordinates - use add_point_labels
950-
import numpy as np
951-
points = np.array([position])
952-
actor = self._pl.scene.add_point_labels(
953-
points,
954-
[text],
955-
font_size=font_size,
956-
text_color=color,
949+
# 3D world coordinates - create 3D text mesh
950+
# We use Text3D instead of add_point_labels to avoid a bug in PyVista
951+
# where it tries to access a non-existent _actors attribute
952+
953+
# Create 3D text object
954+
text_mesh = pv.Text3D(text, depth=0.0)
955+
956+
# Scale text based on font_size (approximate scaling factor)
957+
scale_factor = font_size / 100.0
958+
text_mesh.points *= scale_factor
959+
960+
# Translate text to desired position
961+
text_mesh.translate(position, inplace=True)
962+
963+
# Add text mesh to scene with specified color
964+
actor = self._pl.scene.add_mesh(
965+
text_mesh,
966+
color=color,
957967
**kwargs
958968
)
959969
else:

src/ansys/tools/visualization_interface/backends/pyvista/pyvista_interface.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,19 @@ def show(
443443
jupyter_backend = "html"
444444

445445
# Enabling anti-aliasing by default on scene
446-
self.scene.enable_anti_aliasing("ssaa")
446+
# Only enable if render_window is available (not None)
447+
if hasattr(self.scene, 'render_window') and self.scene.render_window is not None:
448+
self.scene.enable_anti_aliasing("ssaa")
447449

448450
# If screenshot is requested, set off_screen to True for the plotter
449451
if kwargs.get("screenshot") is not None:
450452
self.scene.off_screen = True
453+
454+
# In off-screen mode (e.g., sphinx-gallery), prevent auto-close
455+
# so the plotter can be reused
456+
if self.scene.off_screen and 'auto_close' not in kwargs:
457+
kwargs['auto_close'] = False
458+
451459
if jupyter_backend:
452460
# Remove jupyter_backend from show options since we pass it manually
453461
kwargs.pop("jupyter_backend", None)

0 commit comments

Comments
 (0)