WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-03-2016, 01:38 PM
Ciccio Ciccio is offline
Member
 
Join Date: Jun 2016
Posts: 6
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
and this is my main c++
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;
}
Reply With Quote
  #2  
Old 06-05-2016, 08:39 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You can extend Vizard/Python code with C++ code but I'm not sure it's possible to call Vizard modules from a C++ application. Can you describe what you would like to accomplish and I can check further with a developer? Also, take a look at the Vizard SDK docs, this maybe helpful.
Reply With Quote
  #3  
Old 06-06-2016, 04:20 AM
Ciccio Ciccio is offline
Member
 
Join Date: Jun 2016
Posts: 6
Quote:
Originally Posted by Jeff View Post
You can extend Vizard/Python code with C++ code but I'm not sure it's possible to call Vizard modules from a C++ application. Can you describe what you would like to accomplish and I can check further with a developer? Also, take a look at the Vizard SDK docs, this maybe helpful.
I want to create a sort of virtual programming language (like this) in c++ and I would like to call vizard function in my code c++ to make some action like: add an avatar, move etc.. does it exist some other ways to do this?
Reply With Quote
  #4  
Old 06-06-2016, 06:16 AM
Ciccio Ciccio is offline
Member
 
Join Date: Jun 2016
Posts: 6
I think I figured out how to call Viz using SDK (a mix of buttonDown and command, I will post my code once I will finish it) but right now I have another question, is it possible to add an c++ extension from a dll and not a dle? I just found this
Reply With Quote
  #5  
Old 06-07-2016, 03:21 PM
Ciccio Ciccio is offline
Member
 
Join Date: Jun 2016
Posts: 6
I think I'm getting closer, I created my own extension and from it I load the sensor but I've got a problem:
CExtension.cpp
Code:

extern "C" __declspec(dllexport) viz::Extension* CreateVizardExtension(viz::Data &data)
{
	return new CExtension();
}

viz::Referenced* CExtension::createSensor(viz::Data &data)
{
	int command = data.getInt("command");
	return CSensor::Instance();
}
here is the code of CSensor
Code:
CSensor* CSensor::singleton = NULL;

CSensor::CSensor()
{
	setDataSize(10);
	setVision(false);
	setOculus(true);
	setGyroscope(false);
	setSpeed(1);
	m_data[ISREADY] = VizENum::Off;
}

void CSensor::command(viz::Data &data)
{
	switch (data.getInt("command")) {
	default:
		break;
	case ERRORVIZARD:
		setConnected(false);
		break;
	case ACKNOLEDGECOMMAND:
		setAcknoledge(true);
		break;
	case DATACOMMANDR:
		setDataR(data.getFloat("x"),
			data.getFloat("y"),
			data.getFloat("z"));
		break; 
	case DATACOMMANDL:
			setDataL(data.getFloat("x"),
				data.getFloat("y"),
				data.getFloat("z"));
			break;
	}
}

int CSensor::getSourceType() const
{
	return VIZ_LINK_POS;
}

CSensor* CSensor::Instance()
{
	if (singleton == NULL)
		singleton = new CSensor();
	return singleton;
}
and this is Vizard
Code:
ex=viz.add('BMI.Vizard.dle')
self.sensor =  ex.addSensor()
when from Vizard I call ex.addSensor() the program crash with this report
Code:
Dump Summary
------------
Dump File:	crashdump.dmp : C:\Users\ASDAP\AppData\Local\CrashRpt\UnsentCrashReports\Vizard (32-bit)_4.09.0016\5ac47f9d-2fa6-4037-b442-22e676c841c9\crashdump.dmp
Last Write Time:	07/06/2016 19:11:40
Process Name:	winviz.exe : C:\Program Files (x86)\WorldViz\Vizard4\bin\winviz.exe
Process Architecture:	x86
Exception Code:	0xC0000005
Exception Information:	The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
Heap Information:	Not Present

System Information
------------------
OS Version:	6.1.7601
CLR Version(s):	

