import 3ds_export invalid syntax

Hopefully a not too stupid question but why can’t I import the 3ds_export script in my own script. It works for other exporters but not for 3ds_export

I’m writing a script to convert my obj object to 3ds format.
It works import obj and exporting obj again:

import Blender
from Blender import Scene, Object, Material
import import_obj
import export_obj

scene = Scene.New('ExportScene')
scene.makeCurrent()
import_obj.load_obj('/home/test/scan_faceFrnt_scl8_tst02.obj',CLAMP_SIZE=10.0)
obs = [ob for ob in scene.objects if ob.type == 'Mesh']
export_obj.write('/home/test/test.obj',obs);
#for ob in scene.objects: export_obj.write('/home/test/test.obj',ob)

But trying the 3ds_export script it just won’t work.


import Blender
from Blender import Scene, Object, Material
import import_obj
import 3ds_export

scene = Scene.New('ExportScene')
scene.makeCurrent()
import_obj.load_obj('/home/test/scan_faceFrnt_scl8_tst02.obj',CLAMP_SIZE=10.0)
obs = [ob for ob in scene.objects if ob.type == 'Mesh']
3ds_export.safe_3ds('/home/test/test.3ds');
#for ob in scene.objects: export_obj.write('/home/test/test.obj',ob)

  File "import_objtest.py", line 4
    import 3ds_export
           ^
SyntaxError: invalid syntax

To me it seems the 3ds_exporter is not importable???

Hi!

Not a stupid question at all. In fact, thank-you very much for it! I had no idea you could import scripts just as easy as that.

Do you work with syntax highlighting on? I just tried your code then, and the first thing that struck me, was that “3ds_export” was marked in blue. - the usual colour for numbers.

If you rename 3ds_export.py to export_3ds.py, you can import it, though “Richard Lärkäng” on line 10 causes errors due to the accents on the a’s - change 'em to normal a’s and the script progresses as expected.

Thnx for your reply. I’ve tried your suggestion but I get:

File “import_objtest.py”, line 12, in <module>
AttributeError: ‘module’ object has no attribute ‘safe_3ds’

Btw, It doesn’t complain about the import statement anymore :slight_smile:
It’s only weird it cannot find the safe_3ds function

:cool:

Hmm,:confused:

Well, the word “safe” is not contained in any of the files in my script directory.
How is this function being called, and is the containing file in the scripts directory, are the only two things I can think of at the moment.

I found it as well. I knew I was going to ask a really stupid question some time soon :frowning:

What was a weird thing is that the 3ds exporter needs a Blender.Redraw() before it can export.

This is what we got so far. This script can be called from command line Blender -P script.py. Now we need to load specific files in this script:

import Blender, string, os
from Blender import Draw, Window, Mesh, Mathutils, sys, Scene, Object, Material, Texture, Image
import import_obj
import export_3ds
import BPyMesh

reload(BPyMesh)

import BPyMessages

XXX Texture

blender gui

def main():

## optimze meshes in scene
## settings used by optimizer 
# Defaults and system settings
if os.environ.has_key('BC_HOME'):
    BC_HOME = os.environ['BC_HOME']
else:
    BC_HOME = '/home/arnaud/Documents/z25/bodycount/'

PREF_REDUX= Draw.Create(0.1)
PREF_DO_UV= Draw.Create(1)
NAME = Draw.Create( 'sphere.obj')
LOCATION = Draw.Create( BC_HOME + 'tests/BlenderExporter/')
PICTURE = Draw.Create( 'apple.jpg')
pup_block = [\
        ('Poly Reduce:', PREF_REDUX, 0.05, 0.95, 'Scale the meshes poly count by this value.'),\
        ('UV Coords', PREF_DO_UV, 'Interpolate UV Coords.'),\
        '',\
        '',\
        ('Location: ', LOCATION, 0, 256),\
        ('Name: ', NAME, 0, 128),\
        ('Picture: ', PICTURE, 0, 128),\
    ]

if not Draw.PupBlock('Bodycount Poly Reducer', pup_block):
    return
## import all meshes
LOCATION = LOCATION.val
NAME = NAME.val
PICTURE = PICTURE.val
scene = Blender.Scene.New('BlenderReductionScene')
scene.makeCurrent()
import_obj.load_obj(LOCATION + NAME, CLAMP_SIZE=10.0)

## optimze meshes
PREF_REDUX= PREF_REDUX.val
PREF_BOUNDRY_WEIGHT= 5.0
PREF_REM_DOUBLES= 1
PREF_FACE_AREA_WEIGHT= 1.0
PREF_FACE_TRIANGULATE= 1

VGROUP_INF_ENABLE= 0
VGROUP_INF_REDUX= ''
VGROUP_INF_WEIGHT= 10.0

PREF_DO_UV= PREF_DO_UV.val
PREF_DO_VCOL= 1
PREF_DO_WEIGHTS= 1
PREF_OTHER_SEL_OBS= 0

t = sys.time()

for ob in scene.objects:
    print ob.type
    if ob.type == 'Mesh':
        BASENAME = NAME.split('.').pop(0)
        ob.setName(BASENAME)
        print 'reducing:', ob.name 
        BPyMesh.redux(ob, PREF_REDUX, PREF_BOUNDRY_WEIGHT, PREF_REM_DOUBLES, PREF_FACE_AREA_WEIGHT, PREF_FACE_TRIANGULATE, PREF_DO_UV, PREF_DO_VCOL, PREF_DO_WEIGHTS, VGROUP_INF_REDUX, VGROUP_INF_WEIGHT)              
        print 'assigning material using texture ' + PICTURE
        tex = Texture.New(BASENAME + '-texture')
        tex.setType('Image')
        tex.image = Image.Load(LOCATION + PICTURE)
        mat = Blender.Material.Get().pop(0)
        mat.setName(BASENAME + 'material')
        mat.setTexture(0, tex, Texture.TexCo.UV)
        ob.setMaterials([mat]) 
        ob.colbits = (1&lt;&lt;0)
        print 'Mesh Processing done in %.6f sec.' % (sys.time()-t)


#apparently 3ds export needs a redraw before it can export ???
Blender.Redraw()
export_3ds.save_3ds(LOCATION + BASENAME + '.3ds')
#Blender.Quit()

if name == ‘main’:
main()