# Using the python interpreter included with CMB and aevaCMB

**URL:** https://discourse.kitware.com/t/using-the-python-interpreter-included-with-cmb-and-aevacmb/620
**Category:** Tips and Tricks
**Created:** [March 19, 2021, 9:52pm UTC](https://discourse.kitware.com/t/using-the-python-interpreter-included-with-cmb-and-aevacmb/620 "2021-03-19T21:52:15Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)
#### Post date: [March 19, 2021, 9:52pm UTC](https://discourse.kitware.com/t/using-the-python-interpreter-included-with-cmb-and-aevacmb/620/1 "2021-03-19T21:52:15Z")

</div>

## Packaged python

If you download a [Kitware-generated package of aevaCMB](https://data.kitware.com/#collection/5e387f9caf2e2eed3562242e/folder/5e3888e3af2e2eed35628e50) or CMB, it will come with a `pvpython` executable (in `aevaCMB.app/Contents/bin` on macos, in `bin/pvpython` on linux, and in `bin/pvpython.exe` on windows). You can use this python interpreter as you would any other; the difference is that it sets up the paths so that CMB plugins can be loaded.

## Loading an SMTK resource

You can run `pvpython` on the command line and do things like load SMTK files. The script below will load the example data that comes in the aevaCMB package and print a list of surfaces.

First, we import the `paraview.simple` module so we can load plugins and the smtk modules needed for operations:

```python
import paraview.simple
import smtk
import smtk.attribute
import smtk.model
import smtk.operation
import smtk.plugin

# Some files included in the aevaCMB download:
aevaPluginPath = '/path/to/smtkAEVASessionPlugin.so'
aevaExamplePath='/path/to/femur_acl_tibia.smtk'

```

Now load aeva functionality:

```python
# Load the aeva "session" plugin.
# This plugin provides aeva with a resource type and operations.
paraview.simple.LoadPlugin(aevaPluginPath)
# Create an operation manager (a registry of operations)
opMgr = smtk.operation.Manager.create()
# It is empty by default:
opMgr.availableOperations()

# Tell the SMTK plugin system to populate the manager:
smtk.plugin.registerPluginsTo(opMgr)
opMgr.availableOperations()
# Returns a long list including smtk::session::aeva::Read

```

Create an SMTK operation to read the example data, set the filename, and run it:

```python
readOp = opMgr.createOperation('smtk::session::aeva::Read')
readOp.parameters().findFile('filename').setValue(aevaExamplePath)
res = readOp.operate()

# Check that the operation succeeded:
res.findInt('outcome').value() == int(smtk.operation.Operation.SUCCEEDED)
# Should return True

```

Finally, we can get information from the operation result and ask the resource about its components:

```python
# Get the resource created by the Read operation.
rsrc = res.findResource('resource').value(0)

# rsrc now holds an aeva resource whose components
# include the 3 models in the file (femur, tibia, and ACL).
# We can get a list of all the components:
rsrc.find('*')
# or just the surfaces:
faces = rsrc.find('face')
# We can print their names
names = [x.name() for x in faces]
names.sort()
print('\n'.join(names))
# Should print:
# ACL_FMB_insertion
# ACL_TBB_insertion
# FMB_ACL_insertion
# TBB_ACL_insertion
# face 5
# face 6
# face 7

```

Fancier queries are available and [described in the SMTK documentation](https://smtk.readthedocs.io/en/latest/userguide/model/concepts.html#filtering-and-searching).  
Once you have components of interest, you can create additional operations to select regions, add attributes, and export your processed data.
