Skip to the page
Tutorial areas

Write a script that draws a grid of posts

Write a short Python script in the Run Script window that draws a grid of square posts at set spacing, then run it and undo it in one step.

TutorialIntermediate10 minMenu: Tools › Plug-ins › Run Script…

A script is the quickest way to draw a repeated pattern, such as the posts of a car park, the columns of a hall or the holes in a panel. This tutorial writes one: twelve solid square posts, four across and three down, 3 m apart. You will see the grid in the drawing and undo it in one step.

The picture at the top is the drawing after the script has run.

Twelve orange posts in a grid of four across and three down

What you need

A drawing open in Rodeo. The steps use a new, empty drawing in millimetres. You do not need to know Python beyond what is below. The script imports vs, the module that holds Vectorworks' drawing calls, and calls them as Python functions.

Steps

  1. Choose Tools › Plug-ins › Run Script…. The window opens with a sample script in it.

    The Run Script window with its sample script
  2. Click in the script box, press ⌘A to select the sample, and type this in its place:

    import vs
    
    # a grid of posts: 4 across and 3 down, 3 m apart, each 300 mm square
    vs.FillPat(1)
    vs.FillFore(65535, 25000, 0)
    vs.FillBack(65535, 25000, 0)
    for i in range(4):
        for j in range(3):
            x = i * 3000
            y = j * 3000
            vs.Rect(x, y, x + 300, y + 300)
    vs.Message("Drew 12 posts")
    
    The Run Script window with the grid script typed in
  3. Click Run. The grey log under the script says what happened: the script ran, drew twelve posts and made one undo step.

    The log: Drew 12 posts, and Done: 12 changes, one undo step
  4. Close the window with × and look at the drawing. Twelve squares, 300 mm across, sit on a grid 3 m apart.

How the script works

  • vs.FillPat(1) makes the shapes solid. vs.FillFore and vs.FillBack give the colour as red, green and blue, each from 0 to 65535, and Rodeo uses the nearest colour in the drawing's palette. Here the colour is orange.
  • The two for lines repeat the drawing lines for each column (i) and each row (j). Each pass moves the post 3000 mm along, so the spacing is 3 m.
  • vs.Rect draws a rectangle from one corner to the other, in the drawing's units. The posts are 300 mm, so each runs from x to x + 300.
  • vs.Message writes the line in the log.

Try next

  • Change the 4 and the 3 in the two range lines to draw a bigger or smaller grid, then run again.
  • Change 3000 to the spacing you need, or 300 to the post size.
  • Press ⌘Z once after a run. All the posts go at once, because the run is one undo step.
  • To keep the script, click Save in the Run Script window. Open… loads it again. To run it with a double-click, put it in a script palette: see Scripts.

Limits

  • A solid fill (FillPat(1)) is drawn in its back colour, in Vectorworks as well as in Rodeo, so the script sets FillBack. FillFore colours a solid fill only with FillPat(2), Solid Foreground.
  • Rodeo has more than 1,100 of Vectorworks' 3,250 calls. A call it lacks says so by name in the log.