Problem with 2.3 guide Circle script - I still need help!!

I decided to copy the script out of the book. I did the whole thing:

#####################################################
#
# Demo Script for Blender 2.3 Guide
#
##################################################S68
# This script generates polygons. It is quite useless
# scince you can do polygons with ADD->Mesh->Circle
# but it is a nice complete script example, and the
# polygons are `filled'.
#####################################################

#####################################################
# Importing modules
#####################################################

import Blender
from Blender import NMesh
from Blender.BGL import *
from Blender.Draw import *

import math
from math import *

# Polygon Parameteres
T_NumberOfSides = Create(3)
T_Radius

# Events
EVENT_NOEVENT = 1
EVENT_DRAW    = 2
EVENT_EXIT    = 3

#####################################################
# GUI drawing
#####################################################
def draw():
   global T_NumberOfSides
   global T_Radius
   global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT

   ########## Titles
   glClear(GL_COLOR_BUFFER_BIT)
   glRasterizerPos2d(8, 103)
   Text("Demo Polygon Script")

   ######### Parameters GUI Buttons
   glRasterPos2d(8, 83)
   Text("Parameters")
   T_NumberOfSides = Number("No. of sides: ", EVENT_NOEVENT, 10, 55, 210, 18
   T_NumberOfSides.val, 3, 20, "Number of sides of out polygon");
   T_radius = Slider(Radius: ", EVENT_NOEVENT, 10, 35, 210, 18,    
   T_Radius.val, 0.001, 20.0, 1, "Radius of the polygon");

   ######### Draw and Exit Buttons
   Button("Draw",EVENT_DRAW , 10, 10, 80, 18)
   Button("Exit",EVENT_EXIT , 140, 10, 80, 18)

def event(evt, val):
   if (evt == QKEY and not val):
      Exit()

def bevent (evt):
   global T_NumberOfSides
   global T_Radius
   global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT

   ######### Manages GUI events
 if (evt == EVENT_EXIT):
   Exit()
elif (evt== EVENT_DRAW):
   Polygon(T_NumberOfSides.val, T_Radius.val)
      Blender.Redraw()

Register(draw, event, bevent)

#####################################################
# Main Body
#####################################################
def Polygon(NumberOfSides,Radius):

######### Creates a new mesh
poly = NMesh.GetRaw()

#########Populates it of vertices
for i in range(0, NumberOfSides):
   phi = 3.141592653589 * 2 * i /NumberOfSides
   x = Radius * cos(phi)
   y = Radius * sin(phi)
   z = 0

   v = NMesh.Vert(x,y,z)
   poly.verts.append(v)

#########Adds a new vertex to the center
v = NMesh.vert(0.,0.,0.)
poly.verts.append(v)

