#1
|
|||
|
|||
Import viz from c++
Hello,
I wrote my Vizard (5.0) program in py and every work perfectly. Right now, I'm trying to write a program c++ that load the python code and call all the different functions that I wrote (using Python.h). Everything works fine if I don't import any vizard module but if in my python code I have one or more import viz (or related) the python return this error: "viz module can only be imported by Vizard". Can anyone help me? this is my code python: Code:
import sys sys.path.append('C:/Program Files/WorldViz/Vizard5/python') import viz def add(a, b): return a+b Code:
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string> #ifdef _DEBUG #undef _DEBUG #include <Python.h> #define _DEBUG #else #include <Python.h> #endif static const char* PLUGIN_NAME = "Sample"; void PrintTotalRefCount() { #ifdef Py_REF_DEBUG PyObject* refCount = PyObject_CallObject(PySys_GetObject((char*)"gettotalrefcount"), NULL); std::clog << "total refcount = " << PyInt_AsSsize_t(refCount) << std::endl; Py_DECREF(refCount); #endif } std::string CallPlugIn(const std::string& ln) { PyObject* name = PyString_FromString(PLUGIN_NAME); PyObject* pluginModule = PyImport_Import(name); Py_DECREF(name); if (!pluginModule) { PyErr_Print(); return "Error importing module"; } PyObject* filterFunc = PyObject_GetAttrString(pluginModule, "filterFunc"); Py_DECREF(pluginModule); if (!filterFunc) { PyErr_Print(); return "Error retrieving 'filterFunc'"; } PyObject* args = Py_BuildValue("(s)", ln.c_str()); if (!args) { PyErr_Print(); Py_DECREF(filterFunc); return "Error building args tuple"; } PyObject* resultObj = PyObject_CallObject(filterFunc, args); Py_DECREF(filterFunc); Py_DECREF(args); if (!resultObj) { PyErr_Print(); return "Error invoking 'filterFunc'"; } const char* resultStr = PyString_AsString(resultObj); if (!resultStr) { PyErr_Print(); Py_DECREF(resultObj); return "Error converting result to C string"; } std::string result = resultStr; Py_DECREF(resultObj); return result; } int main(int argc, char* argv[]) { Py_Initialize(); PyObject* sysPath = PySys_GetObject((char*)"path"); PyObject* curDir = PyString_FromString("."); PyList_Append(sysPath, curDir); Py_DECREF(curDir); std::string input; CallPlugIn(input); PrintTotalRefCount(); Py_Finalize(); system("PAUSE"); return 0; } |
Tags |
c++, import, vizard 5.0 |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Unable to draw EyeLink drift correction to screen | chris2307 | Vizard | 6 | 08-18-2014 02:22 PM |
Problems with using WIRKS without the Kinect in a mirror setting | Jennifer | Vizard | 0 | 06-03-2013 03:17 PM |
Import 3DS to Vizard | suwan116 | Vizard | 1 | 05-09-2011 01:28 PM |
Best way to import map data from 3ds Max | v-Salik | Vizard | 6 | 04-09-2010 04:40 AM |
Pick porblem with arrays | shivanangel | Vizard | 3 | 08-27-2007 10:10 AM |