v2.9
How to access Renga from dynamic languages

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}'# random
propertyName = 'Test string property'
levelType = '{C3CE17FF-6F28-411F-B18D-74FE957B2BA8}' # GUID for the 'level' object type, as listed in documentation. See "Object types".
# Property registration
# NOTE: using the S-method accepting the GUIDs as strings
propertyMng.RegisterPropertyS(propertyId, propertyName, 2) # 2 means string type, see the docs.
# Assigning property to the level type
# NOTE: using the S-method to work with the GUID
propertyMng.AssignPropertyToTypeS(propertyId, levelType)
print("Property registered in Renga and assigned to all levels")
# Creating and starting an operation
operation = model.CreateOperation()
operation.Start()
# Setting a property value to all levels
objectCollection = model.GetObjects()
for index in range(objectCollection.Count):
object = objectCollection.GetByIndex(index)
# NOTE: using the S-property
if object.ObjectTypeS == levelType:
propertyContainer = object.GetProperties()
property = propertyContainer.GetS(propertyId)
# NOTE: quering an additional interface with the GetInterfaceByName() method
levelModel = object.GetInterfaceByName("ILevel")
# setting the property value equal to the level name
property.SetStringValue(levelModel.LevelName)
# Applying the changes
operation.Apply()
# Closing the project without saving, dumping all the hard work
app.CloseProject(True)
app.Quit()

See also

Related samples

  • CreateProperty.py
  • OpenSaveCloseProject.py