#########Connects the verticies to form faces
for i in range(0,NumberOfSIdes):
  f = NMesh.Face()
  f.v.append(poly.verts[i])
  f.v.append(poly.verts[(i+1)%NumberOfSides
  f.v.append(poly.verts[numberofsides])
  poly.faces.append(f)

#########Creates a new Object with the new mesh
polyObj = NMesh.PutRaw(poly)

Blender.Redraw()

But when I run it, I get an error:


  File "PolyGen.py", line 50
     T_NumberOfSides.val, 3, 20, "Number of sides of outpolygon");
                   ^
SyntaxError: invalid syntax

I need some help here, as I am a total n00b to python.

Thanks!

Add a “,” at the end of the line 49.

I did that:

#####################################################
#
# Demo Script for Blender 2.3 Guide
#
##################################################S68
# This script generates polygons. It is quite useless
# scince you can do polygons with ADD->Mesh->Circle
# but it is a nice complete script example, and the
# polygons are `filled'.
#####################################################

#####################################################
# Importing modules
#####################################################

import Blender
from Blender import NMesh
from Blender.BGL import *
from Blender.Draw import *

import math
from math import *

# Polygon Parameteres
T_NumberOfSides = Create(3)
T_Radius

# Events
EVENT_NOEVENT = 1
EVENT_DRAW    = 2
EVENT_EXIT    = 3

#####################################################
# GUI drawing
#####################################################
def draw():
   global T_NumberOfSides
   global T_Radius
   global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT

   ########## Titles
   glClear(GL_COLOR_BUFFER_BIT)
   glRasterizerPos2d(8, 103)
   Text("Demo Polygon Script")

   ######### Parameters GUI Buttons
   glRasterPos2d(8, 83)
   Text("Parameters")
   T_NumberOfSides = Number("No. of sides: ", EVENT_NOEVENT, 10, 55, 210, 18,
   T_NumberOfSides.val, 3, 20, "Number of sides of out polygon");
   T_radius = Slider("Radius: ", EVENT_NOEVENT, 10, 35, 210, 18,   
   T_Radius.val, 0.001, 20.0, 1, "Radius of the polygon");

   ######### Draw and Exit Buttons
   Button("Draw",EVENT_DRAW , 10, 10, 80, 18)
   Button("Exit",EVENT_EXIT , 140, 10, 80, 18)

def event(evt, val):
   if (evt == QKEY and not val):
      Exit()

def bevent (evt):
   global T_NumberOfSides
   global T_Radius
   global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT

   ######### Manages GUI events
if (evt == EVENT_EXIT):
   Exit()
elif (evt== EVENT_DRAW):
   Polygon(T_NumberOfSides.val, T_Radius.val)
      Blender.Redraw()

Register(draw, event, bevent)

#####################################################
# Main Body
#####################################################
def Polygon(NumberOfSides,Radius):

######### Creates a new mesh
poly = NMesh.GetRaw()

#########Populates it of vertices
for i in range(0, NumberOfSides):
   phi = 3.141592653589 * 2 * i /NumberOfSides
   x = Radius * cos(phi)
   y = Radius * sin(phi)
   z = 0

   v = NMesh.Vert(x,y,z)
   poly.verts.append(v)

#########Adds a new vertex to the center
v = NMesh.vert(0.,0.,0.)
poly.verts.append(v)

#########Connects the verticies to form faces
for i in range(0,NumberOfSIdes):
  f = NMesh.Face()
  f.v.append(poly.verts[i])
  f.v.append(poly.verts[(i+1)%NumberOfSides
  f.v.append(poly.verts[numberofsides])
  poly.faces.append(f)

#########Creates a new Object with the new mesh
polyObj = NMesh.PutRaw(poly)

Blender.Redraw()

But now I get this:

  File "Text", line 72
    Blender.Redraw()
    ^

SyntaxError: invalid syntax

Try this instead:
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_modelmshapes.htm

I put it into Blender, ran it, and it did nothing.

There might be a soloution, but I don’t know french.

This is a learning experience for me, and I would really like to know what is going on! Please help me with my script.

that looks like you have semicolons, are you sure those are in the sample? Also you are missing a comman after the first 18


  T_NumberOfSides = Number("No. of sides: ", EVENT_NOEVENT, 10, 55, 210, 18
   T_NumberOfSides.val, 3, 20, "Number of sides of out polygon");
   T_radius = Slider(Radius: ", EVENT_NOEVENT, 10, 35, 210, 18,   
   T_Radius.val, 0.001, 20.0, 1, "Radius of the polygon"); 


   T_NumberOfSides = Number("No. of sides: ", EVENT_NOEVENT, 10, 55, 210, 18, T_NumberOfSides.val, 3, 20, "Number of sides of out polygon")
   T_radius = Slider(Radius: ", EVENT_NOEVENT, 10, 35, 210, 18, T_Radius.val, 0.001, 20.0, 1, "Radius of the polygon")

LetterRip

Hmm looking at the script, I guess there are semicolons there… odd never seen them before in a python script.

LetterRip

Semicolons are ignored if they are followed by a NEWLINE character. That was probably done to make frustrated C coders stop whining about “illogical python syntax”.

Martin

So nobody knows the problems? I still get errors!

Why don’t you just use the script from the CD?
It works.

Martin

Ok, ok.

I still would like to know what’s wrong, but I don’t need to know that badly.

Thanks

For one thing, if the code posted in your post is exactly what you are trying to run, it has a lot of indentation errors, syntax errors (missing square brackets and parenthesis) and one of the global variable is not declared properly.

Since you have access to the runnable version on the CD, why don’t you compare both side by side, you’ll see quickly why yours isn’t running.

Martin

Thanks.

I am not the best typer, that’s probably why that happened.

Thanks again!

I put it into Blender, ran it, and it did nothing.

There might be a soloution, but I don’t know french.

This is a learning experience for me, and I would really like to know what is going on! Please help me with my script.[/quote]

it is a module to create elementary shapes as cube, cylinder, polygon…
I added an autotest and some words in english.