Many python problems - any help welcome

Hello,

I just began with some python scripting, and I encountered many problems of all kind. If you know a solution for any of them, thank you for answering. :slight_smile:

  • In the TextWindow (of Blender 2.25 and 2.23), I cannot write any special characters (such as #[]{}, etc) - I use a swiss-french (CH-fr) keyboard. This is very annoying, because I have to edit a text file outside blender containing these characters, then import it into blender to finally copy-paste them where I need them.
    Here my question: Is there a way to edit text files outside blender without having to re-import them after each modification and update the corresponding script-links? Or is there another solution/work-around that I donā€™t know?

  • In my Blender 2.25 (win2k), thereā€™s no more python error output as it existed in Blender 2.23. This makes script debuging almost impossible for me, because after any python error, the whole command line output stops, even after correcting the script error my print calls are no more displayedā€¦

Do you have the same problems? Is there any solution/work-aroud other than restarting Blender after every script error, or than using Blender 2.23?

  • In Blender 2.25, is there a way to preseve variables varables between two calls of a script, or between two scripts? This worked in Blender 2.23 and would be very restrictive if it wouldnā€™t work in 2.25.

Thanks a lot! And sorry to the blender.org forum readers for having also posted these questions here. :expressionless:

Gabriel

hi,

Canā€™t help you with (1) except that I ALWAYS write scripts in an IDLE window and accept I have to reimport them - Iā€™ve found that scripts written directly into the Blender text window sometimes had odd indentations (so stuffs up the scripts).

I open a new window in IDLE, write the script (or current bit there of), save then go:
save - select all - untabify region - OK - save - check module
(I wish there was one hotkey to do this!!)

  1. I have Blender 2.25 and python 2.2 working fine on the win2k box at work. No locking up etc.

  2. I wasnā€™t aware you could save values between scripts in any version (would be VERY useful!!). The easiest way would be for script 1 to write out a text file with the variable values listed and for script 2 to read the values in from this file. Iā€™m playing around with the idea of using empties to hold 3 numeric values. Make an empty called variableABC on an unused layer and set the locX, locY and locZ values to the variable values you want to keep.

Cheers Stephen

Hello,

  • I donā€™t understand well what you say. What is an IDLE window? You mean an external text editor? And what is ā€œuntabify regionā€, and where do you find this option? And how do you do a ā€œcheck moduleā€?

  • In B2.25, if I remove the comment of the following script, run the script, put back the comment, then any following script call wonā€™t print out anything:

import Blender
print Blender.Get("curframe")
#print an_error
  • The following code works in B2.23 (at each call, an incremented number is printed to the console window) - but in B2.25 it always prints out 0.
try: test+=1
except: test=0
print test 

Anyway, I think to write out a file or use your funny empty method is the best solution. The empty solution is very useful to keep track of position, speed or acceleration varables, where are always three variables. Nice tip! 8)
And thank you for your answer!

Gabriel

  1. If you really want to do that in Blender, youā€™ll have to switch the keyboard to English (english american, canadian, whatever). Of, you can continue editing the script outside Blender and use the Ctrl-R shortcut to reload the version on disk whenever you want to update the one in Blender.

  2. I never had that problem and never heard about one like this. But version of 2.25 are you using? The NAN release or a custom build?

  3. I just had an idea of a solution for that problem, I tested it and is seems to work (no garanty though).
    The trick is to embed the variable directly in the Blender API, since, even if itā€™s a different interpreter, the API is not rebooted each time. Hereā€™s what I used to test this theory:


import Blender

try:
        Blender.VarTest += 1
except:
        Blender.VarTest = 1

print Blender.VarTest

link that to framechange and it behaves as it should.

Or, you could use the pickle (or cPickle) module to saves the variable in an external file.

I hope that can help you.

Martin

Re-re-hello, thank you for your useful answers.

  • Yeah, I think Iā€™ll buy a us keyboard one day, even if I write french I never wite the Ć©ĆØĆ  etc. But for now, the CTL-R tip will be VERY useful (it wasnā€™t described in the Blender 2.0 guide)!

  • Theeth, see my previous post for more details (yes I have the 2.25 NAN release). I think that our two previous posts crossed themselves.

  • Yeah, it works for me too! Thats a really great solution! :smiley:
    Gabriel

I tried doing that but I donā€™t get any error. That is, after the first run, it outputs an error on the ā€œprint an_errorā€ line, but after commenting it, it prints the frame number as it should.

about the keyboard thingy, if youā€™re under Window, change the keyboard language can be done in the Control Panel, no real need to buy a new one (unless you donā€™t know where the keys are, but you can probably find a pic of an english keyboard and use it as reference)

Martin

Ok, thatā€™s interesting to know! Iā€™ll try to investigate by re-installing, and so onā€¦ But itā€™s not the first time my computer acts strangly, but all windows computers tend to have a rather random behaviorā€¦ If I canā€™t figur it out, Iā€™ll go work under linux! Anyway, itā€™s really nice of you for having tested it, knowing this helps me a lot!

Yes, I knowā€¦ But Iā€™m programming more and more (usually php), and the us key mapping is more confortable (and Iā€™m lazy). But youā€™re right, it should not be a problem to use another key mapping than what is printed on the keyboard.

Yayayah, Iā€™m happy for having received such a warm help on this forum! One day, Iā€™ll give it back to someone else on this forum, thatā€™s promised! :smiley:

Gabriel

HI,

I donā€™t understand well what you say. What is an IDLE window? You mean an external text editor? And what is ā€œuntabify regionā€, and where do you find this option? And how do you do a ā€œcheck moduleā€?

IDLE is the text editor/command line interpreter that comes with python.

I presume you downloaded python from http://www.python.org/

(if you havenā€™t got it - GET IT! Youā€™ll need the additional modules it provides - like maths, OS/system and string functions)

After you installed you should have a ā€œPython 2.2ā€ folder (or whatever version installed) in your start menu>programs.

In this folder is a shortcut called ā€œIDLE (Python GUI)ā€. Opening this brings up a window with a >>> prompt. This is a command line interpreter, you can type python commands here and get an instant response (obviously not Blender specific stuff).

If you go File>new window, you get a text editing window, you can type/save/debug your script here .

You can then open your saved script in blender using the DASH>open new
button.

the series:
save - select all - untabify region - OK - save - check module
is a basic form of syntax debugging I do to my scripts in the IDLE text window before opening them in Blender.

Regarding making empties - have a look at this thread
https://blenderartists.org/forum/viewtopic.php?t=8168

Cheers Stephen

It happens in my version of 2.25 as well, and others too, when a script is linked and errors occur, the script doesnā€™t seem to run anymore after that.
https://blenderartists.org/forum/viewtopic.php?t=7027

  1. I just had an idea of a solution for that problem, I tested it and is seems to work (no garanty though).
    The trick is to embed the variable directly in the Blender API, since, even if itā€™s a different interpreter, the API is not rebooted each time. Hereā€™s

It definitly works without problems, somebody asked the same question two months ago on blender.org, I gave the same answer.

The same ā€˜trickā€™ (itā€™s in the python docs, you can put variables in any moduleā€™s global namespace) has been used by the Blender gamers in their python scripts, since the game engine has the same ā€˜problemā€™. So they also store variables using the GameLogic module itself.