VCOM:VectorWorks:Scripting:IPythonWrapper: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 15: Line 15:
<interface>
<interface>
<code lang="cpp">
<code lang="cpp">
...put the class definition, including the UUID, here...
// ---------------------------------------------------------------------------------------------------
// {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;
};
</code>
</code>
</interface>
</interface>
Line 24: Line 41:
<line>
<line>
[[VCOM:VectorWorks:Scripting:IPythonWrapper::AddPath|AddPath]]
[[VCOM:VectorWorks:Scripting:IPythonWrapper::AddPath|AddPath]]
 
Add search path in sys.path in python.
</line>
</line>
<line>
<line>
[[VCOM:VectorWorks:Scripting:IPythonWrapper::LoadModule|LoadModule]]
[[VCOM:VectorWorks:Scripting:IPythonWrapper::LoadModule|LoadModule]]
 
Load a named module, or memory block as module into the python run-time.
</line>
</line>
<line>
<line>
[[VCOM:VectorWorks:Scripting:IPythonWrapper::CompileText|CompileText]]
[[VCOM:VectorWorks:Scripting:IPythonWrapper::CompileText|CompileText]]
 
Compile the specified text.
</line>
</line>
<line>
<line>
[[VCOM:VectorWorks:Scripting:IPythonWrapper::RunText|RunText]]
[[VCOM:VectorWorks:Scripting:IPythonWrapper::RunText|RunText]]
 
Execute text as python script in this run-time.
</line>
</line>
<line>
<line>
[[VCOM:VectorWorks:Scripting:IPythonWrapper::Call|Call]]
[[VCOM:VectorWorks:Scripting:IPythonWrapper::Call|Call]]
 
Execute a function in the specified module.
</line>
</line>
<line>
<line>
[[VCOM:VectorWorks:Scripting:IPythonWrapper::GetCallResult|GetCallResult]]
[[VCOM:VectorWorks:Scripting:IPythonWrapper::GetCallResult|GetCallResult]]
 
Get result from the [[VCOM:VectorWorks:Scripting:IPythonWrapper::Call|Call]] execution.
</line>
</line>
</lineList>
</lineList>

Latest revision as of 17:28, 19 September 2013

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]]