v2.2
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

1 import sys
2 import win32com.client
3 
4 if __name__ == '__main__':
5  app = win32com.client.Dispatch("Renga.Application")
6  app.Visible = True
7 
8  if app.CreateProject() != 0:
9  print("Error opening project")
10  sys.exit(1)
11 
12  project = app.Project
13  model = project.Model
14  propertyMng = project.PropertyManager
15  propertyId = '{A288D248-C715-4796-A911-83B2DCD4BDD9}'# random
16  propertyName = 'Test string property'
17  levelType = '{C3CE17FF-6F28-411F-B18D-74FE957B2BA8}' # GUID for the 'level' object type, as listed in documentation. See "Object types".
18 
19  # Property registration
20  # NOTE: using the S-method accepting the GUIDs as strings
21  propertyMng.RegisterPropertyS(propertyId, propertyName, 2) # 2 means string type, see the docs.
22 
23  # Assigning property to the level type
24  # NOTE: using the S-method to work with the GUID
25  propertyMng.AssignPropertyToTypeS(propertyId, levelType)
26  print("Property registered in Renga and assigned to all levels")
27 
28  # Creating and starting an operation
29  operation = model.CreateOperation()
30  operation.Start()
31 
32  # Setting a property value to all levels
33  objectCollection = model.GetObjects()
34  for index in range(objectCollection.Count):
35  object = objectCollection.GetByIndex(index)
36  # NOTE: using the S-property
37  if object.ObjectTypeS == levelType:
38  propertyContainer = object.GetProperties()
39  property = propertyContainer.GetS(propertyId)
40  # NOTE: quering an additional interface with the GetInterfaceByName() method
41  levelModel = object.GetInterfaceByName("ILevel")
42  # setting the property value equal to the level name
43  property.SetStringValue(levelModel.LevelName)
44 
45  # Applying the changes
46  operation.Apply()
47 
48  # Closing the project without saving, dumping all the hard work
49  app.CloseProject(True)
50  app.Quit()

See also

Related samples

  • CreateProperty.py
  • OpenSaveCloseProject.py