sidebar features
sidebar content

Go Back   Blender Artists Forums > General Forums > Python & Plugins

Closed Thread
 
Thread Tools
mthoenes's Avatar
mthoenes mthoenes is offline
Member
 
Join Date: Mar 2002
Posts: 403
For some time I have wanted to have a master script which called my favorite scripts which I frequently use. I have managed to produce something which will give me the result I want but not the flexibility I desire. The ScriptmasterGUI 1.0 actually includes the scripts it calls. I know there is a better way and I would appreciate some advice on what method would be best. Should I have the scripts to be read in from a folder. Can I load the scripts into Blender and call them from inside Blender? I would appreciate any examples that would help this be a useful script for others. So far this only includes Blender Virtual Undo and Blender knife Tool to show what I intend. This functions in 226 on Win2000. I have not tested in other versions or OS's.


http://home.att.net/~cs221/ScriptMasterGUI10.txt
............................................
BlendOn!
mthoenes

My Drawing Site: How to Draw and Paint Smart
My Blender Site: JumboSmart Blender Tutorials
#1   Old 26-Mar-03, 18:53   


marf's Avatar
marf marf is offline
Member
 
Join Date: Jul 2002
Location: wicklow ireland
Posts: 229
cool idea, one script to rule them all

i like it. is there no way it could load all the scripts in a folder?..
just thinking, the main script could become huge if they're all in it, or am i totally wrong?...

anyway cool thought
............................................
\"Half of the people can be part right all of the time, Some of the people can be all right part of the time. But all the people can\'t be alright all the time\"
#2   Old 26-Mar-03, 21:45   
theeth's Avatar
theeth theeth is offline
Administrator
 
Join Date: Oct 2001
Location: Montreal, Canada
Posts: 11,092
technically, if you use the import command on a script with a GUI, it starts the script normally.

however, I don't know if you could use that with another script that already has a gui.

I'll do some testing and see if that could be done.

Martin
............................................
Life is what happens to you when you're busy making other plans.
- John Lennon
#3   Old 26-Mar-03, 22:09   
JarellSmith JarellSmith is offline
Member
 
Join Date: May 2002
Location: California, USA
Posts: 692
I was wondering what advantages this technique would have over just loading your favorite scripts into Blender and then saving it as your default blend file, and then just selecting the script from the menu button as usual?
#4   Old 26-Mar-03, 22:15   
mthoenes's Avatar
mthoenes mthoenes is offline
Member
 
Join Date: Mar 2002
Posts: 403
JarrellSmith wrote:
Quote:
I was wondering what advantages this technique would have over just loading your favorite scripts into Blender and then saving it as your default blend file, and then just selecting the script from the menu button as usual?
The advantage for me is that I like the idea of just hitting a button. Some of these scripts really would be great additions to Blenders programming... It just feels more like part of the interfce this way. It is also a bit faster. The script may not be really necessary - just cool I think. One reason I may work all may favorites into one script is that i seem to loose track of what works where and with which version. I plan to add tool tips that tells which version of Blender they work in..Etc...
It would also be nice to carry one script around instead of 10. I know, you can save them into your default file, but hey, I am just learning python and I figured it was worth trying.

theeth wrote:


Quote:
however, I don't know if you could use that with another script that already has a gui.
I have been trying to figure it out. I am studying Makehuman. It has all sorts of files that are imported. So far I have not come to understand it. I get "no module named.... " errors etc.. If it can be done, I'll figure it out eventually, but i greatly appreciate the help. If it can't be done, that would be good to know - save me some time for sure.

I have learned so much from studying your scripts theeth - Many thanks - this is really fun.

marf wrote:
Quote:
am I totally wrong?
You are not wrong, it would get huge and a bit tough to manage. the kicker is I had to go through and put Tabs in front of all the lines of code when I made the def statements. What a pain.
............................................
BlendOn!
mthoenes

