I made a Docker image that can call FBX SDK Python from Node.js

I made a Docker image that can call FBX SDK Python from Node.js

For some reason, I had to call the FBX SDK Python from Node.js, so I created a Docker image.

The created Docker image is published below. https://hub.docker.com/r/seguropus/fbx-sdk-python-nodejs

Sample code

Place the sample code below. https://github.com/segurvita/docker-fbx-sdk-python-nodejs

How to use the sample code

#Build Docker image
docker-compose build

#Launch Docker container
docker-compose up

With this, if the following display appears, it is successful.

fbx-sdk-python-nodejs    | # FBX SDK can read the following formats.
fbx-sdk-python-nodejs    | 00 FBX (*.fbx)
fbx-sdk-python-nodejs    | 01 AutoCAD DXF (*.dxf)
fbx-sdk-python-nodejs    | 02 Alias OBJ (*.obj)
fbx-sdk-python-nodejs    | 03 3D Studio 3DS (*.3ds)
fbx-sdk-python-nodejs    | 04 Collada DAE (*.dae)
fbx-sdk-python-nodejs    | 05 Alembic ABC (*.abc)
fbx-sdk-python-nodejs    | 06 Biovision BVH (*.bvh)
fbx-sdk-python-nodejs    | 07 Motion Analysis HTR (*.htr)      
fbx-sdk-python-nodejs    | 08 Motion Analysis TRC (*.trc)      
fbx-sdk-python-nodejs    | 09 Acclaim ASF (*.asf)
fbx-sdk-python-nodejs    | 10 Acclaim AMC (*.amc)
fbx-sdk-python-nodejs    | 11 Vicon C3D (*.c3d)
fbx-sdk-python-nodejs    | 12 Adaptive Optics AOA (*.aoa)      
fbx-sdk-python-nodejs    | 13 Superfluo MCD (*.mcd)
fbx-sdk-python-nodejs    | 14 (*.zip)
fbx-sdk-python-nodejs exited with code 0

What you see is a list of file formats that the FBX SDK can read.

If you see this, you have successfully accessed the FBX SDK Python.

What's happening?

First, docker-compose up launches the Docker container.

Once started, the Docker container runs the Node.js code ʻindex.js`.

ʻIndex.js calls the Python code main.py`.

main.py gets a list of supported formats from the FBX SDK Python and displays it.

Dockerfile

There was a person who published a Docker image in which Python and Node.js lived together, so I created a Dockerfile based on that.

Dockerfile


# Python 2.7 and Node.Alpine with js 12
FROM nikolaik/python-nodejs:python2.7-nodejs12-alpine

#Library update with apk
RUN apk update && \
    apk add \
    curl \
    libxml2 \
    libstdc++

#Download FBX SDK
RUN curl -L \
    https://damassets.autodesk.net/content/dam/autodesk/www/adn/fbx/20195/fbx20195_fbxpythonsdk_linux.tar.gz \
    -o /tmp/fbx20195_fbxpythonsdk_linux.tar.gz

#Create installation folder
RUN mkdir -p /python-fbx/install

#Unzip the FBX SDK
RUN tar -zxvf \
    /tmp/fbx20195_fbxpythonsdk_linux.tar.gz \
    -C /python-fbx && \
    printf "yes\nn" | \
    /python-fbx/fbx20195_fbxpythonsdk_linux \
    /python-fbx/install

