def contour(): """The script itself. We needn't have defined a function but having a function makes this more reusable. """ # 'mayavi' is always defined on the interpreter. # Create a new scene. mayavi.new_scene() # Read a VTK (old style) data file. r = VTKFileReader() filename = join(mayavi2.get_data_dir(dirname(abspath(__file__))), 'heart.vtk') r.initialize(filename) mayavi.add_source(r) # Create an outline for the data. o = Outline() mayavi.add_module(o) # Create three simple grid plane modules. # First normal to 'x' axis. gp = GridPlane() mayavi.add_module(gp) # Second normal to 'y' axis. gp = GridPlane() mayavi.add_module(gp) gp.grid_plane.axis = 'y' # Third normal to 'z' axis. gp = GridPlane() mayavi.add_module(gp) gp.grid_plane.axis = 'z' # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the position to the middle of the data. cgp.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 15 cgp.contour.filled_contours = True # An isosurface module. iso = IsoSurface(compute_normals=True) mayavi.add_module(iso) iso.contour.contours = [220.0] # An interactive scalar cut plane. cp = ScalarCutPlane() mayavi.add_module(cp) cp.implicit_plane.normal = 0, 0, 1
def setUp(self): """Initial setting up of test fixture, automatically called by TestCase before any other test method is invoked""" e = NullEngine() # Uncomment to see visualization for debugging etc. #e = Engine() e.start() e.new_scene() self.e = e sgrid = datasets.generateStructuredGrid() src = VTKDataSource(data=sgrid) e.add_source(src) # Create an outline for the data. o = Outline() e.add_module(o) # Create one ContourGridPlane normal to the 'x' axis. cgp1 = ContourGridPlane() e.add_module(cgp1) # Set the position to the middle of the data. cgp1.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp2 = ContourGridPlane() cgp2.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp2.grid_plane.axis = 'y' cgp2.grid_plane.position = 15 e.add_module(cgp2) # An isosurface module. iso = IsoSurface(compute_normals=True) e.add_module(iso) iso.contour.contours = [5] # An interactive scalar cut plane. cp = ScalarCutPlane() e.add_module(cp) ip = cp.implicit_plane ip.normal = 0, 0, 1 ip.origin = 0.5, 0.5, 1.0 # Since this is running offscreen this seems necessary. ip.widget.origin = 0.5, 0.5, 1.0 ip.widget.enabled = False self.scene = e.current_scene self.cgp2 = cgp2 self.iso = iso self.cp = cp return
def contour(i, x): """The script itself. We needn't have defined a function but having a function makes this more reusable. """ # 'mayavi' is always defined on the interpreter. # Create a new scene. mayavi.new_scene() # Read in datacube fd = open("output/output-cube-%.8d-%.3d" % (i, 0)) rho, rhovx, rhovz, rhovy = numpy.fromfile(file=fd, dtype=numpy.float32).reshape( (4, x, x, x)) src = ArraySource(transpose_input_array=False) src.scalar_data = numpy.log10(rho).T.copy() mayavi.add_source(src) # Create an outline for the data. o = Outline() mayavi.add_module(o) # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the position to the middle of the data. cgp.grid_plane.position = 0 # Another normal to 'y' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 0 # Another normal to 'z' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'z' cgp.grid_plane.position = 0 # An isosurface module. iso = IsoSurface(compute_normals=False) mayavi.add_module(iso) iso.contour.contours = [220.0] # An interactive scalar cut plane. cp = ScalarCutPlane() mayavi.add_module(cp) cp.implicit_plane.normal = 0, 0, 1
def run(self): from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.mayavi.filters.threshold import Threshold from enthought.mayavi.modules.surface import Surface from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane self._setupScene() data = self._readData() script = self.script script.add_source(VTKDataSource(data=data)) script.engine.current_object.name = "Error" error = script.engine.current_object threshold = Threshold() script.add_filter(threshold) threshold.lower_threshold = -3.0 surf = Surface() script.add_filter(surf) if showSlice: surf.actor.property.opacity = 0.3 script.engine.current_object = error slice = ScalarCutPlane() script.add_module(slice) slice.actor.property.opacity = 0.5 slice.implicit_plane.origin = (12.0, 12.0, -12.0) slice.implicit_plane.normal = (0, -1.0, 0.0) for obj in [slice, surf]: colorbar = obj.module_manager.scalar_lut_manager colorbar.data_range = (threshold.lower_threshold, -2.0) colorbar.lut_mode = "hot" colorbar.reverse_lut = True colorbar.show_scalar_bar = True colorbar.number_of_labels = 6 colorbar.scalar_bar.label_format = "%-3.1f" w,h = colorbar.scalar_bar.position2 colorbar.scalar_bar.position2 = (w, 0.1) light = script.engine.current_scene.scene.light_manager.lights[0] light.elevation = 20.0 light.azimuth = -45.0 import vtk_geometry vtk_geometry.setCamera(script.engine.current_scene.scene.camera) return
def setUp(self): e = NullEngine() # Uncomment to see visualization for debugging etc. #e = Engine() e.start() e.new_scene() self.e=e # Read a VTK XML data file. r = VTKXMLFileReader() r.initialize(get_example_data('cube.vti')) e.add_source(r) # Create an outline for the data. o = Outline() e.add_module(o) # Create one ContourGridPlane normal to the 'x' axis. cgp1 = ContourGridPlane() e.add_module(cgp1) # Set the position to the middle of the data. cgp1.grid_plane.position = 1 # Another with filled contours normal to 'y' axis. cgp2 = ContourGridPlane() cgp2.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp2.grid_plane.axis = 'y' cgp2.grid_plane.position = 1 e.add_module(cgp2) # An interactive scalar cut plane. cp = ScalarCutPlane() e.add_module(cp) ip = cp.implicit_plane ip.normal = 0,0,1 ip.origin = 0.5, 0.5, 1.0 # Since this is running offscreen this seems necessary. ip.widget.origin = 0.5, 0.5, 1.0 ip.widget.enabled = False self.scene = e.current_scene self.cgp2=cgp2 self.cp=cp return
# <codecell> from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane from enthought.mayavi.filters.point_to_cell_data import PointToCellData # <markdowncell> # then add the !ScalarCutPlane module "above" the !PointToCellData filter, # as usual: # # <codecell> ptocd = PointToCellData() script.add_filter(ptocd) scp = ScalarCutPlane() ptocd.add_module(scp) scp.implicit_plane.normal = (1, 0, 0) scp.implicit_plane.origin = (10, 25, 25) scp.implicit_plane.widget.enabled = False scp.actor.property.diffuse = 0.0 scp.actor.property.ambient = 1.0 scp.actor.property.opacity = 1.0 scp.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # Thus, you can see your data on each cell and not as points (compare to # the first figure showing the use of the !ScalarCutPlane module): # # ![](files/MayaVi(2f)ScriptingMayavi2(2f)Filters_attachments/filter_p2c.png
scene1.scene.z_plus_view() scene1.scene.camera.zoom(mag) enthought.mayavi.mlab.savefig(filename + '+Z.png', size=[500, 500]) enthought.mayavi.mlab.savefig(filename + '+Z.ps', size=[500, 500]) scene1.scene.z_minus_view() scene1.scene.camera.zoom(mag) enthought.mayavi.mlab.savefig(filename + '-Z.png', size=[500, 500]) enthought.mayavi.mlab.savefig(filename + '-Z.ps', size=[500, 500]) #scalar cut plane module_manager1.scalar_lut_manager.data_range = array([0, 1]) scene1.scene.x_plus_view() iso_surface1 = engine.scenes[1].children[0].children[0].children[0] iso_surface1.actor.property.opacity = 0.20000000000000001 from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane scalar_cut_plane = ScalarCutPlane() engine.add_module(scalar_cut_plane, obj=None) origin = scalar_cut_plane.implicit_plane.plane.origin print 'Origin -', origin scalar_cut_plane.implicit_plane.widget.origin = origin scalar_cut_plane.warp_scalar.filter.normal = array([1., 0., 0.]) scalar_cut_plane.implicit_plane.widget.normal = array([1., 0., 0.]) scalar_cut_plane.implicit_plane.widget.enabled = False scene1.scene.reset_zoom() scene1.scene.camera.zoom(zoom) scene1.scene.render() module_manager1 = engine.scenes[1].children[0].children[0] module_manager1.scalar_lut_manager.show_scalar_bar = True module_manager1.scalar_lut_manager.show_legend = True
# # Thus, you have to type: # # <codecell> from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane # <markdowncell> # and # # <codecell> scp = ScalarCutPlane() # set scp as ScalarCutPlane() module script.add_module(scp) # add module to the scene scp.implicit_plane.normal = (1, 0, 0) # set normal to Ox axis # set origin to (i=10, j=25, k=25) i.e. integers for a structured grid scp.implicit_plane.origin = (10, 25, 25) # set origin to (x=1.0, y=2.5, z=2.5) i.e. reals for unstructured grids # scp.implicit_plane.origin = (1.0, 2.5, 2.5) scp.implicit_plane.widget.enabled = False scp.actor.property.diffuse = 0.0 # set some color properties scp.actor.property.ambient = 1.0 # scp.actor.property.opacity = 1.0 # scp.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_scp.png
x, y, z = np.mgrid[-1:1:20j, -1:1:20j, 0:1:10j] surface = mlab.contour3d(sphere(x, y, z), transparent=True) surface.contour.auto_contours = False surface.contour.contours = [1.0] surface.actor.property.opacity = 0.3 axes = mlab.axes(xlabel='x', ylabel='y', zlabel='z') axes.axes.use_ranges = True axes.axes.ranges = np.array([-1., -1., 0., 1., 1., 1.]) engine = mlab.get_engine() module_manager = engine.scenes[0].children[0].children[0] cut_plane = ScalarCutPlane() engine.add_filter(cut_plane, module_manager) cut_plane.warp_scalar.filter.normal = np.array([1., 0., 0.]) cut_plane.enable_contours = True cut_plane.contour.auto_contours = True cut_plane.contour.maximum_contour = 1.0 cut_plane.contour.number_of_contours = 3 cut_plane.contour.filled_contours = True cut_plane.implicit_plane.widget.origin = np.array([15, 10, 5]) cut_plane.implicit_plane.widget.enabled = False circle = ScalarCutPlane() engine.add_filter(circle, module_manager) circle.enable_contours = True
return x**2+y**2+z**2 x, y, z = np.mgrid[-1:1:20j, -1:1:20j, 0:1:10j] surface = mlab.contour3d(sphere(x,y,z), transparent=True) surface.contour.auto_contours = False surface.contour.contours = [1.0] surface.actor.property.opacity = 0.3 axes =mlab.axes(xlabel='x', ylabel='y', zlabel='z') axes.axes.use_ranges = True axes.axes.ranges = np.array([-1., -1., 0., 1., 1., 1.]) engine = mlab.get_engine() module_manager = engine.scenes[0].children[0].children[0] cut_plane = ScalarCutPlane() engine.add_filter(cut_plane, module_manager) cut_plane.warp_scalar.filter.normal = np.array([ 1., 0., 0.]) cut_plane.enable_contours = True cut_plane.contour.auto_contours = True cut_plane.contour.maximum_contour = 1.0 cut_plane.contour.number_of_contours = 3 cut_plane.contour.filled_contours = True cut_plane.implicit_plane.widget.origin = np.array([ 15,10,5]) cut_plane.implicit_plane.widget.enabled = False circle = ScalarCutPlane() engine.add_filter(circle, module_manager) circle.enable_contours = True
def do(self): ############################################################ # Imports. script = self.script from enthought.mayavi.sources.vtk_file_reader import VTKFileReader from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.modules.contour_grid_plane \ import ContourGridPlane from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() # Read a VTK (old style) data file. r = VTKFileReader() r.initialize(get_example_data('heart.vtk')) script.add_source(r) # Create an outline for the data. o = Outline() script.add_module(o) # Create one ContourGridPlane normal to the 'x' axis. cgp1 = ContourGridPlane() script.add_module(cgp1) # Set the position to the middle of the data. cgp1.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp2 = ContourGridPlane() cgp2.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp2.grid_plane.axis = 'y' cgp2.grid_plane.position = 15 script.add_module(cgp2) # An isosurface module. iso = IsoSurface(compute_normals=True) script.add_module(iso) iso.contour.contours = [200.0] # An interactive scalar cut plane. cp = ScalarCutPlane() script.add_module(cp) ip = cp.implicit_plane ip.normal = 0,0,1 ip.origin = 0,0,5 ip.widget.enabled = False # Set the scene to an isometric view. s.scene.isometric_view() # Now test. self.check() ############################################################ # Test if the modules respond correctly when the components # are changed. ctr = cgp2.contour cgp2.contour = ctr.__class__() cgp2.contour = ctr cgp2.actor = cgp2.actor.__class__() iso.contour = iso.contour.__class__() iso.contour.contours = [200.0] iso.actor = iso.actor.__class__() iso.normals = iso.normals.__class__() ip = cp.implicit_plane cp.implicit_plane = cp.implicit_plane.__class__() cp.implicit_plane = ip ip.widget.enabled = False cp.contour = cp.contour.__class__() cp.cutter = cp.cutter.__class__() cp.actor = cp.actor.__class__() s.render() # Now check. self.check() ############################################################ # Test if saving a visualization and restoring it works. # Save visualization. f = StringIO() f.name = abspath('test.mv2') # We simulate a file. script.save_visualization(f) f.seek(0) # So we can read this saved data. # Remove existing scene. engine = script.engine engine.close_scene(s) # Load visualization script.load_visualization(f) s = engine.current_scene self.check() ############################################################ # Test if the MayaVi2 visualization can be deep-copied. # Pop the source object. source = s.children.pop() # Add it back to see if that works without error. s.children.append(source) # Now set the enabled status of the widget, this is impossible # to get correctly. cp = source.children[0].children[-1] cp.implicit_plane.widget.enabled = False self.check() # Now deepcopy the source and replace the existing one with # the copy. This basically simulates cutting/copying the # object from the UI via the right-click menu on the tree # view, and pasting the copy back. source1 = copy.deepcopy(source) s.children[0] = source1 cp = source1.children[0].children[-1] cp.implicit_plane.widget.enabled = False self.check()
# `* widget enabled or not: if enabled, you can play with the mouse to modify normal orientation, position, etc.;`\ # `* some colors properties.` # # Thus, you have to type: # # <codecell> from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane # <markdowncell> # and # # <codecell> scp = ScalarCutPlane() # set scp as ScalarCutPlane() module script.add_module(scp) # add module to the scene scp.implicit_plane.normal = (1, 0, 0) # set normal to Ox axis # set origin to (i=10, j=25, k=25) i.e. integers for a structured grid scp.implicit_plane.origin = (10, 25, 25) # set origin to (x=1.0, y=2.5, z=2.5) i.e. reals for unstructured grids # scp.implicit_plane.origin = (1.0, 2.5, 2.5) scp.implicit_plane.widget.enabled = False scp.actor.property.diffuse = 0.0 # set some color properties scp.actor.property.ambient = 1.0 # scp.actor.property.opacity = 1.0 # scp.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_scp.png
def generate_mayavi_line_plot(self, srcid_sciclasses_list, use_linfit_segments=False, enable_mayavi2_interactive_gui=False): """ Generate a Mayavi mlab 3D plot which summarizes iterative classification of a TUTOR source over the number of epochs used/added. """ # TODO: I would like to plot each sci class a different color # - I should have each science class re-use a single number/color # - I should label which science class by color, as Y axis labels # TODO: I will need to insert a 0 point onto arrays (for s[0]?) if enable_mayavi2_interactive_gui: from enthought.mayavi.scripts import mayavi2 mayavi2.standalone(globals()) from enthought.mayavi import mlab # scalar cut plane plotting module stuff: import enthought.mayavi from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane epoch_ids = [0] # x class_groups = [0] # y probs = [0] # z styles = [0] # numbers used for coloring & glyph sizes used_final_classes = [] i_srcid = 0 for final_class in self.pars['interested_sci_classes']: if not finalclass_ordered_dict.has_key(final_class): continue # skip this science class since nothing to plot else: used_final_classes.append(final_class) srcid_sciclasses_list = finalclass_ordered_dict[final_class] for src_id,sci_classes in srcid_sciclasses_list: print 'src_id:', src_id, '\t', final_class sci_classes.generate_linearfit_endpoints_segments() i = 0 for class_name,class_dict in sci_classes.class_dict.iteritems(): class_style = self.sciclass_style_dict[class_name] if use_linfit_segments: for segment_dict in class_dict['linfit_segments']: epoch_ids.extend([segment_dict['epoch_ids'][0]]) class_groups.extend([i_srcid]) probs.extend([0]) styles.extend([0]) epoch_ids.extend(segment_dict['epoch_ids']) class_groups.extend([i_srcid]*len(segment_dict['epoch_ids'])) probs.extend(segment_dict['probs']) styles.extend([class_style]*len(segment_dict['epoch_ids'])) epoch_ids.extend([segment_dict['epoch_ids'][-1]]) class_groups.extend([i_srcid]) probs.extend([0]) styles.extend([0]) else: epoch_ids.extend([class_dict['epoch_ids'][0]]) class_groups.extend([i_srcid]) probs.extend([0]) styles.extend([0]) epoch_ids.extend(class_dict['epoch_ids']) class_groups.extend([i_srcid]*len(class_dict['epoch_ids'])) probs.extend(class_dict['probs']) styles.extend([class_style]*len(class_dict['epoch_ids'])) epoch_ids.extend([class_dict['epoch_ids'][-1]]) class_groups.extend([i_srcid]) probs.extend([0]) styles.extend([0]) i += 1 i_srcid += 3 # Y spacing between srcids within a science-class i_srcid += 20 # Y spacing between science-class groups mlab.plot3d(numpy.array(epoch_ids), numpy.array(class_groups), numpy.array(probs)*100.0, numpy.array(styles), colormap="Paired", tube_radius=1) # extent=[0,600, # 0,i_srcid, # 15, 110]) mlab.axes(xlabel='N of epochs', ylabel='science class', zlabel='% Prob.')#, # DEBUG/UPGRADE: These seem to trigger some bug about Actor methods: # extent=[0,600, # 0,i_srcid, # -10, 110]) title_str = "num_srcids=%d probability_cut=%0.2lf factor_threshold=%0.2lf bin_size=%d poly_order=%d" % (\ self.pars['num_srcids_to_retrieve_plot'], self.pars['sciclass_probability_cut'], self.pars['polyfit_factor_threshold'], self.pars['polyfit_bin_size'], self.pars['polyfit_poly_order']) ##### TITLE: # The 'z' is a flag in Mayavi2 v3.1.0 documentation: #mlab.text(0.01, 0.97, title_str, width=1.0, name='title', z=0.0) mlab.text(0.01, 0.97, title_str, width=1.0, name='title') ##### SCIENCE CLASS LABELS: # TODO: Eventually I would like the class labels to be colored and # placed on the y axis, but this requires: # 1) later mayavi version to allow 3D text positioning # 2) ability to match text color to the line color-map. if 1: used_final_classes.reverse() y = 0.95 for class_name in used_final_classes: class_str = "%2d %s" %(len(finalclass_ordered_dict[class_name]), class_name) mlab.text(0.85, y, class_str, width=0.095*(len(class_str)/20.0)) y -= 0.018 ##### Add a x-axis plane (I can't figure out code to make it opaque) if 0: cp = ScalarCutPlane() mayavi.add_module(cp) cp.implicit_plane._hideshow() # this un-displays the plane cp.implicit_plane.normal = 0,0,1 cp.implicit_plane.origin = 150,168,15 #cp.implicit_plane.position= 0.15 # feature not available yet print '##### cp:' cp.print_traits() print '##### cp.implicit_plane:' cp.implicit_plane.print_traits() print '##### cp.implicit_plane._HideShowAction:' cp.implicit_plane._HideShowAction.print_traits() ##### Camera position: if enable_mayavi2_interactive_gui: camera_distance = 600 else: camera_distance = 1200 enthought.mayavi.tools.camera.view(azimuth=50, elevation=70, # 0:looking down to -z distance=camera_distance, focalpoint=(100,(i_srcid*0.4),50)) #enthought.mayavi.mlab.show_pipeline() # this introspecive feature is not available in current mayavi version. #####If no Mayavi2 GUI, we allow user to resize image before saving file if not enable_mayavi2_interactive_gui: print 'Please resize window & Press a Key.' import curses stdscr = curses.initscr() while 1: c = stdscr.getch() break curses.endwin() ##### Save figure: img_fpath ="/tmp/%s%s.png" %(title_str.replace('=','').replace(' ','_'), self.pars['save_plot_image_suffix']) if os.path.exists(img_fpath): os.system('rm ' + img_fpath) mlab.savefig(img_fpath)#, size=(500,500))#, dpi=200) #size flag doesn't do anything print "Saved:", img_fpath
def do(self): # Setup the source. self.make_data() from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.modules.contour_grid_plane \ import ContourGridPlane from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane script = self.script s = script.engine.current_scene # Create an outline for the data. o = Outline() script.add_module(o) # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() script.add_module(cgp) # Set the position to the middle of the data. cgp.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp = ContourGridPlane() cgp.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 15 script.add_module(cgp) # An isosurface module. iso = IsoSurface(compute_normals=True) script.add_module(iso) iso.contour.contours = [200.0] # An interactive scalar cut plane. cp = ScalarCutPlane() script.add_module(cp) ip = cp.implicit_plane ip.normal = 0, 0, 1 ip.origin = 0, 0, 5 ip.widget.enabled = False # Set the scene to an isometric view. s.scene.isometric_view() self.check() ############################################################ # Test if saving a visualization and restoring it works. # Save visualization. f = StringIO() f.name = abspath('test.mv2') # We simulate a file. script.save_visualization(f) f.seek(0) # So we can read this saved data. # Remove existing scene. engine = script.engine engine.close_scene(s) # Load visualization script.load_visualization(f) s = engine.current_scene self.check() ############################################################ # Test if the MayaVi2 visualization can be deep-copied. # Pop the source object. source = s.children.pop() # Add it back to see if that works without error. s.children.append(source) # Now set the enabled status of the widget, this is impossible # to get correctly. cp = source.children[0].children[-1] cp.implicit_plane.widget.enabled = False self.check() # Now deepcopy the source and replace the existing one with # the copy. This basically simulates cutting/copying the # object from the UI via the right-click menu on the tree # view, and pasting the copy back. source1 = copy.deepcopy(source) s.children[0] = source1 cp = source1.children[0].children[-1] cp.implicit_plane.widget.enabled = False self.check()