Python – Getting rules from a connection mapping template


This snippet shows how to read a connection (or value) mapping template into a Python dictionary.

t = Application.Dictionary.GetObject( "Model1.Mixer.MappingTemplate1" )

n = Application.GetNumMappingRules( t )

d = {}
for i in range(1,n+1):
        r = Application.GetMappingRule( t, i )
        d[r.Value("From")] = r.Value("To")
        
for k, v in d.iteritems():
     Application.LogMessage( k + " > " +  v )

Line 8 GetMappingRule uses output arguments, so we have to take the returned ISIVTCollection and extract the From and To output arguments. We use From as the dictionary key.

Leave a comment