#Install FBX SDK
RUN cp /python-fbx/install/lib/Python27_ucs4_x64/* \
    /usr/local/lib/python2.7/site-packages/

# python-install shell
RUN npm install -g python-shell

#Delete temporary files
RUN rm -r /python-fbx
RUN rm /tmp/fbx20195_fbxpythonsdk_linux.tar.gz

#Environment variable NODE_Set PATH
ENV NODE_PATH /usr/local/lib/node_modules

python-shell is a library for calling Python from Node.js.

Since I installed it in the global area, I set the environment variable NODE_PATH so that index.js can be obtained with require.

docker-compose.yml

docker-compose.yml looks like this.

docker-compose.yml


version: '3'
services:
  fbx-sdk-python-nodejs:
    image: 'seguropus/fbx-sdk-python-nodejs'
    container_name: 'fbx-sdk-python-nodejs'
    build:
      context: ./
      dockerfile: ./Dockerfile
    volumes:
      - .:/src
    working_dir: /src
    command: node index.js

ʻIndex.js` is executed when the Docker container is started.

index.js

index.js looks like this.

index.js


const pythonShell = require('python-shell');

// python-shell options
const pyOption = {
    mode: 'text',
    pythonPath: '/usr/local/bin/python',
    pythonOptions: ['-u'],
    scriptPath: '/src',
}

// main.Run py
const pyShell = new pythonShell.PythonShell('main.py', pyOption);

//Show Python standard output
pyShell.on('message', (message) => {
    console.log(message);
});

//End processing
pyShell.end(function (err, code, signal) {
    if (err) {
        console.error(err);
    }
    console.log('The exit code was: ' + code);
});

I'm calling main.py with python-shell.

main.py

main.py looks like this.

main.py


from fbx import *


def list_reader_format(manager):
    print('# FBX SDK can read the following formats.')
    for formatIndex in range(manager.GetIOPluginRegistry().GetReaderFormatCount()):
        description = manager.GetIOPluginRegistry().GetReaderFormatDescription(formatIndex)
        print(formatIndex, description)


def main():
    # Create
    manager = FbxManager.Create()
    scene = FbxScene.Create(manager, "fbxScene")

    # List
    list_reader_format(manager)

    # Destroy
    scene.Destroy()
    manager.Destroy()


if __name__ == '__main__':
    main()

I'm loading the FBX SDK Python with from fbx import *. A function called list_reader_format () displays a list of file formats that the FBX SDK Python can read in standard output.

You have successfully created a Docker image that can call the FBX SDK Python from Node.js!

Try publishing to Docker Hub

It's a big deal, so I'll publish it to Docker Hub.

#log in
docker login

#Push Docker image
docker push seguropus/fbx-sdk-python-nodejs

Published below. https://hub.docker.com/r/seguropus/fbx-sdk-python-nodejs

at the end

In creating this article, I referred to the following pages. Thank you very much.

Recommended Posts

I made a Docker image that can call FBX SDK Python from Node.js
I made a package that can compare morphological analyzers with Python
I made a shuffle that can be reset (reverted) with Python
[python] I made a class that can write a file tree quickly
[Python] I made a utility that can access dict type like a path
I made a simple timer that can be started from the terminal
I made a module PyNanaco that can charge nanaco credit with python
I made a familiar function that can be used in statistics with Python
In Python, I made a LINE Bot that sends pollen information from location information.
I made a VM that runs OpenCV for Python
From a book that programmers can learn ... (Python): Pointer
I made a Docker Image that reads RSS and automatically tweets regularly and released it.
I made a python text
A mechanism to call a Ruby method from Python that can be done in 200 lines
From a book that programmers can learn ... (Python): About sorting
python Condition extraction from a list that I often forget
From a book that programmers can learn (Python): Decoding messages
I made a plug-in that can "Daruma-san fell" with Minecraft
I made a module that can be glitched easily, but I can't pass arguments from entry_points
Call a Python function from p5.js.
I made a Line-bot using Python!
I made a fortune with Python.
Docker image that can use cx_Oracle
I made a daemon with Python
[Python] I made a Line bot that randomly asks English words.
[First Ripple] [I am] Call JavaScript (Node.js) from Python and process Ripple
[Python3] I made a decorator that declares undefined functions and methods.
[Python] I made my own library that can be imported dynamically
From a book that programmers can learn (Python): Find the mode
From a book that programmers can learn ... (Python): Review of arrays
[Python] I made an image viewer with a simple sorting function.
I made a library that adds docstring to a Python stub file.
I made a Python wrapper library for docomo image recognition API.
From a book that programmers can learn (Python): Statistical processing-deviation value
I made a Line bot that guesses the gender and age of a person from an image
I made a garbled generator that encodes favorite sentences from UTF-8 to Shift-JIS (cp932) in Python
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
I created a template for a Python project that can be used universally
[Python] I made a decorator that doesn't seem to have any use.
I made a payroll program in Python!
I made a character counter with Python
I made a Discord bot in Python that translates when it reacts
From a book that programmers can learn (Python): Conditional search (maximum value)
I made a Hex map with Python
[Python] I made a function that can also use regular expressions that replace character strings all at once.
ConSinGAN: I tried using GAN that can be generated from one image
I made a tool that makes decompression a little easier with CLI (Python3)
[IOS] I made a widget that displays Qiita trends in Pythonista3. [Python]
After studying Python3, I made a Slackbot
Call a command from Python (Windows version)
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a LINE BOT that returns a terrorist image using the Flickr API
I made a Line Bot that uses Python to retrieve unread Gmail emails!
I made a library to operate AWS CloudFormation stack from CUI (Python Fabric)
From a book that programmers can learn (Python): Class declaration (public / private, etc.)
I want to create a priority queue that can be updated in Python (2.7)
I registered PyQCheck, a library that can perform QuickCheck with Python, in PyPI.
[Python] I made a LINE Bot that detects faces and performs mosaic processing.