Python Api setup

1,888 views
Skip to first unread message

Derrick

unread,
Apr 11, 2016, 2:18:15 PM4/11/16
to OpenVSP
Is there a guide available that shows step by step on how to run VSP from python?
 
I found files that I believe set up the python API from here: https://github.com/OpenVSP/OpenVSP/tree/master/src/python_api, but am having a hard time integrating them. 
 
Where do the .i files go? Should I put them in python's home directory?
What does CMakeLIsts.txt do?
Am I even on the right path?
 
My goal is to be able to create vsp model based on inputs that I feed to vsp from a seperate program all through python.
 
I prefer to use python over .vspscripts because I will eventually be calling vsp from an already established program that is written in python and would like to keep the languages consistent.
 
Thanks for the help,
Derrick

Rob McDonald

unread,
Apr 12, 2016, 10:16:52 PM4/12/16
to OpenVSP
You are on the right path - and this is what the Python API is intended for.

We don't have the ability right now to distribute a pre-compiled library for use from Python.  Instead, you have to be able to compile OpenVSP yourself.

So, the first step to using the Python API for OpenVSP is to compile OpenVSP on the machine you want to do this sort of thing...

Rob

Brent Robbins

unread,
Apr 13, 2016, 12:03:35 AM4/13/16
to ope...@googlegroups.com
Sorry I have been out of the loop for a while.  I thought OpenVSP used angelscript as the language for its API.  It can now do Python?



From: Rob McDonald <rob.a.m...@gmail.com>
To: OpenVSP <ope...@googlegroups.com>
Sent: Tuesday, April 12, 2016 7:16 PM
Subject: [OpenVSP] Re: Python Api setup

--
You received this message because you are subscribed to the Google Groups "OpenVSP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openvsp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Nick Brake

unread,
Apr 13, 2016, 12:20:37 AM4/13/16
to OpenVSP, brenta...@yahoo.com
B-Rob,
VSP uses SWIG to wrap the C++ api and interface with python.  It works pretty well.

Brent Robbins

unread,
Apr 13, 2016, 12:25:15 AM4/13/16
to ope...@googlegroups.com
Thanks for the response, Nick!  Where does angelscript come into play then?



From: Nick Brake <nbr...@gmail.com>
To: OpenVSP <ope...@googlegroups.com>
Cc: brenta...@yahoo.com
Sent: Tuesday, April 12, 2016 9:20 PM
Subject: Re: [OpenVSP] Re: Python Api setup

Nick Brake

unread,
Apr 13, 2016, 12:27:01 AM4/13/16
to OpenVSP
I recently got the python api working for some of my projects and can also help if you get stuck.  keep posting on how far you've gotten as this seems to be a popular question and others can follow this thread.

nick

Rob McDonald

unread,
Apr 13, 2016, 1:33:49 AM4/13/16
to ope...@googlegroups.com
Angelscript is built in. It is used for custom components and for
advanced parameter linking.

We also have a C++ API. You can treat the geometry core of OpenVSP as
a library that can be linked with any C++ program.

SWIG is a semi-automatic wrapper generator that can wrap a C/C++ API
with a wide variety of scripting languages. OpenVSP includes support
for SWIG/Python in the build system.

SWIG can also be used to generate wrappers for Java and lots of other
languages. Hopefully they will support direct wrapping to Matlab in
the nearish future.

Since the library that SWIG binds to is a compiled shared library
(.dll or .so), you need a close match between your installed Python
and OpenVSP. Since we don't control which Python you have on your
machine, you must build OpenVSP yourself in order to use any SWIG
wrapper.

Since we had a built in scripting language, it made sense to connect
it to the API as well. So, we also made a scripting capability based
on Angelscript and exposed everything you can do through the API to
the built in scripting.

So, here is the general idea...

If you want to automate OpenVSP in a quick-and-dirty way, or if
OpenVSP will be used mostly in isolation (perhaps shell script
integration) then it is probably easiest to use Angelscript to write a
*.vspscript file. You can execute them from the GUI. You can
distribute them to your friends. You don't need any compiler,
interpreter, or anything outside of OpenVSP itself.

If you're connecting OpenVSP into some sort of larger framework, then
you'll want to look at using the C++ API or one of its wrapped
versions. If you have a framework in Python, then by all means, use
the Python wrapper.

Of course, for custom components or advanced parameter linking,
Angelscript is the only way to go.

I hope this helps,

Rob

Santiago Balestrini Robinson

