姓名' ...'没有定义

时间:2017-04-10 14:49:28

标签: python freecad

我收到一条消息说

Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'update' is not defined

原始代码是

    from PySide import QtCore

    i = 0
    def update();
    global i
App.getDocument("Unnamed2").Pad001.Placement=App.Placement(App.Vector(0,127.5,0), App.Rotation(App.Vector(0,0,1),-i), App.Vector(0,0,0))
App.getDocument("Unnamed2").Pad.Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(0,0,1),i*(74.0/28.0)), App.Vector(0,0,0))
i += 0.01

    timer = QtCore.QTimer()
    timer.timeout.connect( update )
    timer.start( 1 )

它是齿轮动画的代码,但它不起作用。我编码不是很好,所以我不确定问题是什么。如果有人能帮助我会很好。谢谢。 :)

1 个答案:

答案 0 :(得分:0)

首先,您应该使用def update():而不是def update();。 其次,你缺少缩进

from PySide import QtCore

i = 0
def update():
    global i
    App.getDocument("Unnamed2").Pad001.Placement=App.Placement(App.Vector(0,127.5,0), App.Rotation(App.Vector(0,0,1),-i), App.Vector(0,0,0))
    App.getDocument("Unnamed2").Pad.Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(0,0,1),i*(74.0/28.0)), App.Vector(0,0,0))
    i += 0.01

timer = QtCore.QTimer()
timer.timeout.connect( update )
timer.start( 1 )