【发布时间】:2020-04-20 15:49:09
【问题描述】:
我在使用“在终端中运行 Python 文件”重新运行 Python 脚本时遇到问题。我来自 Sublime Text 3 背景。在 sublime 中,我通常使用 VTK 模块运行一些渲染 3D STL 的代码。当我运行代码时,会打开一个渲染器窗口,显示 3D 模型。通常,在 Sublime Text 中,当我重新运行脚本时,会打开一个新的渲染器窗口,显示相同的 3D 模型。因此,对于每个脚本运行,都会打开一个新的渲染器窗口。 在 VS Code 中,第一次运行时会打开一个渲染器窗口,但随后脚本会被阻止。如果我在不关闭渲染器窗口的情况下再次运行脚本,则会阻止执行,直到关闭渲染器窗口。这带来了一个问题,因为我有时需要比较脚本运行和渲染方式之间的模型变化。
有没有办法避免必须关闭渲染器窗口才能再次运行脚本?
最好的问候,
示例代码:
import vtk
# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create source
source = vtk.vtkSphereSource()
source.SetCenter(0,0,0)
source.SetRadius(5.0)
# mapper
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(source.GetOutput())
else:
mapper.SetInputConnection(source.GetOutputPort())
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# assign actor to the renderer
ren.AddActor(actor)
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
【问题讨论】:
标签: python visual-studio-code sublimetext3 vtk