# bRigid import workaround for Python Mode

**URL:** https://discourse.processing.org/t/brigid-import-workaround-for-python-mode/22402
**Category:** Gallery
**Created:** [July 5, 2020, 9:03pm UTC](https://discourse.processing.org/t/brigid-import-workaround-for-python-mode/22402 "2020-07-05T21:03:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [July 5, 2020, 9:03pm UTC](https://discourse.processing.org/t/brigid-import-workaround-for-python-mode/22402/1 "2020-07-05T21:03:17Z")

</div>

Arbitrarily picked bRigid’s “Box” example & converted it to “Python Mode”: 🐍

```auto
"""
 bRigid BBox (v1.0.4)
 by Daniel Köhler (2013)
 mod GoToLoop (2020-Jul-05)
 Discourse.Processing.org/t/brigid-import-workaround-for-python-mode/22402
"""

add_library('peasycam')

try: add_library('bRigid')
except: pass

# from bRigid import BPhysics, BBox, BObject
from javax.vecmath import Vector3f

def setup():
    size(800, 600, P3D)
    smooth(4)

    PeasyCam(this, 600)

    minv = Vector3f(-120, -250, -120)
    maxv = Vector3f(120, 250, 120)
    grav = Vector3f(0, 500, 0)

    global physics, bbox

    physics = BPhysics(minv, maxv)
    physics.world.gravity = grav

    bbox = BBox(this, 1, 15, 60, 15)

def draw(BG = -1, STEP = .01, FREQ = 10, posv = Vector3f()):
    displayTitle()

    background(BG)
    lights()
    rotateY(frameCount * STEP)

    if not frameCount % FREQ:
        posv.set(random(30), -150, random(1))
        physics.addBody(BObject(this, 100, bbox, posv, True))

    physics.update()
    physics.display()

def keyPressed(): clearAllBodies(physics)

def displayTitle(TITLE = 'Bodies: %d - FPS: %02.f'):
    this.surface.title = TITLE % (len(physics.rigidBodies), frameRate)

def clearAllBodies(phy):
    bodies = phy.rigidBodies
    world = phy.world

    for body in bodies:
        rb = body.rigidBody
        world.removeRigidBody(rb)
        rb.destroy()

    bodies.clear()

```

This is a workaround for @solub’s post from here:

> <https://github.com/jdf/Processing.py-Bugs/issues/300>
>
> Hi,
> I have the following error when trying to import the bRigid library in Python mode:
> sketch\_200701c.pyde:1: RuntimeWarning: PyTableCode.call caught a Throwable that...

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [July 5, 2020, 9:22pm UTC](https://discourse.processing.org/t/brigid-import-workaround-for-python-mode/22402/2 "2020-07-05T21:22:35Z")

</div>

I can’t thank you enough @GoToLoop.