My Drawing Site: How to Draw and Paint Smart
My Blender Site: JumboSmart Blender Tutorials
#5   Old 26-Mar-03, 22:34   
mthoenes's Avatar
mthoenes mthoenes is offline
Member
 
Join Date: Mar 2002
Posts: 403
marf brings up an important issue
Quote:
one script to rule them all
Perhaps a better name for the final creation would be "Lord of the Scripts" Tee hee
............................................
BlendOn!
mthoenes

My Drawing Site: How to Draw and Paint Smart
My Blender Site: JumboSmart Blender Tutorials
#6   Old 26-Mar-03, 22:44   
theeth's Avatar
theeth theeth is offline
Administrator
 
Join Date: Oct 2001
Location: Montreal, Canada
Posts: 11,092
there you go!

Code:
############################################################# # # # The One Script # # # # (C) March 2003 Martin <theeth> Poirier # # Released under the Blender Artistic Licence (BAL) # # See www.blender.org # # # ############################################################# # History # # V: 0.0.0 - 26-03-03 - First draft of the script # # also first working version :) # # used a couple of Python hacks # # but it seems to works correctly # ############################################################# # # # One Script to use them all, One Script to find them # # One Script to bring them all and to the user binds them # # # ############################################################# # - - - - - - - CHANGE THIS LINE - - - - - - - - - # path = "c:/theeth/Blender/Python/Scripts/" import os, sys import Blender sList = [] nMenu = "" vMenu = Blender.Draw.Create(0) sys.path.append(path) def getList(): global path return [f[:f.index(".")] for f in os.listdir(path) if f and len(f) >= 4 and f[-2:] == "py" and f[-1] != "o" and f[-1] != "c"] def makeMenu(): global sList string = "Script%t" i = 0 for s in sList: string += "|" + s + "%x" + str(i) i += 1 return string def exit(): Blender.Draw.Register(pgui,pevent,pbevent) Blender.Draw.Exit = realExit def realExit(): pass sList = getList() nMenu = makeMenu() def pgui(): global nMenu, vMenu Blender.BGL.glClearColor(0.6, 0.6, 0.6, 0.0) Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT) Blender.Draw.Button("LOAD", 1, 10, 50, 70, 20) Blender.Draw.Button("EXIT", 3, 90, 50, 70, 20) vMenu = Blender.Draw.Menu(nMenu, 2, 10, 80, 150, 20, vMenu.val) def pevent(evt, mode): pass def pbevent(evt): global sList, vMenu, path if evt == 3: Blender.Draw.Exit() if evt == 1: mod = sList[vMenu.val] print "Loading " + mod + ".py" Blender.Draw.Exit = exit exec("import " + mod + " as module") gui, event, bevent = 0, 0, 0 if "gui" in dir(module): gui = module.gui if "draw" in dir(module): gui = module.draw if "event" in dir(module): event = module.event if "bevent" in dir(module): bevent = module.bevent if not gui or not event or not bevent: print "no gui functions found in " + mod exit return module.Blender.Draw.Register(gui, event, bevent) realExit = Blender.Draw.Exit Blender.Draw.Register(pgui,pevent,pbevent)
It assumes are your script are in the folder defined at the top.
It works with scripts with GUIs no need to modify them in any way.
I succesfully tested it with S68's Knife, the doc_browser script and my UV Export and Virtual Undo scripts.

Some other script might not work at first, but you just have to add one line in The One Script to fix that. It depends on whether or not the script uses standard names for the GUI functions.

still very early alpha though.

Martin
............................................
Life is what happens to you when you're busy making other plans.
- John Lennon
#7   Old 27-Mar-03, 01:41   
theeth's Avatar
theeth theeth is offline
Administrator
 
Join Date: Oct 2001
Location: Montreal, Canada
Posts: 11,092
I forgot to add:

- works both in 2.23 and 2.26 (although the scripts that are loaded might have other dependancies)
- if you exit the loaded script, it goes back to the script loader screen
- no interaction between different scripts (no residual variables).

if anyone is interested, I could probably continue working on that a little more.

