This article covers how to use the SystemWeaver API in Python in Windows. The user needs basic knowledge of Python and a Python interpreter installed. This article is written and has been tested for Python 3.5.
- The pythonnet package from https://github.com/pythonnet/pythonnet
- Familiarity with the system's meta model and data.
- You have read Guidelines for API Usage
- The SystemWeaver API files (contact your organization's SystemWeaver IT support to obtain the following ddl files or the Nuget package):
- RVFUtility.dll or RVFUtility64.dll (depending on platform target)
Installing the Pythonnet Package
Install the pythonnet package from https://github.com/pythonnet/pythonnet and run the following from a command prompt:
pip3 install pythonnet
Make sure that SystemWeaverClientAPI.dll and RVFUtility64.dll are located in the same directory as your python file.
Log in and Import API
In the first lines of your python file, use the following code to log in and import the API:
import clr clr.AddReference("SystemWeaverClientAPI") from SystemWeaverAPI import * from SystemWeaver.Common import *
The following small example illustrates how you can log in to the test database and read data. You can follow the examples from Introduction to the SystemWeaver API in C# with only slight differences in the syntax.
try: SWConnection.Instance.LoginName = "student" SWConnection.Instance.Password = "student" SWConnection.Instance.ServerMachineName = "localhost" SWConnection.Instance.ServerPort = 1768 SWConnection.Instance.Login() if SWConnection.Instance.Connected: handle = SWHandleUtility.ToHandle("x0400000000000296") item = SWConnection.Instance.Broker.GetItem(handle) for i in item.GetPartItems("EXAC"): print("Component: %s \n" % i.Name) except SWInvalidUsernameOrPasswordException: print("Invalid user or password\n") except Exception: print("Could not connect to server\n")
To use Windows login id instead of LoginName and Password, you can use: SystemWeaverAPI.SWConnection.UseNetworkAuthentication=true if network authentication is available.