How to Fix broken scripts because renaming of API functions

As promised to RickyBlender: This script is broken because a renaming of a function so here is the mini tutorial step by step:

We are going to fix this script: [system_test_script_to_fix.py](http://www.filefront.com/17803566/test.zip/)
Place the script in blender/2.56/scripts/addons   
(or much better (the recommended way by blender developpers for scripts that don't ship with
blender and are not revised by them) in folder: blender/2.56/scripts/addons_contrib
creating such folder if you don't have it yet)
and open blender and go to File/User Preferences/Add-Ons/<b>System</b>

The addon don't even shows (in a recent blender build 34333).
What blender shows in addons is the content of a dictionary variable
"bl_addon_info" in the script, so something is wrong in this variable now.
Close User Preferences.

Change the 3DView to Text Editor and Text/Open and in blender/2.56/scripts/addons
open some script like for example the add_curve_aceous_galore.py and you can see 
that <b>bl_addon_info</b> is now changed to <b>bl_info</b>.
Close this script: in the Text Editor Menu footer you see the script name and to the right a <b>+</b> and
a <b>x</b> button. Click the <b>x</b> one to close the script.

Open in Text editor in blender our script and change bl_addon_info to bl_info
and Text/Save to save the changes. Don't close the script yet.

Open User Preferences/Add-Ons/System and now you see "Test script to fix" addon.
You can't check the box to the right to enable the script. We need to look
the python terminal (not the python console in blender) to know what is happening.
In Windows you have already that python terminal opened.

In Linux you need restart blender from terminal. So if you are in Linux close blender and
open a terminal and navigate to where the blender executable is
(there is an addon for nautilus that adds an option to open a terminal on the folder you are
that is very useful if you didn't know)
and write:
./blender
and now you have the python terminal running too. Of course open the script in the text editor
too if you were in Linux.

Well, try to enable the add-on and look what is said in the python terminal:
It says system_test_script_to_fix.py line 20 ImportError: cannot import name LineIntersect

In the script, the line 20 is this:
from mathutils.geometry import LineIntersect

and this function name is now not found (because the name has changed).
To know what name it has now, in blender change the Text editor to Python Console.
Enter this text:
import mathutils   (and return to import this module)
mathutils.geometry   (and click two times the Autocomplete button, first time it adds a dot
and second it shows the functions in geometry module)

There is not a LineIntersect function so it was renamed, the one with a closer name is "intersect_line_line".

Go to Text editor where we have our script opened and we need to see line numbers. Choose in
the Text Editor menu View/Properties and click the Line Numbers button
In line 20 change:
from mathutils.geometry import LineIntersect
to:
from mathutils.geometry import intersect_line_line

In the properties panel you have a Find button. Enter LineIntersect and click Find
It finds in line 25:
a = LineIntersect(v[0],v[1],v[2],v[3])
that you must change to:
a = intersect_line_line(v[0],v[1],v[2],v[3])

Text/Save and X to unlink (close) the script. Change to 3DView.
In UserPreferences/Add-ons/System you can now enable at last the "Test script to fix" script. The script shows at the bottom of the N panel in the 3DView a button that calls the problematic function and then just returns without doing anything more.

Fixed.

I downloaded it and it is as I said: you must change lines 43, 60, 90 as commented in first post. I guess you are editing zeffii script not mine (it has the same name).

Because the bl_addon_info and changes to the name of API functions, the scripts that are broken will be forever at least you or someone do the changes I explain here.

I said in the Big Number Toolkit thread that I recommend don’t use the /scripts/addons folder.
Instead create an /scripts/addons_contrib folder and place there these scripts that don’t come with blender. So when you download another blender version you only have to copy the /addons_contrib folder there and you don’t touch anything inside /addons folder (these scripts are maintained by blender developpers)

I have a script that compiles and then adds this /addons_contrib folder. I just double click a link in the desktop and all is ready in around two minutes. :cool:
But the download of the source code with subversion I don’t do that with the script, I prefer enter and see in the subversion client what they changed.

my script is up-to-date with changes and linked on the first page always of my own thread. It’s a shame you named that script the same as mine, now there is confusion.

Done. I deleted that script with same name than yours and built an example script instead.
Seems not be a shame anymore now.

getting the latest built to be upated

conusing with 2 scripts habing same name = yes **3

give me the link to the latest script version
i’ll create a new folder for this
and i guess here you will already have done the changes in it

when you save a message here

is it getting slower in forum
seems to me it takes quit a while to save messages / reply since yesterday !

Thanks happy 2.5

I rewrote first post and now is a different script called system_test_script_to_fix.py

sorry but don’t anymore where it is ?

is this in the Zeffi trhead or you have your own thread ?

http://blenderartists.org/forum/showthread.php?t=204836

Thanks

ok i see first post with the new script name

got new build and installed a new folder for new scripts
which is a nice feature thanks for the tip

the only thing i did not find is the find button in the propertie window !
can you re explain or may be show a pic for this button ?

now with this API change for line intersect is there any good doc for theses new functions?
explaning may be ow to sue theses and what you can do ?

Thanks happy 2.5

In the Text Editor View/Properties (hotkey is Ctr+F to show that panel). In that panel there is the properties subpanel and the find subpanel below where you has the Find button.

Yes, you can download the pdf with all the API (just above that red rectangle is the link to the pdf) but you will see the old name LineIntersect yet.

ok but nothing new for the new Geometry module!

Ctlr-F it’s the standard find tool for the text editor

i tought you were talking about the properties panel on the right side like Scene material texture ect…! LOL

Now are you going to open a new thread for this edge script with new name may be or you keep it here!

got to try and use more this new API help script might be usefull !

Thanks happy 2.5

In Blender 2.56 when you click Ctr+F it opens a panel to the left like the tool shelf in a 3DView. It is called Properties if you open it in the Menu of the Text Editor (View/Properties).

You talk about the API Navigator script that PKHG pointed you? Yes, I recommend it too. But I find using the python console a quicker way for things like I explained in first post of this thread.

Why don’t you use a VCS to keep track of your scripts? Then you can post your fixes in the form of patches like this

commit 79d11d8df6258fbb7b2e92b3420633f6bbdd7fe4
Author: Lawrence D'Oliveiro &lt;[email protected]&gt;
Date:   Tue Jan 18 03:46:30 2011 +0000

    another API change

diff --git a/treadtiler.py b/treadtiler.py
index 45223e1..57ce503 100644
--- a/treadtiler.py
+++ b/treadtiler.py
@@ -21,7 +21,7 @@ import sys # debug
 import bpy
 import mathutils
 
-bl_addon_info = \
+bl_info = \
     {
         "name" : "Tread Tiler",
         "author" : "Lawrence D'Oliveiro &lt;[email protected]&gt;",