Boujou Import Script in Blender 2.53 not working?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

SuperOmegaSlacker
Posts: 1
Joined: Tue Aug 10, 2010 2:31 pm

Boujou Import Script in Blender 2.53 not working?

Postby SuperOmegaSlacker » Tue Aug 10, 2010 2:42 pm

Hi,

I have just started using blender, converting from 3DS Max. I am running Blender 2.53 on my Macbook Pro 10.6 and am having difficulty with the Boujou import script. I have installed the script using File > User Preferences > Add-Ons > Install Add-On, which seems to go through without errors. When I go to File > Import, I don't see the option to import the txt file.

I also tried open the script in the text editor and running it that way but I get the following error:
File "/boujou_import.py", line 55
print '__________________'
SyntaxError: invalid syntax
Python script fail, look in the console for now...

I go to the console and paste the script in and get tons of syntax errors... I have no idea where to go form here... I really like the 2.5 interface better than the official version 2.49 and would like to stick with it as I am still learning. Is this script incompatible?

stiv
Posts: 3646
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Postby stiv » Wed Aug 11, 2010 1:14 am

Scripts need to be ported from old Blender (2.49 and older) to new Blender (2.50+).

Old Blender uses Python 2.x, new Blender uses Python 3.x. One of the differences between Python versions is that print is now a function rather than a statement.

Old: print 'foo'
New: print('foo')

In addition, Blender 2.50 has a new Python scripting API which means the Blender specific commands have changed.

Stefano Comba
Posts: 5
Joined: Sat Feb 12, 2011 4:27 pm

maybe this work... maybe not

Postby Stefano Comba » Sat Feb 12, 2011 4:43 pm

Hi,
i've found boujou script for Blender 2.4x. Unfortunately doesn't work with the last version 2.5. So i've tried to convert the script using new API.

This is the result:

Code: Select all

# Simple script used for importing camera tracking data generated by BouJou4
# BouJou4 will not export to Blender, though it will export to a text file.
# This script will read that file.
# Mon 15 Oct 2007 - Simon Beeching (enhzflep)


#import Blender;
#from Blender import Camera, Object, Scene, NMesh
#from Blender import Mathutils
#from Blender.Mathutils import *

import bpy;
from bpy import *;

print ('-------------------------------------------------------')
print ('------------- BouJou4 import script v0.0 --------------')
print ('-------------------------------------------------------')



