VCOM:VectorWorks:Scripting:IPythonWrapper

From Vectorworks Developer
Jump to navigation Jump to search

Description

namespace VectorWorks::Scripting

This interface is a representation of a python run-time. You can use this interface to create a run-time, set it up, and execute scripts.

Note that executing scripts consecutively in an run-time environment will let all defined variable remain after each script execution.

Interface

// ---------------------------------------------------------------------------------------------------
// {196DB14F-F32C-445E-A785-15E16CAB9E83}
static const VWIID IID_PythonWrapper = { 0x196db14f, 0xf32c, 0x445e, { 0xa7, 0x85, 0x15, 0xe1, 0x6c, 0xab, 0x9e, 0x83 } };

class DYNAMIC_ATTRIBUTE IPythonWrapper : public IVWUnknown
{
public:
	virtual void		VCOM_CALLTYPE AddPath(const char* path) = 0;
	virtual bool		VCOM_CALLTYPE LoadModule(const char* moduleName) = 0;
	virtual bool		VCOM_CALLTYPE LoadModule(const char* moduleName, void* memory, int memorySize) = 0;
    
	virtual bool		VCOM_CALLTYPE CompileText(const char* pythonCode) = 0;
	virtual void		VCOM_CALLTYPE RunText(const char* pythonCode) = 0;
	virtual bool		VCOM_CALLTYPE Call(const char* functionName, const TXStringArray& arrParams) = 0;
	virtual bool		VCOM_CALLTYPE Call(const char* moduleName, const char* functionName, const TXStringArray& arrParams) = 0;
	
	virtual TXString	VCOM_CALLTYPE GetCallResult() const = 0;
};

Members

AddPath Add search path in sys.path in python.
LoadModule Load a named module, or memory block as module into the python run-time.
CompileText Compile the specified text.
RunText Execute text as python script in this run-time.
Call Execute a function in the specified module.
GetCallResult Get result from the Call execution.

Remarks

There is predefined type for smart VCOM pointer VCOMPtr to IPythonWrapper interface:

typedef VCOMPtr<IPythonWrapper>  IPythonWrapperPtr;

Use the following interface to capture the logging from the script execution:

class DYNAMIC_ATTRIBUTE IPythonLogger
{
public:
	virtual ~IPythonLogger() {}

	virtual void VCOM_CALLTYPE LogStdOut(const char* msg) = 0;
	virtual void VCOM_CALLTYPE LogStdErr(const char* msg) = 0;
};

Version

Available from: Vectorworks 2014

See Also

VCOM:VCOMPtr

[[VCOM:VCOMPtr]]