Visual Studio Code vs Sublime Text script execution and re-execution with opened external windows (UI or VTK renderer)

大城市里の小女人 提交于 2020-04-30 06:34:27

问题


I'm having issues re-running a python script using the "Run Python File in Terminal". I come from a Sublime Text 3 background. In sublime, I usually run some code that renders 3D STL using the VTK module. When I run the code, a renderer window opens displaying the 3D model. Typically, in Sublime Text, when I rerun the script, a new renderer window opens showing the same 3D model. So for every script run, a new renderer window opens. In VS Code, a renderer window opens on the first run but then the script is blocked. If I run the script again without closing the renderer window, the execution is blocked until the renderer window is closed. This poses an issue since I need to sometimes compare changes in the model between script run and how they render.

Is there a way to avoid having to close a renderer window to run the script again?

Best Regards,

Sample 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()

回答1:


It sounds like Sublime Text creates a new terminal on every execution while VS Code reuses the same terminal to save the cost/overhead of the recreation. If you need to compare two terminals simultaneously you can launch multiple terminals in VS Code and copy-and-paste the execution line from one terminal and paste it into the other.



来源:https://stackoverflow.com/questions/61326585/visual-studio-code-vs-sublime-text-script-execution-and-re-execution-with-opened

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!