Calling C++ Custom Commands from Scripting

 
 
 

When a C++ custom command returns an array, the value received by the caller depends on the scripting language, and whether a CValueArray or a CRefArray is returned. For example, if a command returns a CValueArray, then a JScript caller gets a safe array, but if a command returns a CRefArray, then a JScript caller gets an XSICollection.

Language

CRefArray

CValueArray

VBScript

XSICollection

XSICollection

JScript

XSICollection

safe array

Python

XSICollection instance

tuple

JScript Example: Calling a C++ command that returns an array

//
// GetValueArray() is a C++ custom command that returns a CValueArray
//

var aSafeArray = GetValueArray();

var aVBArray = new VBArray( aSafeArray );
logmessage( typeof( aVBArray ) );
logmessage( aVBArray.dimensions() );

// Access the VBArray directly
for (var i=0; i <= aVBArray.ubound(1); i++)
{
	Application.LogMessage( aVBArray.getItem(i).fullname );
}

// Convert the VBArray to a JScript array
var aJSarray = aVBArray.toArray();
for (e=new Enumerator(aJSarray);!e.atEnd();e.moveNext())
{
	var o = e.item();
	logmessage( o.fullname );
}

//
// GetRefArray() is a C++ custom command that returns a CRefArray
//

var objects = GetRefArray();
logmessage( objects.type );	//INFO : XSICollection
for (e=new Enumerator(objects);!e.atEnd();e.moveNext())
{
	var o = e.item();
	Application.LogMessage( o.fullname );
}

Python Example: Calling a C++ command that returns an array

#
# GetValueArray is a C++ custom command that returns a CValueArray
#

objects = Application.GetValueArray()

Application.Logmessage( unicode(type(objects)) )#INFO : <type 'tuple'>

for o in objects:
	Application.LogMessage( o.name )
	Application.Logmessage( unicode(type(o)) )#INFO : <type 'instance'>
	Application.LogMessage( Application.classname(o) )

#
# GetRefArray is a C++ custom command that returns a CRefArray
#

objects = Application.GetRefArray()
Application.Logmessage( unicode(type(objects)) )#INFO : <type 'instance'>
Application.Logmessage( objects.type )# XSICollection

for o in objects:
	Application.LogMessage(o.name)

for i in range(objects.Count):
	Application.LogMessage(objects(i).FullName)

VBScript Example: Calling a C++ command that returns an array

'
' GetValueArray() returns a CValueArray
'
set objects = GetValueArray()

logmessage( typename( objects ) )'INFO : Object
logmessage( objects.type )'INFO : XSICollection

for each o in objects
	logmessage o.name
next
'
' GetRefArray() returns a CRefArray
'
set objects = GetRefArray()
logmessage typename( objects )'INFO : Object
logmessage( objects.type )'INFO : XSICollection
for each o in objects
	logmessage o.name
next

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License