Documentation‎ > ‎



Documentation on this page will help you get start with uPy. 
We provide several examples that can be found in uPy/examples.
uPy consists of three independent modules that can be used for scripts, scripts with dialogs, and plugins.
- modelling Helper :
- user interface adaptor :
- plugin adaptor :


Follow the instructions on the Download page.


Read these basics then look at the provided examples.

Getting started with the modeler module

This little snippet of code shows how to access uPy, and then create and color a simple primitive.

import sys

#uPy must be in the pythonpath, if not uncomment the next line to add it 
#pathtoupy = "/Users/ludo/DEV/upy/trunk/" 

import upy 
#get the helperClass for modeling 
helperClass = upy.getHelperClass() 
helper = helperClass() 
print (helper._usenumpy) #this verify if numpy is installed 
#if you dont want to use it, simply uncomment the next line 
#helper._usenumpy = False 

#your first geometry 
sphere,mesh_sphere = helper.Sphere("mySphere",radius=2.0) 
#change her color 
#red. you can access color alias using from upy import colors as col;

All the primitives supported are provided in the BasicGeom example. You can also review the API.


Getting started with the ui module

The UI module provides access to a class that builds graphic user interfaces with basic widgets. The following example demonstrates how to use uPy to display a dialog with simple buttons. This example can be found in upy/examples folder.

# -*- coding: utf-8 -*- """ Created on Wed Dec 29 13:09:18 2010 @author: Ludovic Autin """ #example for a script not a plugin .... import sys #pyubic have to be in the pythonpath, if not add it #pathtoupy = "/Users/ludo/DEV/" #sys.path.insert(0,pathtoupy) import upy upy.setUIClass() #this will automatically recognize the host and define the class uiadaptor #if this script is nt embeded or uPy dont recognize the host you can manually specify it:
upy.setUIClass("qt")from upy import uiadaptor #you can also directly import the one you want : #from pyubic.dejavuTk.tkUI import tkUIDialog as uiadaptor #from pyubic.blender.blenderUI import blenderUIDialog as uiadaptor

class simpleButtonsGUI(uiadaptor): def setup(self): self.initWidget(id=10) self.setupLayout() #theses two function are for c4d def CreateLayout(self): self._createLayout() return 1 def Command(self,*args): # print args self._command(args) return 1 def button1_cb(self,*args): #get the stat isCheck=self.getBool(self.CHECKBOXS["button1"]) print("button1 ", isCheck) # self.drawMessage("button1 "+str(isCheck)) def button2_cb(self,*args): #get the stat isCheck=self.getBool(self.CHECKBOXS["button2"]) print("button2 ", isCheck) def button3_cb(self,*args): #get the stat isCheck=self.getBool(self.CHECKBOXS["button3"]) print("button3 ", isCheck) def okButton(self,*args): print("ok") result= "" #overall state isCheck=self.getBool(self.CHECKBOXS["button1"]) result +="button1 "+str(isCheck)+"\n" isCheck=self.getBool(self.CHECKBOXS["button2"]) result +="button2 "+str(isCheck)+"\n" isCheck=self.getBool(self.CHECKBOXS["button3"]) result +="button3 "+str(isCheck)+"\n" self.drawMessage(title="myGuiResult",message=result) def quitButton(self,*args): answer = self.drawQuestion("Quit",question="Are You sure?") if answer : self.close() def initWidget(self,id=None): #this where we define the buttons self.CHECKBOXS ={ "button1":self._addElemt(id=id,name="button1",width=80,height=10, action=self.button1_cb,type="checkbox",icon=None, variable=self.addVariable("int",0)), "button2":self._addElemt(id=id+1,name="button2",width=80,height=10, action=self.button2_cb,type="checkbox",icon=None, variable=self.addVariable("int",0)), "button3":self._addElemt(id=id+2,name="button3",width=80,height=10, action=self.button3_cb,type="checkbox",icon=None, variable=self.addVariable("int",0)) } id = id + len(self.CHECKBOXS) self.PUSHS = {} self.PUSHS["OK"] = self._addElemt(id=id,name="OK",width=80,height=10, action=self.okButton,type="button",icon=None, variable=self.addVariable("int",0)) self.PUSHS["QUIT"] = self._addElemt(id=id+1,name="QUIT",width=80,height=10, action=self.quitButton,type="button",icon=None, variable=self.addVariable("int",0)) def setupLayout(self): #this where we define the Layout #this wil make three button on a row self._layout = [] self._layout.append([self.CHECKBOXS["button1"],self.CHECKBOXS["button2"],self.CHECKBOXS["button3"]]) self._layout.append([self.PUSHS["OK"],self.PUSHS["QUIT"]]) if == "tk": #from DejaVu import Viewer #vi = Viewer() #require a master try : import tkinter except : import Tkinter as tkinter root = tkinter.Tk() mygui = simpleButtonsGUI(master=root,title="buttonsUI") #mygui.display() elif == "qt": from PySide import QtGui app = QtGui.QApplication(sys.argv) mygui = simpleButtonsGUI(title="buttonsUI") else : mygui = simpleButtonsGUI(title="buttonsUI") #call it mygui.setup() mygui.display() if == "qt": app.exec_() ##execfile("/Users/ludo/DEV/pyubic/examples/")

Getting started with the plugin module

The Plugin module provides access to a class that help initialize and register new plugins to the host(s). This is the most recent module added to uPy and is not yet complete as of April 2012.... please check back often.

    >>> PLUGIN_ID = 1027431
    >>> import upy
    >>> plugTypeClass,operatorHostClass = upy.getPluginClass(plug="command")
    >>> class MyPlugin(plugTypeClass):
    >>>    plugin_name = "myPlugin"
    >>>    plugin_tooltip= "a general plugin"
    >>>    plugin_id =  PLUGIN_ID
    >>>    def runCommands(self):
    >>>        #put here what should do the plugin. i.e. open a dialog windows
    >>>        #or create some objects...       
    >>>        pass    
    >>>plug = MyPlugin()
    >>>if "__res__" in locals() :
    >>>    plug.register(MyPlugin,Object=plug,res=__res__)#add menuadd={"head":None} to add an access to the plugin in Blender
    >>>else :
    >>>    plug.register(MyPlugin,Object=plug)
    >>>#do no touch the following lines required by Blender and Maya    
    >>>#Blender Function
    >>>def register():
    >>>    print (__name__)
    >>>def unregister():
    >>>    pass
    >>>#Maya function
    >>>def initializePlugin(mobject):
    >>>    pass
    >>>def uninitializePlugin(mobject):
    >>>    pass