# declaration of function used to load the file
def myLoader(fileName):

    file = open(fileName, 'r');
    i = 1;
    readVerts = False;
    readCam = False;
    numFrames = 0;

    for curLine in file.readlines():
        # check for correct file header.
        # if it's not found, print an error and exit
        if (i==1) and ('boujou export' not in curLine):
            print ('ERROR: incorrect file header.')
            print ('line #: '+str(i))
            print (' - expecting "# boujou export: text"');
            print (' - found "'+curLine+'"');
            file.close();
            break;
   
   
    ################################################################################
    #
    #  Camera loading code
    #
    ################################################################################
   
        # if we find the string that signifies the end of the file,
        # change our flag to false - we can't read nothing!!
        if (readCam == True):
            coOrds = curLine.split()
            if  (len(coOrds) == 0):
                readCam = False;
                print('('+str(i)+'): Found end of camera block');
                allObj = Object.Get()
                for curObj in allObj:

                    if curObj.name[:10]=='boujou_tmp':
                        cur.unlink(curObj);

   
        # CAMERA FRAME DATA FOUND!!
            else:
                # set the camera rotation/translation matrix
                rX = [float(coOrds[0]), float(coOrds[1]), float(coOrds[2]), 0.0];
                rY = [float(coOrds[3]), float(coOrds[4]), float(coOrds[5]), 0.0];
                rZ = [float(coOrds[6]), float(coOrds[7]), float(coOrds[8]), 0.0];
                tR = [float(coOrds[9]), float(coOrds[11])*-1.0, float(coOrds[10]), 1.0];
                tmpObj.setMatrix(Mathutils.Matrix(rX, rY, rZ, tR));
               
                # set the lens
                tmpCam.lens = float(coOrds[12]);
               
                # add point(keyframe) for camera position IPOs
                locx.addBezier((numFrames+1, tmpObj.LocX))
                locy.addBezier((numFrames+1, tmpObj.LocY))
                locz.addBezier((numFrames+1, tmpObj.LocZ))
   
                # add point(keyframe) for the camera rotation IPOs
                rotx.addBezier((numFrames+1, (tmpObj.RotX*18/3.141593)-9))
                roty.addBezier((numFrames+1, -1.0*tmpObj.RotZ*18/3.141593))
                rotz.addBezier((numFrames+1, 1.0*tmpObj.RotY*18/3.141593))

                # add point on IPO curve for lens (focal distance)
                lenscurve.addBezier((numFrames+1, tmpCam.lens))
                                       
                # increment the index used for setting IPOs to point to next frame
                numFrames += 1;
   
        # CAMERA BLOCK FOUND!!
        # if '#R(0,0)' is found, then we have the start of the vertex data
        if ('#R(0,0)' in curLine):
            print( '(' +str(i) +'): Camera data found in export file');
            readCam = True;            # set flag to indicate we're in a camera block
            cRend = Camera.New('persp');
            cRend.lens = 35.0
            cRend.setDrawSize(1.0);
            oRend = Object.New('Camera');
            oRend.name = 'BouJou_Cam'
            oRend.link(cRend);
            cur = Scene.GetCurrent();
            cur.link(oRend);
            cur.setCurrentCamera(oRend);
            ipo = Blender.Ipo.New('Object', 'render_cam_objipo');
            oRend.setIpo(ipo);
           
            # create the ipo curves that we'll be needing
            locx = ipo.addCurve('LocX')
            locx.setInterpolation('Linear')
            locy = ipo.addCurve('LocY')
            locy.setInterpolation('Linear')
            locz = ipo.addCurve('LocZ')
            locz.setInterpolation('Linear')
            rotx = ipo.addCurve('RotX')
            rotx.setInterpolation('Linear')
            roty = ipo.addCurve('RotY')
            roty.setInterpolation('Linear')
            rotz = ipo.addCurve('RotZ')
            rotz.setInterpolation('Linear')
            camipo = Blender.Ipo.New('Camera','render_cam_camipo')
            cRend.setIpo(camipo)
            lenscurve = camipo.addCurve('Lens')
            lenscurve.setInterpolation('Linear')
   
            # create the temporary camera that is used to convert our camera matrix
            # into rotation and translation figures. This dummy camera also holds the
            # lens info. This temp camera is needed to create the IPO curves
            tmpCam = Camera.New('persp');
            tmpCam.lens = 35.0;
            tmpObj = Object.New('Camera');
            tmpObj.name = 'boujou_tmp'
            tmpObj.link(tmpCam);
            cur.link(tmpObj);



        ################################################################################
        #
        #  Vertex loading code
        #
        ################################################################################
        # if we find the string that signifies the end of the file,
        # change our flag to false - there's nothing left to read
        if ('#End of boujou export file' in curLine):
            print( '(' +str(i) +'): Found end of boujou export file');
            readVerts = False;
            mesh.update()
            cur.update()

        # if we're currently allowed to read vertex positions, then
        # split the line up into individual 'words' - putting the first 3
        # into a 3 element array used to hold 1 point
        if (readVerts==True):
            coOrds = curLine.split();
            if len(coOrds):
                x = float(coOrds[0]);
                y = float(coOrds[1]);
                z = float(coOrds[2]);
                v = NMesh.Vert(x, -z, y)
                mesh.verts.append(v);
   
        # if '#x y z' is found, then we have the start of the vertex data
        # (the x, y and x are all separated with tab characters (\t))
        if ('#x\ty\tz' in curLine):
            readVerts = True;

            ob = Object.New('Mesh', 'BouJouData')
            ob.setLocation(0.0, 0.0, 0.0)
            mesh = ob.getData();
            cur = Scene.getCurrent()
            cur.link(ob)

            print( '(' +str(i) +'): Vertex data found in export file');
        ##########################################################################

        # increment the file's line counter
        i += 1;
        ########### End of loop performed on each lie of the file ################
       
    print ('Total of '+str(numFrames)+' frames tracked.');
    file.close();
    ##################### End of myLoader(filename) ##############################
   
   
# Script starts execution here
# call function myLoader with the file chosen in a file open dialog
# use the string "Import  .txt" on the button
Blender.Window.FileSelector(myLoader, "Import .txt");


The problem is: i haven't found in the documentation an alternative to the last line

Code: Select all

Blender.Window.FileSelector(myLoader, "Import .txt");


Anyone could help me?

I think that maybe this is the only problem in this script and after that maybe it works!!

Thanks

batFINGER
Posts: 33
Joined: Wed Jan 23, 2008 4:33 pm

Postby batFINGER » Sat Feb 12, 2011 6:43 pm

Hi

here is a simple script with a panel and an operator that selects a file from the fille browser window... it's pretty self explanatory...

Can i suggest you get a more recent build as a few things in the API keep changing.

Code: Select all


import bpy,os
from io_utils import ImportHelper

def main(context,self):
   
   directory, file = os.path.split(self.filepath)
   print("Directory:"+directory)
   print("File:     "+file)


class OBJECT_PT_hello(bpy.types.Panel):
    bl_label = "Hello World Panel"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Import File", icon='WORLD_DATA')

        row = layout.row()
        row.operator(SimpleOperator.bl_idname)

       
       
class SimpleOperator(bpy.types.Operator, ImportHelper):
    '''Tooltip'''
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
     
    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def draw(self,context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Import File in FileBrowser", icon='WORLD_DATA')
       
   
    def execute(self, context):
        main(context,self)
        return {'FINISHED'}
     
    def invoke(self,context,event):

        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}   

def BoujouImport(self, context):
    self.layout.operator(SimpleOperator.bl_idname, text="Bojou Import", icon='PLUGIN')
   
def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.utils.register_class(OBJECT_PT_hello)
    bpy.types.INFO_MT_file_import.append(BoujouImport)
   


