Jiba,

I was seeing if I could learn a little more of the Blender Python API,
and I came up with this. It's just a demo, but I thought it might be
useful to see if you could integrate it with your import_blender.py or
blender2cal3d.py scripts (I made it with the latter in mind). It makes
setting parameters a little easier.... :-)

Anyway, if it's useful, then great (feel free to use it), if not, then
fine, it was a good learning experience for me. :-)

--Matt

On Wed, 19 Nov 2003, Jiba wrote:

>Date: Wed, 19 Nov 2003 23:59:37 +0100
>From: Jiba <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Cc: [EMAIL PROTECTED]
>Subject: Re: [Soya] Soya + Blender 2.28 or 2.30?
>
>On Wed, 19 Nov 2003 03:37:26 -0800 (PST)
>Matthew Bogosian <[EMAIL PROTECTED]> wrote:
>
>> Howdy all,
>>
>> I was so thrilled to find Soya and was really excited to start playing
>> with it with my own models, but I'm afraid I've hit a bit of a wall.
>> I've been using Blender (2.28 and 2.30). I installed the Python files
>> (from intern/python) by hand into my PYTHONPATH, but whenever I run
>> import_blender.py (from Soya 0.5.1), I get the following:
>>
>>     Traceback (most recent call last):
>>       File "/usr/lib/python2.3/site-packages/soya/import_blender.py", line 116, in ?
>>         open(filename, "w").write(export_to_soya())
>>       File "/usr/lib/python2.3/site-packages/soya/import_blender.py", line 26, in 
>> export_to_soya
>>         objs      = Blender.Object.Get()
>>     AttributeError: class Object has no attribute 'Get'
>>
>> If I try blender2cal3d (from blender2cal3d 0.4), I get the following:
>>
>>     Traceback (most recent call last):
>>       File "./cal3d/blender2cal3d-0.4/blender2cal3d.py", line 942, in ?
>>         export()
>>       File "./cal3d/blender2cal3d-0.4/blender2cal3d.py", line 652, in export
>>         scene = Blender.Scene.getCurrent()
>>     AttributeError: class Scene has no attribute 'getCurrent'
>>
>> I even tried going back to 2.25, but I still had the same problem. Did
>> the Blender Python API change drastically in 2.2x? What version of
>> Blender are folks using with Soya? Is there a tutorial available for
>> Blender (+ GIMP) -> Soya (importing and using model and texture data)?
>> Is there an alternate path or solution for us folks using 2.30 or am I
>> just a total ignoramus?
>>
>> Any help would be greatly appreciated.
>
>I use Blender 2.28...
>
>I send you the latest export file from Soya 0.5.2, it is probably a newer version.
>
>I've written recently a chapter on Blender integration in the still-in-early-stage 
>Soya Handbook ; i join it in PDF format (see chapters 5 and following).
>
>Hope this help,
>
>Jiba
>
#=========================================================================
"""
  Press ALT-P to run.

  Copyright (c) 2003, Matthew Bogosian <[EMAIL PROTECTED]>

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
#=========================================================================

#---- Imports ------------------------------------------------------------

import Blender
import Blender.BGL
import Blender.Draw
import Blender.Window
import os
import os.path

#---- Private hook methods -----------------------------------------------

#=========================================================================
def _draw():
    """
    """
    global _soya_export_toggle

    Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)

    # Draw the title
    height = _MAX_Y
    Blender.BGL.glRasterPos2d(_MIN_X, height)
    Blender.Draw.Text(_SCRIPT_NAME)
#    Blender.BGL.glRasterPos2d(_MIN_X + 1, height)
#    Blender.Draw.Text(_SCRIPT_NAME)

    # Draw the widgets
    height -= 40
    Blender.Draw.Button(_OUTPUT_DIR_STR, _EVENT_SAVE, _MIN_X, height, 
_OUTPUT_DIR_STR_WIDTH + 10, 20, _OUTPUT_DIR_TIP)
    Blender.BGL.glRasterPos2d(_MIN_X + _OUTPUT_DIR_STR_WIDTH + 15, height + 5)

    if os.path.isdir(_save_dir):
        Blender.Draw.Text(_save_dir + _DIR_EXISTS_STR)
    else:
        Blender.Draw.Text(_save_dir)

    height -= 30
    _soya_export = _soya_export_toggle.val
    _soya_export_toggle = Blender.Draw.Toggle(_SOYA_EXPORT_STR, _EVENT_NONE, _MIN_X, 
height, _SOYA_EXPORT_STR_WIDTH + 10, 20, _soya_export, _SOYA_EXPORT_TIP)

    height -= 30
    width = max(_RUN_STR_WIDTH, _EXIT_STR_WIDTH)
    Blender.Draw.Button(_RUN_STR, _EVENT_RUN, _MIN_X, height, width + 10, 20, _RUN_TIP)
    Blender.Draw.Button(_EXIT_STR, _EVENT_EXIT, _MIN_X + width + 15, height, 
_EXIT_STR_WIDTH + 10, 20, _EXIT_TIP)

#=========================================================================
def _eventButton(a_event):
    """
    """
    if a_event == _EVENT_EXIT:
        Blender.Exit()
    elif a_event == _EVENT_SAVE:
        Blender.Window.FileSelector(_savePathFileDialog, _CHOOSE_DIR_STR)
    elif a_event == _EVENT_RUN:
        _runScript()

#=========================================================================
def _eventInput(a_event, a_val):
    """
    """
    # Check to see if it was a key/mouse button release
    if a_val == 0:
        if a_event in (Blender.Draw.ESCKEY, Blender.Draw.QKEY):
            Blender.Exit()

#---- Private callback methods -------------------------------------------

#=========================================================================
def _savePathFileDialog(a_path):
    """
    """
    global _save_dir
    path = a_path

    if not os.path.isdir(path):
        path = os.path.dirname(path)

    _save_dir = path

#---- Private methods ----------------------------------------------------

#=========================================================================
def _runScript():
    """
    """
    # Do your stuff here
    import time
    i = 0.0

    while i < 1.0:
        if i < 0.2:
            progress_text = 'Doing something...'
        elif i < 0.5:
            progress_text = 'Doing something else...'
        elif i < 0.7:
            progress_text = 'Stalling...'
        else:
            progress_text = 'Cleaning up...'

        Blender.Window.DrawProgressBar (i, progress_text)
        time.sleep(0.5)
        i += 0.1

    Blender.Window.DrawProgressBar (1.0, "Finished!")
    Blender.Exit()

#---- Private constants --------------------------------------------------

# Script constants
_SCRIPT_NAME = 'blender2cal3d GUI Demo'
_CUR_FILE = Blender.Get('filename')

# String constants
_DIR_EXISTS_STR = ' (exists!)'
_CHOOSE_DIR_STR = 'Choose directory...'

_OUTPUT_DIR_STR = 'Output directory:'
_OUTPUT_DIR_STR_WIDTH = Blender.Draw.GetStringWidth(_OUTPUT_DIR_STR)
_OUTPUT_DIR_TIP = 'Changes the directory in which to save the exported cal3d files. 
WARNING: this script will delete all existing files in this directory!'

_SOYA_EXPORT_STR = 'Export for Soya?'
_SOYA_EXPORT_STR_WIDTH = Blender.Draw.GetStringWidth(_SOYA_EXPORT_STR)
_SOYA_EXPORT_TIP = 'If set, properly exports files which can be used with Soya.'

_RUN_STR = 'Go!'
_RUN_STR_WIDTH = Blender.Draw.GetStringWidth(_RUN_STR)
_RUN_TIP = 'Runs the script. WARNING: this script will delete all existing files in 
the above directory!'

_EXIT_STR = 'Cancel'
_EXIT_STR_WIDTH = Blender.Draw.GetStringWidth(_EXIT_STR)
_EXIT_TIP = 'Aborts the script.'

# Layout constants
_MIN_X = 10
_MAX_Y = 120

# Event constants
_EVENT_NONE = 0
_EVENT_EXIT = _EVENT_NONE + 1
_EVENT_SAVE = _EVENT_EXIT + 1
_EVENT_RUN = _EVENT_SAVE + 1

#---- Private globals ----------------------------------------------------

# Script values (and their defaults)
_save_dir = 'cal3d'

if _CUR_FILE != None:
    _save_dir = os.path.join(os.path.dirname(_CUR_FILE), _save_dir)
elif 'HOME' in os.environ:
    _save_dir = os.path.join(os.environ['HOME'], _save_dir)
else:
    _save_dir = os.path.join(os.getcwd(), _save_dir)

_soya_export = True

# GUI widgets
_confirm = False
_soya_export_toggle = Blender.Draw.Create(_soya_export)

#---- Initialization -----------------------------------------------------

Blender.Draw.Register(_draw, _eventInput, _eventButton)
Blender.Redraw()

Reply via email to