unread,
Apr 13, 2016, 10:31:17 AM4/13/16
to OpenVSP
I've had some mixed success building the Python API.  The following is a docker layer that may provide some clues.  THis has been the most robust way for us to build this, but note that it presumes you are using Anaconda and you have it at /opt/conda:

# install and build openvsp
RUN set -x \
&& yum install -y epel-release
&& yum install -y gcc-c++ git make swig unzip \
libxml2 fltk cpptest glew libstdc++-static \
libxml2-devel \
cpptest-devel eigen3-devel glm-devel cminpack-devel \
&& yum clean all \
# Link include and libs for Python API. The CMake file doesn't seem to
# read the environment variables, and the setting of the paths in the
# CMakeFileLists.txt for the API doesn't work right. This does it
&& ln -s /opt/conda/include/python3.5m /usr/include/python3.5m \
&& ln -s /opt/conda/lib/libpython3.so /usr/lib64/libpython3.5m.so \
# get most recent cmake
&& curl -L https://cmake.org/files/v3.5/cmake-3.5.0-Linux-x86_64.tar.gz | \
tar -C /usr/local -xvaz --strip-components=1 -f - \
# Download and Build OpenVSP
&& mkdir OpenVSP; cd OpenVSP \
&& mkdir build; mkdir repo \
&& git clone https://github.com/OpenVSP/OpenVSP.git repo \
&& cd build \
&& cmake -DCMAKE_BUILD_TYPE=Release -DVSP_NO_GRAPHICS=true \
-DVSP_USE_SYSTEM_FLTK=true -DVSP_USE_SYSTEM_CPPTEST=true \
-DVSP_USE_SYSTEM_LIBXML2=true -DVSP_USE_SYSTEM_EIGEN=true \
-DVSP_USE_SYSTEM_GLM=true -DVSP_USE_SYSTEM_GLEW=true \
-DVSP_USE_SYSTEM_CMINPACK=true \
../repo/SuperProject \
&& make \
# install OpenVSP and the python_api
&& unzip ./OpenVSP-prefix/src/OpenVSP-build/OpenVSP-3.5.2-Linux -d /usr/local/bin \
&& pushd OpenVSP-prefix/src/OpenVSP-build/src/python_api/ \
&& mkdir /opt/conda/lib/python3.5/site-packages/openvsp \
&& cp vsp.py _vsp.so /opt/conda/lib/python3.5/site-packages/openvsp \
&& popd \
# TODO: clean up /OpenVSP if the files are not needed after building and
# installing the binaries/python api (add line continuation above)
&& cd / && rm -rf /OpenVSP \
# add OpenVSP to the path
&& export PATH=$PATH:/usr/local/bin/OpenVSP-3.5.2-Linux/

the whole symlink issue is there to try to resolve a problem we were having with SWIG not finding the correct python.  I tried setting the environment variables but to no avail so we had to resort to this contraption.

I hope to understand CMAKE better and provide you all with a cleaner and more robust script.  Other caveats:  there may be other dependencies that exist in other dockerfiles, but i cannot share those yet...  would be glad to answer any questions/concerns or share ideas.

Also, if you are interested, I started prototyping a more abstracted and pythonic API built on top of the SWIG interface.


and a "tutorial" notebook here: https://github.com/sanbales/OpenVSP/blob/python_api/src/python_api/Tutorial.ipynb which tries to do other things, like render the vehicle in the notebook using threejs.

Cheers,

-Santiago

Karthik Mahesh

unread,
Sep 6, 2018, 9:10:10 AM9/6/18
to OpenVSP
Which version of OpenVSP can Python use? Is it compatible with Python 2.7? I noticed you're using 3.5.

Cheers,
Karthik

Rob McDonald

unread,
Sep 6, 2018, 12:10:53 PM9/6/18
to ope...@googlegroups.com
If you compile your own wrapper, then it will use whatever version of Python you build against (2.7 or 3.X).  The wrapper included with the OpenVSP *.zip file is built against 3.5.

Rob

Connor Sun

