Skip to content
master
MaxMSP-Interfacing/MaxMSP Interfacing AxiDraw (Python)/
MaxMSP-Interfacing/MaxMSP Interfacing AxiDraw (Python)/

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

README.md

MaxMSP Interfacing AxiDraw (Python)

The word "Interfacing" is here primarily understood as a process of establishing interoperational constitution between Max/MSP and other programming languages. In this part we will examine the interfacing between Max/MSP and an AxiDraw XY plotter through Python.

Set-up

In this guide I assume that the reader has already worked with AxiDraw through the inkscape software, and is familiar with using it to plot .svg. Thus we wont be covering all of the necessary first time quick setup which is covered extensivly throughout this guide

On page 17 of the guide, the reader will have come accross "3.3 Aside: Alternative software, CLI, and API's". in this section, it becomes apparent to the user of the AxiDraw that there are other ways of controlling the plotter than using inkscape.

There is a stand-alone command-line interface (CLI) tool, as well as a full-featured python library. You can learn more about these tools at:

CLI

Python

In this guide we will mainly be focusing on using the python library to control the AxiDraw, and try to combine the python library with Max/MSP.

Download and unzip this folder on your computer.

In the unzipped folder there is another named "AxiDraw_API_v256" where the rest of the elements are located for using python with Axidraw.

Installing the Python-AxiDraw-Api

  • Install Python on your computer if you don't already have it available. This can be checked by typing in "python --version" into your Terminal or CMD.
  • You will also need to have Pip installed which is Pythons package manager. Again you can check if you already have this on your computer by typing "pip --version" into your terminal or CMD.
    • if pip is not installed you can type in "sudo easy_install pip" into your terminal or CMD. This will install pip on your computer

Installing dependencies

  • Use pip to install pyaxidraw og axicli
    • in Terminal or CMD write "cd /Users/username/Documents/axidraw-api/ (Your location and path will vary)"
    • write "pip install"
    • write "pip install -r requirements.txt"

Python interactive

open /AxiDraw_API_v256/test_Interactive.py in a text-editor that can run python-scripts. in this guide I will be using ATOM.

from pyaxidraw import axidraw   # import module
ad = axidraw.AxiDraw()          # Initialize class
ad.interactive()                # Enter interactive context
ad.connect()                    # Open serial port to AxiDraw
                                # Absolute moves follow:
ad.moveto(1,4)                  # Pen-up move to (1 inch, 1 inch)
ad.lineto(2,1)                  # Pen-down move, to (2 inch, 1 inch)
ad.moveto(0,0)                  # Pen-up move, back to origin.
ad.disconnect()                 # Close serial port to AxiDraw

Connect your computer and power-cable to the plotter and compile the python script.

If you have installed and connected everything correctly then you should see the plotter move. If not go back and check that everything has been done according to the installation guide.

The question is now, how can we connect the Python script to Max/MSP in a way that makes sense?

In order to establish a connection between max/MSP and python we need to use the Node for max framework and an npm package called python-shell which can be installed by writing "npm install python-shell" in the terminal or CMD

then we must create two files a Hello.py, and a javascript file containing the necessary code to establish a connection we will call this python.js.

Hello.py contains

import sys

# defining X/Y for pen-up and pen-down
xlin = sys.argv[1]
ylin = sys.argv[2]
xmov = sys.argv[3]
ymov = sys.argv[4]


print("Pen-Down", xlin, ylin) #ad.lineto(x,y)

print("Pen-Up",xmov, ymov) #ad.moveto(x,y)

python.js contains

const maxApi = require('max-api');
let {
  PythonShell
} = require('python-shell')

let args = 'insert';

maxApi.addHandler('input', (xlin, ylin, xmov, ymov) => {
  //maxApi.outlet(vari);

  let options = {
    mode: 'text',
    pythonPath: '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3',
    pythonOptions: ['-u'], // get print results in real-time
    scriptPath: '/Users/Pacour/Developer/Aufbau/MaxMSP Interfacing AxiDraw (Python)/Code',
    args: [xlin, ylin, xmov, ymov]
  };

  PythonShell.run('Interactive.py', options, function(err, results) {
    if (err) throw err;
    //results is an array consisting of messages collected during execution
    maxApi.outlet(results);
  });
});

Now that the files are done we can move on to the max-patcher.

  • make a new patcher, and save it as a project within the folder where the other .js and .py scripts are located.

Max/MSP patcher

----------begin_max5_patcher----------
1619.3ocyZs0iaZDE9Y6eEi3oTIuTlKbKUpJQMu1pHUUoV0TYgsGu6jEyffw
d81n7euyEvKNKFyU23UKBFF3b9ly8yvWlOyZE+HM2B7VveClM6KymMSOjZfY
EWOyZWzw0wQ45oYsluaGMQXsvbOA8nPO9uvSx4wzxwS1uiuWDSE5mxoXzzHw
5GXI2uLitVXnpmcP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