Martin
............................................
Life is what happens to you when you're busy making other plans.
- John Lennon
#8   Old 27-Mar-03, 03:16   
mthoenes's Avatar
mthoenes mthoenes is offline
Member
 
Join Date: Mar 2002
Posts: 403
theeth,
Very nice. I tried a couple of scripts and just as you said, some would not load because of "no gui functions found". Nice work in any case. I will certainly find use for it. I think the script could be very useful.

Has anyone suggested a standard for scripts or some sort of common template for GUI setups. In trying to learn from looking at other scripts, I have found quite a variety in how people name things. I also wish everyone's header could state name, version, etc...Which version/versions of Blender it works with. Basic instructions on useage, etc. Oh well. that would be too easy and perhaps it goes against creativity. It would go along way towards compatability however. I have begun to add notes in the headers of the scripts I have download as to what version they work with, etc. I know the script list at the top of this forum attempts to do some of that organizing as well.

Your efforts are greatly appreciated. Thanks for taking time to expand on some of the ideas I have thrown out.

I have another question for you to ponder....

Can a script be used to give a KeyBoard or Mouse command to the active 3D Window. For instance, could you make a button in a script window that put the selected object into rotation mode by sending Blender an RKEY command or a button sending an RKEY - XKEY - XKEY local rotaion command.


Is it possible to have a python script
............................................
BlendOn!
mthoenes

My Drawing Site: How to Draw and Paint Smart
My Blender Site: JumboSmart Blender Tutorials
#9   Old 27-Mar-03, 13:43   
theeth's Avatar
theeth theeth is offline
Administrator
 