unread,
Feb 25, 2019, 4:00:16 AM2/25/19
to OpenVSP
Hi Rob,
     I’m a beginner to OpenVSP and have found OpenVSP extremely useful and easy. I appreciate your effort in OpenVSP and the Anaconda Python bindings. Much time is saved.
     When trying your wrapper included with the OpenVSP *.zip file, I find that perhaps the wapper was built against python 3.6 instead of 3.5. The Anaconda (Anaconda3-5.0.1-Windows-x86.exe) you mentioned at this post has Python 3.6 as default. And when I try the test.py with python 3.5, it reports ImportError like this:
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 19:24:31) [MSC v.1900 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 6.5.0 -- An enhanced Interactive Python.

run test.py
Traceback (most recent call last):

  File "E:\OpenVSP-3.16.2\python\test.py", line 4, in <module>
    import vsp as vsp

  File "E:\OpenVSP-3.16.2\python\vsp.py", line 17, in <module>
    _vsp = swig_import_helper()

  File "E:\OpenVSP-3.16.2\python\vsp.py", line 16, in swig_import_helper
    return importlib.import_module('_vsp')

  File "C:\ProgramData\Anaconda3\envs\py35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

ImportError: DLL load failed: The specified procedure could not be found.
In python 3.6, ‘run test.py’ returns as follow, which indicates the success of the Python API. Am I right?
Python 3.6.8 |Anaconda custom (32-bit)| (default, Feb 11 2019, 15:50:09) [MSC v.1915 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 7.2.0 -- An enhanced Interactive Python.

run test.py
SET_ALL =  0
SET_SHOWN =  1
SET_NOT_SHOWN =  2
SET_FIRST_USER =  3
EXPORT_FELISA =  0
EXPORT_XSEC =  1
EXPORT_STL =  2
EXPORT_AWAVE =  3
EXPORT_NASCART =  4
EXPORT_POVRAY =  5
EXPORT_CART3D =  6
EXPORT_VORXSEC =  7
EXPORT_XSECGEOM =  8
EXPORT_GMSH =  9
EXPORT_X3D =  10
EXPORT_STEP =  11
VSP_OK =  0
VSP_INVALID_PTR =  1
VSP_CANT_FIND_TYPE =  3
VSP_CANT_FIND_PARM =  4
VSP_CANT_FIND_NAME =  5
VSP_INVALID_GEOM_ID =  6
VSP_FILE_DOES_NOT_EXIST =  7
VSP_FILE_WRITE_FAILURE =  8
VSP_WRONG_XSEC_TYPE =  10
VSP_WRONG_FILE_TYPE =  11
VSP_INDEX_OUT_RANGE =  12
VSP_INVALID_XSEC_ID =  13
VSP_INVALID_ID =  14
VSP_CANT_SET_NOT_EQ_PARM =  15
SYM_XY =  1
SYM_XZ =  2
SYM_YZ =  4
SYM_ROT_X =  8
SYM_ROT_Y =  16
SYM_ROT_Z =  32
SYM_PLANAR_TYPES =  3
SYM_NUM_TYPES =  6
XSEC_FUSE =  0
XSEC_STACK =  1
XSEC_WING =  2
XSEC_CUSTOM =  3
XSEC_NUM_TYPES =  5
X_DIR =  0
Y_DIR =  1
Z_DIR =  2
XS_SHIFT_LE =  0
XS_SHIFT_MID =  1
XS_SHIFT_TE =  2
XS_POINT =  0
XS_CIRCLE =  1
XS_ELLIPSE =  2
XS_SUPER_ELLIPSE =  3
XS_ROUNDED_RECTANGLE =  4
XS_GENERAL_FUSE =  5
XS_FILE_FUSE =  6
XS_FOUR_SERIES =  7
XS_SIX_SERIES =  8
XS_BICONVEX =  9
XS_WEDGE =  10
XS_BEZIER =  11
XS_FILE_AIRFOIL =  12
XS_NUM_TYPES =  19
XSEC_BOTH_SIDES =  0
XSEC_LEFT_SIDE =  1
XSEC_RIGHT_SIDE =  2
IMPORT_STL =  0
IMPORT_NASCART =  1
IMPORT_CART3D_TRI =  2
IMPORT_XSEC_MESH =  3
IMPORT_PTS =  4
NO_FILE_TYPE        =  0
COMP_GEOM_TXT_TYPE  =  1
COMP_GEOM_CSV_TYPE  =  2
DRAG_BUILD_TSV_TYPE =  4
SLICE_TXT_TYPE      =  8
MASS_PROP_TXT_TYPE  =  16
DEGEN_GEOM_CSV_TYPE =  32
DEGEN_GEOM_M_TYPE   =  64
CFD_STL_TYPE =  128
CFD_POLY_TYPE =  256
CFD_TRI_TYPE =  512
CFD_OBJ_TYPE =  1024
CFD_DAT_TYPE =  2048
CFD_KEY_TYPE =  4096
CFD_GMSH_TYPE =  8192
CFD_SRF_TYPE =  16384
CFD_TKEY_TYPE =  32768
INT_DATA =  0
DOUBLE_DATA =  1
STRING_DATA =  2
VEC3D_DATA =  3
MESH_INDEXED_TRI =  0
MESH_SLICE_TRI =  1
GEOM_XSECS =  2
CFD_STL_FILE_NAME =  0
CFD_POLY_FILE_NAME =  1
CFD_TRI_FILE_NAME =  2
CFD_OBJ_FILE_NAME =  3
CFD_DAT_FILE_NAME =  4
CFD_KEY_FILE_NAME =  5
CFD_GMSH_FILE_NAME =  6
CFD_SRF_FILE_NAME =  7
CFD_TKEY_FILE_NAME =  8
CFD_NUM_FILE_NAMES =  12
CFD_MIN_EDGE_LEN =  0
CFD_MAX_EDGE_LEN =  1
CFD_MAX_GAP =  2
CFD_NUM_CIRCLE_SEGS =  3
CFD_GROWTH_RATIO =  4
CFD_LIMIT_GROWTH_FLAG =  5
CFD_INTERSECT_SUBSURFACE_FLAG =  6
CFD_HALF_MESH_FLAG =  7
CFD_FAR_FIELD_FLAG =  8
CFD_FAR_MAX_EDGE_LEN =  9
CFD_FAR_MAX_GAP =  10
CFD_FAR_NUM_CIRCLE_SEGS =  11
CFD_FAR_SIZE_ABS_FLAG =  12
CFD_FAR_LENGTH =  13
CFD_FAR_WIDTH =  14
CFD_FAR_HEIGHT =  15
CFD_FAR_X_SCALE =  16
CFD_FAR_Y_SCALE =  17
CFD_FAR_Z_SCALE =  18
CFD_FAR_LOC_MAN_FLAG =  19
CFD_FAR_LOC_X =  20
CFD_FAR_LOC_Y =  21
CFD_FAR_LOC_Z =  22
CFD_WAKE_SCALE =  23
CFD_WAKE_ANGLE =  24
POINT_SOURCE =  0
LINE_SOURCE =  1
BOX_SOURCE =  2
NUM_SOURCE_TYPES =  5
XDDM_VAR =  0
XDDM_CONST =  1
NORMAL_SURF =  0
WING_SURF =  1
NUM_SURF_TYPES =  4
SS_LINE =  0
SS_RECTANGLE =  1
SS_ELLIPSE =  2
SS_NUM_TYPES =  5
AR_WSECT_DRIVER =  0
SPAN_WSECT_DRIVER =  1
AREA_WSECT_DRIVER =  2
TAPER_WSECT_DRIVER =  3
AVEC_WSECT_DRIVER =  4
ROOTC_WSECT_DRIVER =  5
TIPC_WSECT_DRIVER =  6
SECSWEEP_WSECT_DRIVER =  7
NUM_WSECT_DRIVER =  8
SWEEP_WSECT_DRIVER =  8
SWEEPLOC_WSECT_DRIVER =  9
SECSWEEPLOC_WSECT_DRIVER =  10
('POD', 'FUSELAGE', 'WING', 'STACK', 'BLANK', 'ELLIPSOID', 'BODYOFREVOLUTION', 'PROP', 'HINGE', 'CONFORMAL')
All geoms in Vehicle.
('PQUAYWKAMT', 'RLPWWTLWCX', 'BMJPVFTEWA')
All geoms in Vehicle.
()
End of second use case, all geoms in Vehicle.
('FBBTWFUNUC',)
Start of third use case, read in first-case file.
All geoms in Vehicle.
('PQUAYWKAMT', 'RLPWWTLWCX', 'BMJPVFTEWA')
 Thanks for the help,
 Connor.

Rob McDonald

unread,
Feb 25, 2019, 10:52:23 AM2/25/19
to ope...@googlegroups.com
I think the confusion stems from the file name 'Anaconda3-5.0.1-Windows-x86.exe'.  Note the hyphen.

That file contains 'Anaconda3' version 5.0.1.  Which happens to be based on Python 3.6 -- not 3.5.

Yes, it appears that everything is working the way it should for you with 3.6.

Rob

--
Reply all
Reply to author
Forward
0 new messages