Skip to content

Commit 5841368

Browse files
committed
Changed default port + Added ability to select Port
- Closes #10 - Minor changes/improvements.
1 parent c4b193f commit 5841368

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Blender Debugger for VS Code (and Visual Studio)
1+
# Blender Debugger for VS Code (and Visual Studio)
22

33
Inspired by [Blender-VScode-Debugger](https://github.com/Barbarbarbarian/Blender-VScode-Debugger) which was itself inspired by this [remote_debugger](https://github.com/sybrenstuvel/random-blender-addons/blob/master/remote_debugger.py) for pycharm as explained in this [Blender Developer's Blog post](https://code.blender.org/2015/10/debugging-python-code-with-pycharm/).
44

@@ -86,9 +86,7 @@ Go to the Debugging tab and add a configuration. Pick Python. You'll want the co
8686
"name": "Python: Attach",
8787
"type": "python",
8888
"request": "attach",
89-
"localRoot": "${workspaceFolder}",
90-
"remoteRoot": "${workspaceFolder}",
91-
"port": 3000,
89+
"port": 5678, //careful, this used to be 3000 in older versions of vscode and this addon
9290
"host": "localhost"
9391
},
9492
```
@@ -123,8 +121,9 @@ Now in Blender the text editor will show this little red button in the top left.
123121
- To determine whether the problem is on Blender's side or your editor's: Close Blender and download/copy this [test script](https://gist.github.com/AlansCodeLog/ff1b246a8e31938e1c3dbfdcbb90522f) and run it with Python, and then try to connect to the server with your editor. If you're still getting problems then the problem is with VS Code, try:
124122
- Check your detected your Python install, or set it manually.
125123
- For VS Code try reinstalling the VS Code Python extension.
124+
- If you've been using this addon for a while and it's suddenly giving you a connection error, it might be because the default port has changed. VS Code's Python extension (vscode-python) has changed their default port from 3000 to 5678, so I have changed the default accordingly. I've made it configurable now though, so just check the port the addon is set to matches the one in your `launch.json` in VS Code.
126125

127-
Otherwise, if nothing works, don't hesitate to file an issue.
126+
Otherwise, if none of that helped, don't hesitate to file an issue.
128127

129128
# Notes
130129

__init__.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
bl_info = {
2222
'name': 'Debugger for VS Code',
2323
'author': 'Alan North',
24-
'version': (0, 2, 0),
24+
'version': (0, 3, 0),
2525
'blender': (2, 79, 0),
2626
"description": "Starts debugging server for VS Code.",
2727
'location': 'In search (default shortcut:space) type "Debug"',
@@ -92,18 +92,32 @@ class DebuggerPreferences(bpy.types.AddonPreferences):
9292
name="Timeout",
9393
default=20
9494
)
95+
96+
port = bpy.props.IntProperty(
97+
name="Port",
98+
min=0,
99+
max=65535,
100+
default=5678
101+
)
95102
def draw(self, context):
96103
layout = self.layout
97-
layout.prop(self, "path")
98-
layout.label(text="Pluging will try to auto-find it, if no path found, or you would like to use a different path, set it here.")
99-
row = layout.split()
100-
row.label(text="Timeout in seconds for attach confirmation listener.")
101-
row.prop(self, "timeout")
104+
row_path = layout
105+
row_path.label(text="The addon will try to auto-find the location to ptvsd, if no path is found, or you would like to use a different path, set it here.")
106+
row_path.prop(self, "path")
107+
108+
row_timeout = layout.split()
109+
row_timeout.prop(self, "timeout")
110+
row_timeout.label(text="Timeout in seconds for the attach confirmation listener.")
111+
112+
row_port = layout.split()
113+
row_port.prop(self, "port")
114+
row_port.label(text="Port to use. Should match port in VS Code's launch.json.")
115+
102116

103117
# check if debugger has attached
104-
def check_done(i, modal_limit):
118+
def check_done(i, modal_limit, prefs):
105119
if i == 0 or i % 60 == 0:
106-
print("Waiting...")
120+
print("Waiting... (on port "+str(prefs.port)+")")
107121
if i > modal_limit:
108122
print("Attach Confirmation Listener Timed Out")
109123
return {"CANCELLED"}
@@ -125,7 +139,8 @@ class DebuggerCheck(bpy.types.Operator):
125139
def modal(self, context, event):
126140
self.count = self.count + 1
127141
if event.type == "TIMER":
128-
return check_done(self.count, self.modal_limit)
142+
prefs = bpy.context.user_preferences.addons[__name__].preferences
143+
return check_done(self.count, self.modal_limit, prefs)
129144
return {"PASS_THROUGH"}
130145

131146
def execute(self, context):
@@ -153,6 +168,7 @@ def execute(self, context):
153168
#get ptvsd and import if exists
154169
prefs = bpy.context.user_preferences.addons[__name__].preferences
155170
ptvsd_path = prefs.path
171+
ptvsd_port = prefs.port
156172

157173
#actually check ptvsd is still available
158174
if ptvsd_path == "PTVSD not Found":
@@ -171,7 +187,7 @@ def execute(self, context):
171187

172188
# can only be attached once, no way to detach (at least not that I understand?)
173189
try:
174-
ptvsd.enable_attach(("0.0.0.0", 3000), redirect_output=True)
190+
ptvsd.enable_attach(("0.0.0.0", ptvsd_port), redirect_output=True)
175191
except:
176192
print("Server already running.")
177193

0 commit comments

Comments
 (0)