Join Date: Oct 2001
Location: Montreal, Canada
Posts: 11,092
Quote:
Originally Posted by mthoenes
Can a script be used to give a KeyBoard or Mouse command to the active 3D Window. For instance, could you make a button in a script window that put the selected object into rotation mode by sending Blender an RKEY command or a button sending an RKEY - XKEY - XKEY local rotaion command.
not through the Blender API anyway. I know there's a Python module to send keyboard or mouse event, but it's only for Windows.
Someone (sorry, can't remember who) already tried something like this, but it didn't work really well.

Martin
............................................
Life is what happens to you when you're busy making other plans.
- John Lennon
#10   Old 27-Mar-03, 13:54   
bmax bmax is offline
Member
 
Join Date: Mar 2002
Location: c:\recycled\
Posts: 3,128
hey, cool idea guys, and theeth, please continue working on this script!!
#11   Old 27-Mar-03, 16:02   
theeth's Avatar
theeth theeth is offline
Administrator
 
Join Date: Oct 2001
Location: Montreal, Canada
Posts: 11,092
second version, read the comments at the top for more info.

I'll post a proper .py file somewhere tomorrow, I understand some person are not too keen on the copy/paste method for script release.

Code:
############################################################# # # # The One Script # # # # (C) March 2003 Martin <theeth> Poirier # # Released under the Blender Artistic Licence (BAL) # # See www.blender.org # # # ############################################################# # History # # V: 0.0.0 - 26-03-03 - First draft of the script # # also first working version :) # # used a couple of Python hacks # # but it seems to works correctly # # V: 0.2.0 - 26-03-03 - Added some error handling # # modules that cannot import no # # longer crashes the script. # # # # Moreover, those script are also # # removed from the menu since they # # could have created some further # # headaches because of the import # # buffer. # # # # After doing some more testing, it # # seems that the imported script keep # # their variables (probably because # # of Blender's module buffer) # # That's good, since people will # # have no reason to complain about # # losing their settings when # # switching from one script to # # another back and forth. # ############################################################# # # # One Script to use them all, One Script to find them # # One Script to bring them all and to the user binds them # # # ############################################################# # - - - - - - - CHANGE THIS LINE - - - - - - - - - # path = "c:/theeth/Blender/Python/Scripts/" import os, sys import Blender sList = [] nMenu = "" vMenu = Blender.Draw.Create(0) sys.path.append(path) def getList(): global path return [f[:f.rindex(".")] for f in os.listdir(path) if f and len(f) >= 4 and f[-2:] == "py" and f[-1] != "o" and f[-1] != "c"] def makeMenu(): global sList string = "Script%t" i = 0 for s in sList: string += "|" + s + "%x" + str(i) i += 1 return string def exit(): Blender.Draw.Register(pgui,pevent,pbevent) Blender.Draw.Exit = realExit def realExit(): pass sList = getList() nMenu = makeMenu() def pgui(): global nMenu, vMenu Blender.BGL.glClearColor(0.6, 0.6, 0.6, 0.0) Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT) Blender.Draw.Button("LOAD", 1, 10, 50, 70, 20) Blender.Draw.Button("EXIT", 3, 90, 50, 70, 20) vMenu = Blender.Draw.Menu(nMenu, 2, 10, 80, 150, 20, vMenu.val) def pevent(evt, mode): pass def pbevent(evt): global sList, vMenu, path, nMenu if evt == 3: Blender.Draw.Exit() if evt == 1: mod = sList[vMenu.val] print "Loading " + mod + ".py" Blender.Draw.Exit = exit try: exec("import " + mod + " as module") except ImportError, err: print "\nCould not load " + mod + " due to the following error:" print "\n\t" + str(err) print "\n" + mod + " will no longer appear in the menu choices.\n\t(this affect this session only)" sList.remove(mod) nMenu = makeMenu() Blender.Draw.Exit = realExit return gui, event, bevent = 0, 0, 0 if "gui" in dir(module): gui = module.gui if "draw" in dir(module): gui = module.draw if "event" in dir(module): event = module.event if "bevent" in dir(module): bevent = module.bevent if not gui or not event or not bevent: print "no gui functions found in " + mod Blender.Draw.Exit = realExit return module.Blender.Draw.Register(gui, event, bevent) realExit = Blender.Draw.Exit Blender.Draw.Register(pgui,pevent,pbevent)
Martin
............................................
Life is what happens to you when you're busy making other plans.
- John Lennon
#12   Old 28-Mar-03, 00:18   
theeth's Avatar
theeth theeth is offline
Administrator
 
Join Date: Oct 2001
Location: Montreal, Canada
Posts: 11,092
http://www.clubinfo.bdeb.qc.ca/~theeth/TheOneScript.py

Martin
............................................
Life is what happens to you when you're busy making other plans.
- John Lennon
#13   Old 28-Mar-03, 18:48   
rndrdbrian's Avatar
rndrdbrian rndrdbrian is offline
Donating Member
 
Join Date: Dec 2001
Location: Scotland, UK
Posts: 1,108
Quote:
Originally Posted by theeth
http://www.clubinfo.bdeb.qc.ca/~theeth/TheOneScript.py

Martin

Excellent script Theeth!!!!!


Makes using multiple scripts a lot easier! And tidier too!

cheers

--
Brian
#14   Old 28-Mar-03, 19:05   
Manuel Manuel is offline
Member
 
Join Date: Mar 2002
Location: Italy
Posts: 626
Quote:
Originally Posted by mthoenes
I am studying Makehuman. It has all sorts of files that are imported. So far I have not come to understand it. I get "no module named.... " errors etc.. If it can be done, I'll figure it out eventually, but i greatly appreciate the help. If it can't be done, that would be good to know - save me some time for sure.
The next version of MakeHuman will become simpler; the module
imported are diminish, but MakeHuman aren't only a script: in the
scene must exist a basemesh.

You can solve the problem about module error putting
the classes (actually in the textbuffer of MH blender file) in the same path of your python installation...but...sorry, without the initial basemesh the script don't work...
#15   Old 30-Mar-03, 12:30   
Closed Thread

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 17:28.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Blender Headlines
Featured Artwork
Crocodile by Julia Korbut
Classic vintage look renders by HANGAR
Blending life - Old George by bigbad
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Social BlenderArtists