File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed
src/ansys/tools/visualization_interface/backends/pyvista Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments