VCOM:VectorWorks:Scripting:IPythonWrapper: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
namespace <code>VectorWorks::Scripting</code> | namespace <code>VectorWorks::Scripting</code> | ||
.. | 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. | |||
</desc> | </desc> | ||
Line 13: | Line 15: | ||
<interface> | <interface> | ||
<code lang="cpp"> | <code lang="cpp"> | ||
// --------------------------------------------------------------------------------------------------- | |||
// {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 22: | 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> | ||
Line 62: | Line 73: | ||
<code lang="cpp"> | <code lang="cpp"> | ||
typedef VCOMPtr<IPythonWrapper> IPythonWrapperPtr; | typedef VCOMPtr<IPythonWrapper> IPythonWrapperPtr; | ||
</code> | |||
Use the following interface to capture the logging from the script execution: | |||
<code lang="cpp"> | |||
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; | |||
}; | |||
</code> | </code> | ||
</remark> | </remark> |
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]]