def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    bpy.utils.unregister_class(OBJECT_PT_hello)
    bpy.types.INFO_MT_file_import.remove(BoujouImport)

if __name__ == "__main__":
    register()

    # test call
   # bpy.ops.object.simple_operator()



Run the script from the script window.. then press the button in the hello world panel that shows up in the object property panel. This is purely a quick sample from the templates.. I also put in the code to make it an import menu item.

Stefano Comba
Posts: 5
Joined: Sat Feb 12, 2011 4:27 pm

Postby Stefano Comba » Sat Feb 12, 2011 7:45 pm

Thank you for your quick reply! I've run script but Blender said me there is an error.

Line 61:
bpy.utils.register_class(SimpleOperator)

Attribute error: 'module' object has no attribute 'register_class'
location: <Unknown location>:-1

Do you have any idea? I don't undestand... maybe it's my fault!

I think that i've the latest beta 2.5x but i'll check to be sure.

stiv
Posts: 3646
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Postby stiv » Sun Feb 13, 2011 12:38 am

Do you have any idea? I don't undestand... maybe it's my fault!


More likely recent API changes. The register code has been changing lately. Make sure you have a recent build and check the script templates for examples. As a last resort, you can always look at the API docs on the wiki.

batFINGER
Posts: 33
Joined: Wed Jan 23, 2008 4:33 pm

Postby batFINGER » Sun Feb 13, 2011 1:50 am

Yep that is for a pretty recent build revision 347xx. You can compile them yourself or download one from http://graphicall.com. With all the API changes it pays (IMO) to at least start from where it's at when writing a script.

That said it may work in prior versions by just deleting/commenting all the code from "def register():" down.

Stefano Comba
Posts: 5
Joined: Sat Feb 12, 2011 4:27 pm

Postby Stefano Comba » Sun Feb 13, 2011 11:45 am

Yesterday i've downloaded (from graphicall.org) the recent build 348xx for MACOSX and during script running finally no errors occurs. But, for some other reasons nothing happens.. no panel appears!

New suggestions?
Thanks
Stefano

batFINGER
Posts: 33
Joined: Wed Jan 23, 2008 4:33 pm

Postby batFINGER » Sun Feb 13, 2011 3:32 pm

Sorry took a while to reply.. totally effed my blender builds...

The panel is in the object tab of the properties window called "Hello World Panel".. It also appears in the import menu... which is the one I'd go for and use the panel on the filebrowser screen for any import properties.

Why the object panel of the properties window? that's where the simple panel template py put it... you can change the bl_region_type property to put it somewhere else.

Stefano Comba
Posts: 5
Joined: Sat Feb 12, 2011 4:27 pm

Postby Stefano Comba » Sun Feb 13, 2011 5:08 pm

Thank you very much! It works! :)

Sorry but i'm not so expert in py... so now i have to use the file selected with your script, joining your script with mine.

Code: Select all

def myLoader(fileName):

    file = open(fileName, 'r');
    ...
    ...


myLoader it's a function that open the selected file and parse the content to create a new boujou tracking camera in blender. You can see the entire function in my first post.

Could you please help me doing this? I'm little confuse :(

Thanks!!!!!
Stefano

batFINGER
Posts: 33
Joined: Wed Jan 23, 2008 4:33 pm

Postby batFINGER » Sun Feb 13, 2011 5:48 pm

In my sample look at the "main" method. It is called by the execute method of the operator and is passed self (an instance of the operator class) and context . .. context.scene is the active scene for instance.

I

Use your Myloader instead

Code: Select all

def MyLoader(context,self):
   
   directory, file = os.path.split(self.filepath)
   print("Directory:"+directory)
   print("File:     "+file)
   f = open(self.filepath,'r')
   ...
   ...


And change

Code: Select all

      main(context,self)


in the execute method of the operator class SimpleOperator to

Code: Select all

MyLoader(context,self)


Have a look at some of the addon scripts in 2.56/scripts/addons for some hints tips on how to do some things.

Stefano Comba
Posts: 5
Joined: Sat Feb 12, 2011 4:27 pm

Postby Stefano Comba » Sun Feb 13, 2011 7:09 pm

thank you very much!!! it works :)
Stefano

keithcomposer
Posts: 1
Joined: Thu Feb 17, 2011 5:23 am

Final script

Postby keithcomposer » Thu Feb 17, 2011 5:25 am

Could you please post the final version of the script.

Neverinactive
Posts: 1
Joined: Sun May 29, 2011 8:47 am

Final Blender - Boujou Script

Postby Neverinactive » Sun May 29, 2011 8:54 am

Greetings! Great work, we'd love to have one of you guys on our team someday.

Question, could somebody please post the final version of the Blender - Boujou script that has been compiled on this forum? That would help us out a bunch! Thanks.

Neverinactive (admin@neverinactive.com)
We are obsessed with creating stuff! http://www.neverinactive.com

chlowden
Posts: 2
Joined: Sat Jun 11, 2011 9:55 am

Postby chlowden » Sun Mar 18, 2012 9:19 am

Did anyone post The script?
Many thanks


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest