Switch Direction/Reverse Curve

Does anyone have code to reverse the direction of a curve? It’s in the GUI (Edit Mode:Curve/Segments/Switch Direction) but I need to be able to do it in python. Can’t quite figure it out. :frowning:

thanks

First of all as a new user I want to say a lound and kind hello to everyone :rolleyes: Quite new to Blender too… Thanks for helping making this great software happen!

[bump] I had a look at the source code, and unfortunately it seems to be done in C :frowning: I tried to replicate that sort of behaviour for just two points like below:

tmpCur = Curve.New()
tmpObj = Object.New('Curve')
tmpObj.link(tmpCur)
tmpCur.appendNurb( subcurve[pointIndex-1] )
tmpCur[0].append( subcurve[pointIndex] )
STATE['scene'].link(tmpObj)

(...)

switch = tmpCur[0][0]
tmpCur[0][0] = tmpCur[0][1]
tmpCur[0][1] = switch
tmpCur.update()

subcurve is an existing curve I want to replicate… This (so creating in the order point[0], point[1]) works, but when I switch the order, the curve looks quite different.

Any ideas?
Kind regards.
David

I made such a script some time ago. See http://blenderartists.org/forum/showthread.php?t=71837 .

Thanks for the reply! Unfortunately, it does just the same as my current code - turns a Bezier curve into something unrecognizable. Is there any way to invert Bezier curves?

Cheers,
David

One possibility would be to use Blender’s function via Python like in this example: http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Cookbook#ScanFill

Excellent, I didn’t know you could do that. Thanks for the tip! The problem I am having now, however, is that once the menu is displayed, the script sort of stops executing - so that I still have to manually click the option. Even placing QHandles but didn’t help much.

winId = Window.GetScreenInfo(Window.Types.VIEW3D)[0]['id']
Window.EditMode(1)
Window.QAdd(winId, Draw.WKEY,1)
Window.QHandle(winId)
Window.QAdd(winId, Draw.LEFTMOUSE,1)

The click does get executed, if I do the following:

winId = Window.GetScreenInfo(Window.Types.VIEW3D)[0]['id']
Window.EditMode(1)
Window.QAdd(winId, Draw.WKEY,1)
Window.QHandle(winId)
Window.QAdd(winId, Draw.LEFTMOUSE,1)
while( True ):
    print 'Haaa'
Window.EditMode(0)

(I know, silly.) I can see loads of Haa’s printed in the console. Checked with print what happens during a ‘real’ MB press, there seems to be a MOUSEX followed by a MOUSEY event. Yet having those doesn’t help either.

Regards,
David

Ok, some progress. I’ve come to the obvious conclusion that the small pop-up appearing when you press WKEY does not belong to the 3d window, and hence cannot receive its events. But then… what does it belong to? I’ve tried the scripts window too to no avail. So what I’ve got so far:

 tmpObj.select(1)
viewWin = Window.GetScreenInfo(Window.Types.VIEW3D)[0]['id']
scriptWin = Window.GetScreenInfo(Window.Types.SCRIPT)[0]['id']
Window.EditMode(1)
Window.QAdd(viewWin, Draw.WKEY, 1, 0)
Window.QAdd(scriptWin, Draw.LEFTMOUSE, 1, 1)
Window.QAdd(scriptWin, Draw.LEFTMOUSE, 0, 1)
Window.QHandle(viewWin)
Window.QHandle(scriptWin)

Ehh, maybe it’s asking too much? Perhaps in the end there is a way of doing the same in Python? Another problem I’ve noticed is that most of the time when the popup is drawn, mouse pointer is directly above the right option (second, Switch Direction). But sometimes it’s above the first one for some reason.

Anyway, thanks for all your help so far!
Cheers,
Dav

A little update - it is not possible to trick UI - Special menu that appears once you press WKEY steals all inputs. So it would appear that if it can be done, it can only be done in Python… anyone…? :slight_smile:

Cheers!
Dav

probably best to add this into the Blender C/Python API, not a bad function to get your hands dirty

Just came back from a short trip. Well, there you go if anyone is in urgent need of a solution to this :cool: