Overview
Since Renga API is built upon the COM technology it is possible to access Renga API with dynamically typed languages, such as Python, VBScript, etc. Currently Renga can only load plugins from binary C++ DLLs and .NET assemblies, so accessing Renga API with dynamically typed languages is possible only from standalone applications.
All Renga API functionality is accessible from such languages, with a few caveats:
- Some dynamically typed languages do not support (or only partially support) COM structures (known as UDTs - user defined types - in Microsoft lingo). To circumvent the case where methods with UDT-typed arguments don't work for you, look for their functionality available in other methods.
- Renga uses standard COM-defined structure named GUID for entity identification. It may be impossible to work directly with this type in dynamically typed languages. In that case use methods and/or properties whose names end with the "S" suffix to pass GUIDs as strings.
- Although Renga implements the standard COM QueryInterface() method for casting interfaces (which you'd need to use to get an ILevel from an IModelObject), it might be a problem to call it from a dynamic language. In this case use the GetInterfaceByName() method.
Example: accessing Renga with Python
import sys
import win32com.client
if __name__ == '__main__':
app = win32com.client.Dispatch("Renga.Application")
app.Visible = True
if app.CreateProject() != 0:
print("Error opening project")
sys.exit(1)
project = app.Project
model = project.Model
propertyMng = project.PropertyManager
propertyId = '{A288D248-C715-4796-A911-83B2DCD4BDD9}'
propertyName = 'Test string property'
levelType = '{C3CE17FF-6F28-411F-B18D-74FE957B2BA8}'
operation = project.CreateOperation()
operation.Start()
propertyMng.RegisterPropertyS(propertyId, propertyName, 2)
propertyMng.AssignPropertyToTypeS(propertyId, levelType)
print("Property registered in Renga and assigned to all levels")
objectCollection = model.GetObjects()
for index in range(objectCollection.Count):
object = objectCollection.GetByIndex(index)
if object.ObjectTypeS == levelType:
propertyContainer = object.GetProperties()
property = propertyContainer.GetS(propertyId)
levelModel = object.GetInterfaceByName("ILevel")
property.SetStringValue(levelModel.LevelName)
operation.Apply()
app.CloseProject(True)
app.Quit()
See also
Related samples
- CreateProperty.py
- OpenSaveCloseProject.py