error in the if, elif, else statement ?

juan-manuel.behrendt at siemens.com juan-manuel.behrendt at siemens.com
Wed May 9 03:46:26 EDT 2007


Hello together,

I wrote a script for the engineering software abaqus/CAE. It worked
well until I implemented a selection in order to variate the variable
"lGwU" through an if elif, else statement. I am going to post the
first 82 lines of the script, since the error message points at line
80:

from abaqusConstants import *
from abaqus import *

def CreateSchraube(name, l, flag=None, flag2=None):
        import part
        vp = session.currentViewportName
        model = session.sessionState[vp]['modelName']
        m = mdb.models[model]
        s = m.ConstrainedSketch(name='__profile__', sheetSize=1000.0)
        s.ConstructionLine(point1=(0.0, -500.0), point2=(0.0, 500.0))

        if flag==1:

          dh = 15.0
          z = 15.0
          dz = 60.0
          d = 72.0
          f = 1.0
          dD = f*62.0
          lGwO = 110.0

          if flag2==11:                       # here appears the
beginning of the new impletation in order to variate lGwU
             lGwU = 0.8*d                  # you can see these inner
if, elif, else statement 4 times, because
          elif flag2==12:                    # the outer if, elif,
else statement (which works!) has 4 cases
             lGwU = 1.0*d
          elif flag==13:
             lGwU = 1.2*d
          else: pass

        elif flag==2:

          dh = 15.0
          z = 15.0
          dz = 60.0
          d = 72.0
          f = 1.0
          dD = f*62.0
          lGwO = 110.0

          if flag2==11:
             lGwU = 0.8*d
          elif flag2==12:
             lGwU = 1.0*d
          elif flag==13:
             lGwU = 1.2*d
          else: pass

        elif flag==3:

          dh = 25.0
          z = 15.0
          dz = 68.0
          d = 80.0
          f = 1.0
          dD = f*71.5
          lGwO = 120.0

          if flag2==11:
            lGwU = 0.8*d
          elif flag2==12:
            lGwU = 1.0*d
          elif flag==13:
            lGwU = 1.2*d
          else: pass

        elif flag==4:

         dh = 25.0
          z = 15.0
          dz = 68.0
          d = 80.0
          f = 1.0
          dD = f*71.5
          lGwO = 120.0

          if flag2==11:
            lGwU = 0.8*d
          elif flag2==12:
            lGwU = 1.0*d
          elif flag==13:
            lGwU = 1.2*d
          else: pass

        else: pass

        xyCoords = ((dh/2, -z), (dz/2, -z), (dz/2, 0), (d/2, 0),    #
this is line 80, where the error message points at
                           (d/2, lGwU), (dD/2, (d-dD)/
(2*tan(radians(12)))+lGwU),
                           (dD/2, l-lGwO-z-(d-dD)/
(2*tan(radians(20)))), (d/2, l-lGwO-z), (d/2, l-z), (dh/2, l-z), (dh/
2, -z))

So, a lot of code, I hope somebody will read it.
My Problem ist the error message, which says:

" #* UnboundLocalError: local variable 'lGwU' referenced before
assignment
  #*File "C:\ABAQUS_Products\6.6-3\abaqus_plugins\Schraube.py", line
80, in
  #*CreateSchraube
  #*     xyCoords = ((dh/2, -z), (dz/2, -z), (dz/2, 0), (d/2, 0), "

So the error message is quite clear, however it is not suitable to
what I've written in my script, because the local variable 'lGwU' IS
assigned before referenced and, furthermore in line 80 lGwU does not
appear.
Another strange thing is, that the first two cases, where lGwU = 0.8*d
and lGwU = 1.0*d is, do work in my abaqus script.
So the error message only occurs if I choose lGwU = 1.2*d.

I expect a stupid different error, since I am a Python beginner
(please don't be impatient), but I am not seeing it.

Sincerely,

Manu




More information about the Python-list mailing list