Requesting Assistance to Update Script

Hi all,

I have been using Blender 2.4x to develop 3d models for a program called RealFlight.

RF uses a utility called “3ds2kex” to take a 3ds model and convert it to a usable model. The Blender guys at RF have been using an export utility (included here) to take a .blend file and convert it to .3ds. This script also generates a .kex file that includes pivot information for the model.

I have started messing around with Blender 2.5x and I can’t get this script to work in the new version. I was hoping someone could take a look at the script and either update it for me, or point out what I need to do to update it.

Thanks for your help.

Hmm, it seems the code is too long to post here. Any ideas on how best to share the code so someone can look at it?

You can paste code at http://www.pasteall.org/ for linking. :slight_smile:

Don’t forget to save the link or you’ll lose it and have to repost. :wink:

Okay, here’s the link.

http://www.pasteall.org/16890

I place the script in “2.55\scripts\op” The script is named “3ds2kex_export.py”.

On startup, here is what Blender’s console window tells me:


Error initializing quicktime
found bundled python: C:\Users\XXXXX\Desktop\portable\BLENDE~1.55-\2.55\py
thon
Traceback (most recent call last):
  File "C:\Users\XXXXX\Desktop\portable\BLENDE~1.55-\2.55\scripts\modules\
bpy\utils.py", line 45, in _test_import
    mod = __import__(module_name)
  File "C:\Users\XXXXX\Desktop\portable\BLENDE~1.55-\2.55\scripts\op\3ds2k
ex_export.py", line 134
    print 'Warning: Filenames must be less than 12 characters (\'' + name + '\')
'
                                                                 ^
SyntaxError: invalid syntax

I’m guessing that line 45 in utils.py is throwing an error because the script is broken. The error I get is on line 134. Here are lines 124~150:


def sane_name(name, nameBucket, isFilename):
    if nameBucket not in name_mapping:
        name_mapping[nameBucket] = {}
        name_unique[nameBucket] = []

    name_fixed = name_mapping[nameBucket].get(name)
    if name_fixed != None:
        return name_fixed
    
    if (isFilename) and (len(name) > 12):
                print 'Warning: Filenames must be less than 12 characters (\'' + name + '\')'
        new_name = name[:12]
    else:
        new_name = name
    
    i = 0
    
    while new_name in name_unique[nameBucket]:
        if (isFilename) or (new_name != name):
            new_name = new_name[:-4] + '.%.3d' % i
        else:
            new_name = new_name + '.%.3d' % i
        i+=1
    
    name_unique[nameBucket].append(new_name)
    name_mapping[nameBucket][name] = new_name
    return new_name

Anyone have any ideas?

Two things are wrong with this line:


print 'Warning: Filenames must be less than 12 characters (\'' + name + '\')'

Firstly, in Python 3.x, print is a function print(), secondly it looks like an inverted comma just before the word “name” is out of place. Given that it is a function now, the whole end probably needs to be changed.

In 2.x it should probably be:


print 'Warning: Filenames must be less than 12 characters \' + name + '\'

In 3.x it should probably be:


print('Warning: Filenames must be less than 12 characters \' + name + '\')

I replaced the line with your 2.x example and got this:


  File "C:\Users\XXXXX\Desktop\portable\BLENDE~1.55-\2.55\scripts\op\3ds2k
ex_export.py", line 134
    print 'Warning: Filenames must be less than 12 characters \' + name + '\'
                                                                          ^
SyntaxError: invalid syntax

I also tried the 3.x example and it didn’t work either.

Strange. Well if all else fails you could always comment that print statement out. It’s only user feedback to provide notice that the file name is being truncated. It should have no adverse effects on the rest of the script.

I commented out that line and now it’s throwing another error on line 425:

  File "C:\Users\XXXXX\Desktop\portable\BLENDE~1.55-\2.55\scripts\op\3ds2k
ex_export.py", line 425
    print spaces, self.name, " = ", self.value
               ^
SyntaxError: invalid syntax

Here are lines 419~427:


    def dump(self,indent):
        if (self.value!=None):
            spaces=""
            for i in xrange(indent):
                spaces+="  ";
            if (self.name!=""):
                print spaces, self.name, " = ", self.value
            else:
                print spaces, "[unnamed]", " = ", self.value


BTW, thank you for looking at this and helping me out.

all print line in 2.5 must be with parenthesis like

print (‘hello’)

so try this

print (spaces, self.name, " = ", self.value)

happy 2.5

I corrected about 4 other print statements. No more errors there. Now it’s throwing an error on line 31:

import Blender

It says there is no module named Blender.


import math
import Blender
import bpy
import BPyMesh
import BPyObject
from BPyMesh import getMeshFromObject
from BPyObject import getDerivedObjects
from Blender import Registry
import struct
import os

sorry but are you dong this i 2.5 ?

2.5 does not ahve any module blender
that was used in 2.49 ?
so remove it that’s all

happy 2.5

You’re probably going to need to find out where all the functionality has been moved to in 2.5. The Blender module has been removed and replaced with a new, improved bpy.

Okay, I did some more poking around and I get this:



Warning! 'C:\Users\XXXXX\Desktop\portable\BLENDE~1.55-\2.55\scripts\op\3ds
2kex_export.py' has no register function, this is now a requirement for register
able scripts.

This script is based off the included 3ds export script. I didn’t see anything in the normal script that looks like a register function…

I would like to help
There are so many things to find out …
e.g. look here (a Cube with two materials the second with two textures as two images)

My test:


import bpy
cu = bpy.context.active_object
print(cu.material_slots)
slot1 =cu.material_slots[1]
print(dir(slot1))
print("material",dir(slot1.material))
print("slot1.material.type=",slot1.material.type)
print(slot1.material.specular_color)
print(dir(slot1.material))
mat0 = slot1.material.texture_slots[1]
print("mat0=",mat0)
print(dir(mat0))
print(dir(mat0.texture))
print(mat0.texture.image)
for mat in slot1.material.texture_slots:
    if mat:
        print(mat.texture.type)

def get_material_images(material):
    # blender utility func.
    images = []
    if material:
#        for mtex in material.getTextures():
        for mtex in material.texture_slots:
            if mtex and mtex.texture.type == 'IMAGE':
                image = mtex.texture.image.name
                if image:
                    images.append(image) # maye want to include info like diffuse, spec here.
    return images

imageNames = get_material_images(slot1.material)
print(imageNames)

giving:

[‘kubus.png’, ‘pokal.jpg’] indeed the name of the picture files :wink:

I completely didn’t understand any of that. Sorry.

Look at the given source for
def get_material_images(material):
That has to be changed completely!
And I gave a (probable) solution (if I understood the original)
(as well how I find out , the first commands)

Meaning: you need a lot of changes, because 2.49 and 2.55 are not totally compatible.

I sympathize with you completely. I’ve been working with DudeCon on updating the “AutoMasonry” script for Belnder 2.5 (almost ready for public use). There are a lot of structural changes you’ll need to make. My recommendation is to have a look at some of the packaged add-ons for general info on how to update your script.

I based my changes on some of the “add_mesh” modules but you’ll probably want to look at the “io_export” modules. What you need now is common for all types of extensions, look at the end of the file for registration and related functions.