[Addon] SublimeBlender - Execute scripts from Sublime Text 3

BlenderSublime : Develop with Sublime Text 3 as an external script editor.

An interactive bridge between Sublime and Blender. To improve the quality of development :slight_smile:
BlenderSublime allows you to develop, execute and debug straight from Sublime without exiting Sublime.

Features

  • Execute your script from Sublime directly in Blender
  • Sublime Console shows the console output of Blender
  • Easy to use with a Sublime Shortcut : Ctrl + E

Download : https://github.com/svenfraeys/SublimeBlender
Setup : BlenderSublime Documentation

I am still new to the world of Blender. I saw this as a good use for development.
But if there are more specific needs for Blender developers do let me know :slight_smile:

Enjoy !

1 Like

This looks awesome and I just tried it out. Works great in Sublime Text 3, but doesnā€™t work in ST2. Maybe an excuse to finally upgrade up to ST3.

At one point I tried to create an auto-complete plugin for the BPY module (so it works like ctrl+space in the blender console). I didnā€™t have any luck with that at the time, have you done anything like that in Sublime Text? If this could also do hinting/auto-complete that would be amazing!

Ah great that it works from the first go ! :slight_smile:

Think ST2 runs on Python2 and ST3 runs on Python 3 for writing pluginā€™s ? (but can be wrong)
but the sublime plugin is quiet easy to setup so I will check out a ST2 version somewhere this week if you want.

ah the Auto-completion is a good idea to check out. Depends a bit how you have to populate a dropdown list in Sublime.
But you have any resources that already can point me in the good direction would be great!

PS : Hope you read the ā€˜bugsā€™ section in the documentation. The ā€˜blender.exeā€™ process will not shut down when you close blender. Since the SublimeBlender thread is not closed. So can be that it will block new connections.

As for the issue between st2 and st3, Iā€™m sure it is the python versions. The error is in the url ā€œrequestā€ module.
As far as autocomplete goes, the best I found was scraping the api web site here, but it didnā€™t seem like the best way to go about it:
http://www.blender.org/documentation/blender_python_api_2_69_release/genindex.html

As for the current plugin, so Iā€™m getting it to work for basic things. But I just created a quick panel for the toolbar and I can seem to get the script to run in blender. If I run it in blenders text editor it works (this just creates a simple button and panel in the toolbar), but if I run it via sublime it doesnā€™t.

Hereā€™s what I have right now thatā€™s causing the problem.

import bpy

class addLightViewPanel(bpy.types.Panel):
    bl_label = "LightView"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = 'objectmode'


    def draw(self, context):
        layout = self.layout
        row = self.layout.row()
        row.label(text="LightView")
        row.operator("object.lightview", text="Run!", icon="PLAY")


# Create Operator
class OBJECT_OT_makelight(bpy.types.Operator):
    bl_idname = "object.lightview"
    bl_label = "LightView"
    bl_description = "Create Light from current view"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self, context):
        scn = bpy.context.screen.scene
        scn.camera = coordcam
        viewcoords = coordcam.location
        print(coordcam)


obj = bpy.context.active_object
print(obj)
### Define Classes to register
classes = [addLightViewPanel, OBJECT_OT_makelight]


def register():
    for c in classes:
        bpy.utils.register_class(c)
    # bpy.types.WindowManager.curve_tracer = bpy.props.PointerProperty(type=TracerProperties)
def unregister():
    for c in classes:
        bpy.utils.unregister_class(c)
    # del bpy.types.WindowManager.curve_tracer
if __name__ == "__main__":
    register()

New features for Sublime Blender !

  • full auto-completion for the bpy module.
  • Auto save file when executing the script from Sublime.

Current Issues:
I am still looking into the correct way of executing the script in Blender, cause it is still doing crazy things.
example : execute ā€˜bpy.ops.mesh.primitive_cube_add()ā€™ : will create a cube but after that it jumps into edit mode. The problem is probably because the code runs in a different thread. I am still looking in to it. But if someone for different alternatives.

@crazycourier
You can see in my source code how to implement auto-completion in Sublime. I was able to plug the system in the default auto-completion system of Sublime. Really easy to do but it is not in the online documentation.
I still have to test your ui code that you gave but it is probably connected to the same problem given above.

@@crazycourier your code works fine if you comment bellow two lines

obj = bpy.context.active_object
print(obj)

Reason may be blender python dosenot allow may be because to prevent crash acceing it even after delete

@Svennovich for Sublime 3

But here everything works except auto complete, it dose work slow some time more oten it dosenot. But code runs smooth and connection works cool.

Help me if its working for you. It will just moke it lot more faster to blender scripting.

Yeah, it works for me as well, except autocomplete.

I try to test it on Lubuntu 12.10ā€¦ but dosenā€™t work

Addon in Blender, seems to work ok showing in the blender console:

Info: SublimeBlender Connection is open.

but sublime3 dosenā€™t do anything, not showing any errors on consoleā€¦
my sublime package is under packages, and the name of the path is ā€œBlender Developmentā€, i can reach settings and keymap files, but shortcut donā€™t do anything (crtl + E, or alt + P), with command palette (crtl + shft + P) dosenā€™t work, tooā€¦

Cool! But, can you make an autocomplete function for the Blender text editor?Im not good enough to make it, but your code suggests that you are on a pretty high level.It could be blessing for everyone, as, I suppose, I am not the only one who usees Blnederā€™s text editor much more than external editors! It would be awesome!

thanks so much for this, very handy! :slight_smile:

I just started coding for Blender and this is so helpful, thank a lot for this, works great.

This is superb! I use SublimeText 3 all of the time and now it will be much more enjoyable.

You totally filled a need. This is super great.:smiley:

Iā€™m glad I stopped by this forum! I just started using Sublime and I really like it, this will be a great addition to my toolbox!

Smart idea for an add-on! Thanks :slight_smile:

Anyone have this working with Sublime?

I know this is hella necro posting, but I found this thread in my own searching and figured I would chime in since I had some trouble getting it to work. Following the setup instructions on github, if youā€™re on windows, itā€™s likely not going to work right out of the box because the hotkey used to send the script to blender (alt+p) doesnā€™t workā€¦ itā€™ll just open the Project menu. You need to set or override a different hotkey in sublimeā€™s keymap files. So, as an example- my Default.sublime-keymap (user) looks like:

[
	{ 
        "keys": ["ctrl+e"], "command": "sublime_blender_execute",
    }
]

Additionally, autocomplete and linting doesnā€™t work out of the box either- youā€™ll need to download Python and add it to your PATH environment variable, and install the Anaconda package for sublime text (if you have package control enabled in sublime, just ā€œinstall packageā€ and ā€œanacondaā€).

Hope that helps some other future person who ran into the same speedbumps I hit!

1 Like

hi there, I just stumbled upon this after I bought sublime 3. any plans on updating this to blender 2.80 ?
I am trying myself, but since I am too new to python and blender, I canā€™t get it to work.
I am trying to follow this conversion tutorial https://www.youtube.com/watch?v=Mjy-zGG3Wk4.
I got it to show up in the addon manager but the command or the panel is not appearing in blender.

thanks

1 Like

I think itā€™s in the blender institute plan to support sublime, I heard it in last stream with Pablo

1 Like

Bumpity bump bumpā€¦

1 Like