Modules
-------
Module Name	Module Path	Module Version
-----------	-----------	--------------
winviz.exe	C:\Program Files (x86)\WorldViz\Vizard4\bin\winviz.exe	4.0.0.0
ntdll.dll	C:\Windows\SysWOW64\ntdll.dll	6.1.7601.23418
kernel32.dll	C:\Windows\SysWOW64\kernel32.dll	6.1.7601.23418
KERNELBASE.dll	C:\Windows\SysWOW64\KERNELBASE.dll	6.1.7601.23418
user32.dll	C:\Windows\SysWOW64\user32.dll	6.1.7601.19061
gdi32.dll	C:\Windows\SysWOW64\gdi32.dll	6.1.7601.23418
lpk.dll	C:\Windows\SysWOW64\lpk.dll	6.1.7601.19146
usp10.dll	C:\Windows\SysWOW64\usp10.dll	1.626.7601.19054
msvcrt.dll	C:\Windows\SysWOW64\msvcrt.dll	7.0.7601.17744
advapi32.dll	C:\Windows\SysWOW64\advapi32.dll	6.1.7601.23418
sechost.dll	C:\Windows\SysWOW64\sechost.dll	6.1.7601.18869
rpcrt4.dll	C:\Windows\SysWOW64\rpcrt4.dll	6.1.7601.23418
sspicli.dll	C:\Windows\SysWOW64\sspicli.dll	6.1.7601.23418
CRYPTBASE.dll	C:\Windows\SysWOW64\CRYPTBASE.dll	6.1.7601.23418
comdlg32.dll	C:\Windows\SysWOW64\comdlg32.dll	6.1.7601.17514
shlwapi.dll	C:\Windows\SysWOW64\shlwapi.dll	6.1.7601.17514
comctl32.dll	C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_41e855142bd5705d\comctl32.dll	6.10.7601.18837
shell32.dll	C:\Windows\SysWOW64\shell32.dll	6.1.7601.19135
imm32.dll	C:\Windows\System32\imm32.dll	6.1.7601.17514
msctf.dll	C:\Windows\SysWOW64\msctf.dll	6.1.7601.18731
wininet.dll	C:\Windows\SysWOW64\wininet.dll	11.0.9600.18315
api-ms-win-downlevel-user32-l1-1-0.dll	C:\Windows\SysWOW64\api-ms-win-downlevel-user32-l1-1-0.dll	6.2.9200.16492
api-ms-win-downlevel-shlwapi-l1-1-0.dll	C:\Windows\SysWOW64\api-ms-win-downlevel-shlwapi-l1-1-0.dll	6.2.9200.16492
api-ms-win-downlevel-version-l1-1-0.dll	C:\Windows\SysWOW64\api-ms-win-downlevel-version-l1-1-0.dll	6.2.9200.16492
version.dll	C:\Windows\System32\version.dll	6.1.7600.16385
api-ms-win-downlevel-normaliz-l1-1-0.dll	C:\Windows\SysWOW64\api-ms-win-downlevel-normaliz-l1-1-0.dll	6.2.9200.16492
normaliz.dll	C:\Windows\SysWOW64\normaliz.dll	6.1.7600.16385
iertutil.dll	C:\Windows\SysWOW64\iertutil.dll	11.0.9600.18315
api-ms-win-downlevel-advapi32-l1-1-0.dll	C:\Windows\SysWOW64\api-ms-win-downlevel-advapi32-l1-1-0.dll	6.2.9200.16492
userenv.dll	C:\Windows\SysWOW64\userenv.dll	6.1.7601.17514
profapi.dll	C:\Windows\SysWOW64\profapi.dll	6.1.7600.16385
setupapi.dll	C:\Windows\SysWOW64\setupapi.dll	6.1.7601.17514
cfgmgr32.dll	C:\Windows\SysWOW64\cfgmgr32.dll	6.1.7601.17621
oleaut32.dll	C:\Windows\SysWOW64\oleaut32.dll	6.1.7601.19144
ole32.dll	C:\Windows\SysWOW64\ole32.dll	6.1.7601.23392
devobj.dll	C:\Windows\SysWOW64\devobj.dll	6.1.7601.17621
clbcatq.dll	C:\Windows\SysWOW64\clbcatq.dll	2001.12.8530.16385
cryptsp.dll	C:\Windows\System32\cryptsp.dll	6.1.7601.18741
rsaenh.dll	C:\Windows\System32\rsaenh.dll	6.1.7600.16385
RpcRtRemote.dll	C:\Windows\System32\RpcRtRemote.dll	6.1.7601.17514
ws2_32.dll	C:\Windows\SysWOW64\ws2_32.dll	6.1.7601.17514
nsi.dll	C:\Windows\SysWOW64\nsi.dll	6.1.7600.16385
inetmib1.dll	C:\Windows\System32\inetmib1.dll	6.1.7601.17514
IPHLPAPI.DLL	C:\Windows\System32\IPHLPAPI.DLL	6.1.7601.17514
winnsi.dll	C:\Windows\System32\winnsi.dll	6.1.7600.16385
snmpapi.dll	C:\Windows\System32\snmpapi.dll	6.1.7600.16385
wsock32.dll	C:\Windows\System32\wsock32.dll	6.1.7600.16385
mswsock.dll	C:\Windows\System32\mswsock.dll	6.1.7601.18254
WSHTCPIP.DLL	C:\Windows\System32\WSHTCPIP.DLL	6.1.7600.16385
viz_python.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\viz_python.dll	0.0.0.0
vizcore.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\vizcore.dll	0.0.0.0
opengl32.dll	C:\Windows\System32\opengl32.dll	6.1.7600.16385
glu32.dll	C:\Windows\System32\glu32.dll	6.1.7600.16385
ddraw.dll	C:\Windows\System32\ddraw.dll	6.1.7600.16385
dciman32.dll	C:\Windows\System32\dciman32.dll	6.1.7601.19146
dwmapi.dll	C:\Windows\System32\dwmapi.dll	6.1.7601.18917
osg.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\osg.dll	2.9.12.72
OpenThreads.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\OpenThreads.dll	2.5.0.12
msvcr90.dll	C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll	9.0.30729.6161
msvcp90.dll	C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcp90.dll	9.0.30729.6161
osgDB.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\osgDB.dll	2.9.12.72
osgUtil.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\osgUtil.dll	2.9.12.72
zlib1.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\zlib1.dll	1.2.5.0
osgText.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\osgText.dll	2.9.12.72
osgParticle.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\osgParticle.dll	2.9.12.72
quartz.dll	C:\Windows\System32\quartz.dll	6.6.7601.19091
winmm.dll	C:\Windows\System32\winmm.dll	6.1.7601.17514
psapi.dll	C:\Windows\SysWOW64\psapi.dll	6.1.7600.16385
python27.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\python27.dll	2.7.2150.1013
CrashRpt1300.dll	C:\Program Files (x86)\WorldViz\Vizard4\bin\CrashRpt1300.dll	1.3.0.0
uxtheme.dll	C:\Windows\System32\uxtheme.dll	6.1.7600.16385
wintrust.dll	C:\Windows\SysWOW64\wintrust.dll	6.1.7601.18839
crypt32.dll	C:\Windows\SysWOW64\crypt32.dll	6.1.7601.18839
msasn1.dll	C:\Windows\SysWOW64\msasn1.dll	6.1.7601.17514
_hashlib.pyd	C:\Program Files (x86)\WorldViz\Vizard4\bin\DLLs\_hashlib.pyd	0.0.0.0
transform.pyd	C:\Program Files (x86)\WorldViz\Vizard4\bin\DLLs\transform.pyd	0.0.0.0
_ctypes.pyd	C:\Program Files (x86)\WorldViz\Vizard4\bin\DLLs\_ctypes.pyd	0.0.0.0
BMI.Vizard.dle	C:\Users\ASDAP\Documents\Francesco\BMI v3.0\Debug\Viz\BMI.Vizard.dle	0.0.0.0
msvcp140.dll	C:\Windows\System32\msvcp140.dll	14.0.23918.0
VCRUNTIME140.dll	C:\Windows\System32\VCRUNTIME140.dll	14.0.23918.0
api-ms-win-crt-runtime-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-runtime-l1-1-0.dll	10.0.10586.9
ucrtbase.dll	C:\Windows\System32\ucrtbase.dll	10.0.10586.9
api-ms-win-core-timezone-l1-1-0.dll	C:\Windows\System32\api-ms-win-core-timezone-l1-1-0.dll	10.0.10586.9
api-ms-win-core-file-l2-1-0.dll	C:\Windows\System32\api-ms-win-core-file-l2-1-0.dll	10.0.10586.9
api-ms-win-core-localization-l1-2-0.dll	C:\Windows\System32\api-ms-win-core-localization-l1-2-0.dll	10.0.10586.9
api-ms-win-core-synch-l1-2-0.dll	C:\Windows\System32\api-ms-win-core-synch-l1-2-0.dll	10.0.10586.9
api-ms-win-core-processthreads-l1-1-1.dll	C:\Windows\System32\api-ms-win-core-processthreads-l1-1-1.dll	10.0.10586.9
api-ms-win-core-file-l1-2-0.dll	C:\Windows\System32\api-ms-win-core-file-l1-2-0.dll	10.0.10586.9
api-ms-win-crt-string-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-string-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-heap-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-heap-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-stdio-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-stdio-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-convert-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-convert-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-locale-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-locale-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-math-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-math-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-multibyte-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-multibyte-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-time-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-time-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-filesystem-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-filesystem-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-environment-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-environment-l1-1-0.dll	10.0.10586.9
api-ms-win-crt-utility-l1-1-0.dll	C:\Windows\System32\api-ms-win-crt-utility-l1-1-0.dll	10.0.10586.9
apphelp.dll	C:\Windows\System32\apphelp.dll	6.1.7601.19050
any idea?
Reply With Quote
Reply

Tags
c++, import, vizard 5.0

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -7. The time now is 04:04 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC