A Bit of Feedback
Now I finally got around to test your add-on. Scrolling through all your snippets, I'm really impressed with all the work you put into this.
I just have a few comments: In Blender UI the frist letter of each word is in caps, like this: Open Library Folder Save snippet could be a + icon. (should there also be a remove function(- icon)? Insert could be a paste icon, or a check mark, but I couldn't find any. Maybe all of the icons is that self explanatory that you could add all of the icons to the right with the arrows? Maybe Open Folder could go into the add-on properties? (If you got + and - you properly wouldn't have to open the folder?)
One really useful function would be to search inside the snippets by the name of a function and all the files containing that string would be visible among the snippets. That's properly very hard to implement, I guess? The hard part with an add on like this is to find what you're looking for. And a function-search operator would help.
Thank you for the feedback.
In Blender UI the frist letter of each word is in caps, like this: Open Library Folder
I know that button label should be titled, but I often forget to do it. Tx for the reminder, I'll do that.
Save snippet could be a + icon.
Agree
(should there also be a remove function(- icon)? Maybe Open Folder could go into the add-on properties? (If you got + and - you properly wouldn't have to open the folder?)
I will think about that. But I have to admit that I prefer doing operation of renaming/deleting/moving snippets direclty with the texts files. I chose this system (over my original json oriented approach) because I wanted it super EZ for people to do action on each snippets. like editing and sharing. That's why I did'nt want to add a delete button in the first place. Wanted to keep it simple and "OS explorer oriented".
In the same spirit I'll let "Open Folder" in the UI. I use it really often so I dont want to push it back to the prefs . For exemple usually when I add a snippets I open to sort it in the way I want. I know that since I use prefixes that can be automated, but maybe some other people would want to do otherwise.
Insert could be a paste icon, or a check mark, but I couldn't find any.
Yeah its not the best one. But could not find a better one and I'm used to it now ^^
Maybe all of the icons is that self explanatory that you could add all of the icons to the right with the arrows?
If you mean on the right side of the ui_list it's sounds good, I'll see what I can do.
One really useful function would be to search inside the snippets by the name of a function and all the files containing that string would be visible among the snippets. That's properly very hard to implement, I guess? The hard part with an add on like this is to find what you're looking for. And a function-search operator would help.
I totally agree with you about this. Thats why I try to make the titles of my own snips as explicit as I can, so I can use the built-in UI list search bar efficiently. I already thought about some way to have an inside-snippet'search but as you said it's kind of hard to do. With my current knowledge of searching techniques it would surely be slow and clumsy. Maybe by manually generating an index file of the functions with an additional button, but I'm not sure I can do a user friendly UX/UI with this method... so for now thats a standby for this feature.
One thing I want to implement first is the ability to filter by specific categories/types/user-defined-filter with a tag system. For example now more than ever we need to be able to filter snippet by blender version compatibility. I have a somewhat clear idea of how to achieve this but again, I'm afraid that it may add too much complexity both to UI and UX. And it will alterate the simplicity of the text files themselves that I like, since the best way I found is by adding a dic at the start of each snippets to gather these information and make it readable/editable both by python and by the user... But I'll definitely do this to at least avoid version conflict, that's starting to bother me.
Another thing I would really like to achieve is to make it easier to share ! Like having an online shared snippet repository where the addon can read/write so it can be fed realtime by the dev community ! That's on a whole other level but would be so awesome...
Once I go back from holidays I'll see to all of this. (when times allow that is.) ;)
I played around with the idea of a text preview of the template header, maybe you'll find that interesting?
https://blenderartists.org/uploads/default/original/4X/7/8/9/78952dba5b95b4f582b376fb2feadb17fde09373.gif
For me the biggest problem with using templates is that the titles doesn't describe what I need to know. Ex. if I'm looking for a UI solution, a template(the build in ones) might actually use it, but is actually showcasing something else, and therefore I'll not be able to find it by looking at their names. Also with the removal of the left tools sidebar most template UIs are not easy to find for newcomers, so having a text preview, the location could be exposed.
Interesting indeed. Thats a nice way to do it ! Not so long ago I thinked about running a modal operator to display an openGL preview overlay over the text area (this way you dont have to extend the compressed toolbar to see clearly the preview). But running a modal for just the text editor snippets seemed a bit overkill to me (though I still want to try it some days)...
Feel free to pull request some change if you already did the code. Or send me a template snippet of your template preview so I can add it later ! 😉
Ok there is a new version for you to try ! Mostly cosmetic change but that's a big improvement on the UI side thanks to your feedback. 👍 Now I'm thinking of a tag system to filter the snippets.
For the header preview can you send me your testing code so I can save some time ?
Currently it doesn't seem to install properly(it doesn't show up among the installed add ons?). In the bl_info there is a whitespace line, and that gives an error, but still when removing that, it doesn't work here?
It was just a mock up with a label pr. line(copy + pasted) and a .box added to the column.
Ok ! sorry for that, I commited the wrong file. I just started using vscode's blender dev plugin from Jacque. L. I understand how it works now. Strange though... I corrected that single line and its working good for me. Can you try redownload it ?
Ok for the preview, I didn't understand that it was a mockup. thx
Yes, now it opens. I had to refresh the list to get entries in the list on first run, maybe it should do this automatic?
Maybe you could consider making a new text block when adding a snippet to the Text Editor, and call it the name of the snippet. Currently it is overwriting whatever is in the text block called 'Text'. Users may loose work this way.
I asked for adding a checkmark to the Blender icon set, if this is added, it might be a better icon than the arrow.
I really like the search function, if possible maybe to could be open on default?
Ah, next update there will be a checkmark included: https://devtalk.blender.org/t/new-icons-for-blender-2-8x/4651/716
Yes, now it opens. I had to refresh the list to get entries in the list on first run, maybe it should do this automatic?
I tried to do this just now. I added a call of the reload function in the register. But the problem is that when you hit the checkbox to enable the addon it's in the context of the preferences (I can't access bpy.context.scene). So it give an error... I'll check if there is a workaround later.
Maybe you could consider making a new text block when adding a snippet to the Text Editor, and call it the name of the snippet. Currently it is overwriting whatever is in the text block called 'Text'. Users may loose work this way.
It supposed to work the way you say. It's the case for me... it's never overwriting an existing text block. maybe we are not talking about the same thing or I misunderstood. Can you send an exemple ?
Since the last two published version, if no text block is loaded, it will create a new one with the name of the snippet (just as you just asked ) ! This is the only moment when the script is really "creating" a text datablock.
I asked for adding a checkmark to the Blender icon set, if this is added, it might be a better icon than the arrow. Ah, next update there will be a checkmark included
Cool ! Do you know if in the code I can check if an icon exists ? (to avoid error and replacing with old icon for people who haven't update blender)
I really like the search function, if possible maybe to could be open on default?
Totally agree, I use this search all the time. looking a bit on the web it's possible with self.use_filter_show = True, (found here) It will be in the next version.
Ok preview is live ! \o/
But the spacing gap between line label is too big. I dont know how setup something better (not so good in UI tweaking code...) I did as follow:
if bpy.context.scene.sniptool_preview:
# box.prop(scn, 'sniptool_preview', text='')# '\n' not recognised, split in multiple labels
box = layout.box()
for l in bpy.context.scene.sniptool_preview.split('\n'):
box.label(text=l)
@tin2tin Tell me If you know a better way
Maybe placing something like this before the loop will do the trick: box = box(align=True)
Maybe using box also may add additional spacing?
Not at computer right now, so I can't check.
This is as tight as possible(without box):
if bpy.context.scene.sniptool_preview:
# box.prop(scn, 'sniptool_preview', text='')# '\n' not recognised, split in multiple labels
col = layout.column(align=True)
for l in bpy.context.scene.sniptool_preview.split('\n'):
col.label(text=l)
But that's without the box.
Do you know about this snippet collection? https://github.com/zeffii/BlenderPythonRecipes/wiki
The build in templates are called like this:
bpy.utils.script_paths("templates_py"),
So maybe templates_py a predefined path, so maybe you can grab them too?
Maybe there should be two insert functions one in a new document and one pasting into the current document(paste icon)?
On the new icon, maybe a try and catch could be used?
This is as tight as possible(without box)
I think I'll let the box for now and see later how can I do better (at least the UI is nice that way).
Maybe there should be two insert functions one in a new document and one pasting into the current document(paste icon)?
I'm not sure about having two buttons. it's fairly simple to make a new block with a clic or alt+N and from the beginning the snippets aimed at being tiny piece of code that you insert in your scripts, not really there to load full-fledged scripts/addons so I'll stick with only the insert.
On the new icon, maybe a try and catch could be used?
Yeah right, I wondered if existed som specific 'get' method but a good'old try block will be fine.
The build in templates are called like this [...]so maybe you can grab them too ?
I thought of integrating the build-in template (just to be able to reach them with the search really) but I in the end it would be redundant to have them at both location. It's kind of good to have your own snippets (or community) separated from the shipped ones.
Do you know about this snippet collection?
I knew of zeffi x_templates and once a sort of tag/category filters is up I might add these. Before adding snippets that aren't mine I need to find a good way to sort all of this and mixing everything is difficult.
But be wary, I'm sort of a slow developer... This might take a while. And thus today was dedicated to the snippetLib, I have a lot of other project to work on ^^. (as anyone 😄 )
Thanks for all the proposals. Keeped me motivated.
The Templates implementation is pretty bad as it is now(that mega long menu), so maybe your add-on could replace it? Or be included in Blender as a much more comprehensive snippet lib.?
You think it can go in ? I always think I use too many hacky tricks in my code to be ever included.
The next I wanted to do is modify the snippets themselves by adding versions/tag/description/stuff with a dic at the header of each one. This header would be evaluated in python during the scan, and generated with the add popup when you create a new one. Something pretty much like this :
info = {
'icon' : 'OUTLINER_OB_EMPTY', #optionally the user can choose an icon instead of the default one
'description' : 'Add empty at object location', #description (displayed like a tooltip)
'tags' : ['object', 'translation', '2.8+',] #every new tag would add a checkbox in another UI list dedicated to filtering snippets of the first UI list.
'version' : '2.80' #merged in the tags ? it's kind of one...
}
Here is were the real snippets starts
blablabla...
(Do you have comment about this btw)
BUT, replacing the current Template system or going alongside it means I'll certainly will have to stick with plain snippets (like it is now) since template_py are also plain. So the categorization filter would be only folder based (like zeffii did with his menu/submenus)... The build-in template are only few but with a lot of snippets I dont know if this filter only will be ok. :s
Here goes the dilemmas
To be able to search the contents and functions of the snippets could be very useful, but it'll complicate things and may be a lot of work.
The preview idea was mainly for reading a commented text block at the start of a script(which would have to be added to each snippet), but if you add info headers maybe the preview is not needed, because the exposing the info would be sufficient preview?
The build in templates could also be updated to comply to whatever styles you find right, but of course the Blender Devs would have to be convinced first.
I think the optimal snippet solution would be to connect the API docs with snippets showcasing all the functions, so if you want to add info, maybe the api functions could be harvested from the snippet and added to the info, so snippets somehow could be linked to the api documentation. I don't know how to do that, but I this it could be a great way for people learn coding Blender Python.
To be able to search the contents and functions of the snippets could be very useful, but it'll complicate things and may be a lot of work.
I see a rather simple way to make it, but it will be a somewhat slow search (but not too slow either) that will rely on scanning every snippets at each search call. So that mean a lot of read on disk... But heh ! if the user find his stuff, no cost too great ! Will run some test and if it seems ok I'll add it
The preview idea was mainly for reading a commented text block at the start of a script(which would have to be added to each snippet), but if you add info headers maybe the preview is not needed, because the exposing the info would be sufficient preview?
After thinking hard (5 long minutes 😲 ) I decided to stay with plain snippets, if only for the sake of simplicity. And for the limited time I can spare working on this addon.
The build in templates could also be updated to comply to whatever styles you find right, but of course the Blender Devs would have to be convinced first.
About this, it might be better to stick with plain text too, I dont think the devs will be convinced by a script that evaluate string to python execution from an external file for security reason (but maybe I'm wrong)
I think the optimal snippet solution would be to connect the API docs with snippets showcasing all the functions, so if you want to add info, maybe the api functions could be harvested from the snippet and added to the info, so snippets somehow could be linked to the api documentation. I don't know how to do that, but I this it could be a great way for people learn coding Blender Python.
Sound too complex for me to handle 😅
By the way there was a new version yesterday evening. I think you'll like the new feature. The preview now display the definition/classes (if any) in another box below.
I wanted also to scan the build-in snippet (as you proposed) while adding a checkbox on preferences to disable this source. BUT it's incompatible with my current design that is made for specifically targetting one library folder only.
If I make the library multi-folder it add a level of complexity (and not only on the code level). For exemple when you add a new snippets you will have to choose where to send it. Same when you open lib folder, does-it open all folder ?(a bit messy) or again a choice popup ?... + certainly other problems I didnt think about (like handling file conflict for example).
So again it kind of break the simplicity of the plugin that I like... The built-in template can just be moved to the snippets lib folder and it will work perfectly fine.
Since it can be really usefull to have multiple source anyway, I just put the idea on standby for later.
Cool with the classes/defs extracts.
If the snippets are always pasted into the current document, maybe the paste icon should be used instead of the arrow?
Big new update. You will certainly like it !
Here is the changelog of this v0.2.0 (always updated on the readme btw):
- New feature : Search in content (search in content and filename). act like reload with a filtering when populating the list
- New snippet standalone add mode (instead of inserting in current text, create a new text block)
- New option in user preferences : Choose max line number for preview (default 10)
- New option in user preferences : When auto-creating a new textblock choose wich text editor option to toggle on.
- Better tooltips
Wow that's super cool!
A couple of small things I noticed: In the Preferences, in 2.81 everything is right aligned and starting with a capital letter(eg. Show). 'Preview line number' should maybe be 'Preview number of lines'.
Insert in new document, maybe use the New File icon eg. document with +? (Using the copy icon in the text editor header is a bug)
Maybe the new search function could suggest selected text in the search field when opening the popup?
I'm not sure about this, but maybe it is easier for users to navigate the snippets if ex. bpy_ is added to the end of the filenames instead of the beginning - so you could still use them for searching, but the actual function would be the first you'll read?
Maybe you could ask on https://blender.chat/channel/python if there is a solution which will load the files in the list at start up?
A couple of small things I noticed: In the Preferences, in 2.81 everything is right aligned and starting with a capital letter(eg. Show). 'Preview line number' should maybe be 'Preview number of lines'.
Done. I didn't know of this new layout.use_property_split = True
The labels staying on the left side feels slightly odd but this is definitely better.
Insert in new document, maybe use the New File icon eg. document with +? (Using the copy icon in the text editor header is a bug)
Done. Didn't realised it was weird ahah (the duplicate made sense too in a way)
Maybe the new search function could suggest selected text in the search field when opening the popup?
Wow ! I super like this idea 👍 ! Done. (only if the selection does not go over one line)
I'm not sure about this, but maybe it is easier for users to navigate the snippets if ex. bpy_ is added to the end of the filenames instead of the beginning - so you could still use them for searching, but the actual function would be the first you'll read?
About that, I dont really want to change it since it's just sort of a naming rule I made for myself. I only did this to have a quick idea of the "type" but also to sort them (both in OS and in the UI list), going with a suffix will disable this sorting in both. But that's fine, other users can name otherwise as they like (and definitely will). And ultimately, it may just be useless to have this. I may just drop it to stay simple and avoid inconsistency with other users snippets.
Maybe you could ask on https://blender.chat/channel/python if there is a solution which will load the files in the list at start up?
Since this is not super important, this is where my lazyness come in ! 😸 I start feeling like an hermit working on this ahah. maybe later.
Cool! I can't come up with anything more, except you could run a pep8 check. If vscode doesn't have it, maybe you could use this one: http://pep8online.com/
Looking at it again. You're right, it is better to left align the preferences.
Maybe the list widget should have a default height which fits the height of the icons?
Opening the Sidebar:

Refreshing the list:

Having the Preview button selected, it is pretty dominant, maybe it could just be an icon button below the folder open button?
Maybe double clicking a list item should paste it into the current text?
Renaming, by double clicking snippet name, makes the file unreachable.
Ahah ! I knew you were going to go back with some other changes in mind.
Looking at it again. You're right, it is better to left align the preferences.
All right, I take your word for it, dont mind it being left or right.
Maybe the list widget should have a default height which fits the height of the icons?
True, but I dont know how to do that ^^. Will see if its possible
Having the Preview button selected, it is pretty dominant, maybe it could just be an icon button below the folder open button?
Though I agree it may be currently a bit too big, I like the way it serve as a clear separator/indicator. I tried a few different things for this part of the UI already, but did not test putting it in the side-icons... I'll give it a shot.
Maybe double clicking a list item should paste it into the current text?
I want that too. Not sure if it's possible to trigger it with a double clic (I think the rename action is part of the UIlist core design). I'll check this anyway but my hope aren't that high...
Already tried something towards this idea of quick insert. At some point I got it working so just single clic on it would paste (but it wasn't relying on clicking event, and it's not something we want now with the preview).
Renaming, by double clicking snippet name, makes the file unreachable.
Yeah, if you want to rename you need to go in the folder library and rename the file itself then hit the reload. From the start it's up with this OS-based approach. I know it's not perfect but it greatly simplify things. Nevertheless, I wondered if I should sync the rename on list with the actual file on disk, But it's complicated (maybe not even possible without super tricky hacks...) so I prefer not to.
In the end the double clic to insert would definitely be a good thing, it will be a new cool feature that fix a bad UX in one shot !
I wasn't sleepy while you were blending stuff and gathering toughts ! There is a new feature prepared over the weekend, Check the changelog ;)
One sad thing though : after a lot of trial and sweat yesterday, I failed miserably trying to implement a TabTrigger system in Blender when inserting snippet. Placing/moving the cursor with the API is just an absolute pain ! I'm not sure to add this feature in the end... Already lost way too much time just for this that I consider a bonus. But I think it's cool that we can now write the syntax in the snippets and enjoy it after conversion on external editor. Btw what editor do you use ? where are you from ? what is your main use of blender ? so many question all of a sudden 😄.
I'm not using any external editor(only Notepad++ once in a while). I know I should, but I'm mostly doing Blender UI work, and it is so much faster to do this from within Blender Text Editor. (I know some people using Emacs and Vim for coding Blender add-ons too)
Generally I just think that the Text Editor has been falling far behind, and do need a lot of love to reach the level of the rest of Blender and therefore I did this thread on Blenderartists to gain some traction for the Text Editor: https://blenderartists.org/t/how-would-you-show-some-love-for-the-blender-text-editor/
The better and more friendly the Text Editor seems, the more add-on devs will start coding for Blender(and eventually they'll move to other IDEs), which is a good thing imo. And therefore I think a good snippets/templates system is crucial.
Here is the new version. I made all the change except for the double-click-insert on item, did not found a way to do it... But as a fix I disabled the rename on double click (just had to make items labels instead of props)
The UI is better now than ever before ;)
Also added a 'Todo' and 'ideas considered' in the readme. Here is the change log.
v0.2.3 2019-09-05:
- Converting a snippets without prefix now use containing folder name as trigger keyword. (instead of "bsnip") thinking about making it the default in the future...
- UI fix : The list as now a default minimum size that match the right icons space.
- UI fix : List item are no longer renamable with double click does nothing, this avoid bad UX and losing track of the snippets file
- UI new : Preview toggle button is now part of the right side buttons.
Excellent! Maybe it deserves a tab with the "Snippets" name, now it uses the full tab?
Maybe you can make a post about it here(so people will know that there still are good things going on with the Text Editor)? https://blenderartists.org/t/how-would-you-show-some-love-for-the-blender-text-editor/1163857/89
I can post about it on Twitter, if you're not on Twitter?
Since it's for coding purpose the dev tab seemed like the right choice. But with the preview and all taking that much space I agree its a good idea to have a dedicated tab. Will do it in the next update ;)
About sharing it, I had planned to post it on the BA thread you mentionned (and eventually on my twitter). But before I want to do 2 things :
-
The number one of my todo : Changing the code so I does not affect user's paperclip. I already knew that was considered sort of a bad hack (even before Campbell mentionned it) and at the same time it is so much simple to use this rather than the rest of the API... but there is no way it will ever be included in blender as it is and tempering with clipboard is clearly no good. So I will try to make it work clean.
-
Second : I want to make numerous changes on my personal library that is shipped with it. Since these snippets are already there, they should be an exemple of good naming convention for the user to make their own snippet. But now that I made the converter and used some snippets in vscode and sublime, it's clear that some of my prefix name aren't that clear and my folder structure is not used as its best.
There is more to it on this second todo. I dont know if I completely drop the idea of a prefix and use instead the name of the folder there are being stored in.
This way you have a clean file name (compatible with old templates, good point) and not think that much about "categorizing" when adding a new snippets. Changing the category afterward would be as simple as moving the snippet into another folder. The addon is still able to detect something to be use as a prefix with the folder structure alone. And not classifying it would automatically fall in the "snippets" category (or maybe bpy by defaut).
The other way is keeping things as they are. Which does not rely on folder structure. Actually now it use both. If no prefix is given, the folder name is used when using the converter. Not so bad all things considered. The one thing I super like about this current method is that you can have a same "category" (prefix) within different folders. That means you can have your own snippets or specific project snippets in another folder but not mixed (lost) within "standard" library or any other people snippets. In other words it lets you organise the library with more flexibility. Moreover for multiple user working with the same source folder on network where the can create a User folder and still categorize it properly inside...
I think there is a choice to make bout this (I'm not so good with choices ... doubt being a dear friend of mine ^^)
In any cases I think about going with more detailed name. For exemple I used sometimes def_ as prefix just to say these were containing methods, not interesting infos on the snippet itself...
My current categories are :
bpy : blender python (this is kind of an all or uncategorized category but not completely though)
py : pure pyhon operation that work out of the blender scope
def : will delete this one, with time passing i added def on many other prefixed snippets
dev : directly related with developpement, like getting addon preferences etc.
regex : this category is relevant, will keep it as it is
rig : rigging stuff, good category event if its kind off
and thats about it.
I won't go too detailed either. Because with trigger words in IDE you'll have to remenber as many keywords as there are category... Always trying to keep name short to avoid taking screen space when displayed in UI list and used as trigger keyword.
Maybe something relative to the areas (or scope of action) like :
bpy, py, regex, rig : still good
mat or shader : for scripting related to shader/material...
node : node-tree things
obj : whenever the snippets affect objects in the 3D viewport
mesh : when using bmesh module and other edit mode stuff
ui : panel template and such
gp : grease pencil python (will do this one anyway)
_ops or operator ? : Considering the default templates, there would be an operator exemples category
batch ? : batching stuff. This is tricky, since it can be in many other category (for exemple batch export object can be in obj etc... this is why I wanted to add a tag system but it will overcomplexify things so let be only one tag.
...
This might already be to much category to memorize triggers. Maybe grouping all viewport related stuff under bpy is still good... I think a lot with the converter in mind because I see a lot of potential with this. Sadly you can have only one keyword trigger in those IDEs and only vscode let you "elastic search" in the result after tapping the trigger (that is super cool btw).
I want your opinion. What do you think of all this ? what organisation would you prefer to use ? folder or name prefix like now ? I suppose you used it a bit already, how have you entered and categorized your own new snippets ? have you got any category or sorting in mind ?
Of course the user can decide himself for his own method of sorting and will add more category anyway (still more flexible for him if folder are not used as tag).
Also maybe I'm overthinking things... that will not be a first 😄.
Will think about it while fixing the clipboard.