Recommended Posts

Hello,

It's my first post here, so please be gentle 🙂

I wanted to create my first script in Vectorworks using Python, simple Random Walker like this:

import random

size = 50
posX = 0
posY = 0
steps = 100

for i in range(steps):
vs.Rect(posX, posY, posX + size, posY + size)
r = random(4)
if r == 0:
posX += size
posY += size
if r == 1:
posX -= size
posY += size
if r == 2:
posX -= size
posY -= size
if r == 3:
posX += size
posY -= size

How can I create random int number in range 0 - 3 (0, 1, 2, 3).  Same code runs in processing.

There is this method in python, but it does not work in Vectorworks.

randrange ([start,] stop [,step])

Thanks for any help!

Hello,

maybe you simply forgaot the "namespace" try this:

import random
print ( random.randrange (0, 500, 3) )

• 1

Maybe this will help - you need to use "random.randrange(value)"

import random

size = 50
posX = 0
posY = 0
steps = 100

for i in range(steps):
vs.Rect(posX, posY, posX + size, posY + size)
r = random.randrange(4) #corrected to include namespace
if r == 0:
posX += size
posY += size
if r == 1:
posX -= size
posY += size
if r == 2:
posX -= size
posY -= size
if r == 3:
posX += size
posY -= size
• 1

Thank you you PatW and Marissa, it's working now 🙂

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×

• KBASE