Creating User Defined Primitives and User Defined Models in Python Scripts

You can create User Defined Primitives and User Defined Models in Python scripts (based on the IronPython implementation).

Advantages Compared to C++

Changes compared to C

Though methods, constants and structures are kept as close to the C implementation as possible, some changes had to be made to make code Python-compatible.

Structures

For a complete list of structures and examples please see UDP/UDM Structures.

Return Values for UDM and UDP Functions

For information on return values for each UDM and UDP function, see the Return Values section.

Constants

Enumeration/Enum constants have almost the same names as in C but the enum must be qualified by the type. Additionally, redundant "UDP", "UDM" or type prefixes have been removed. This allows for better human-readability.

# Example of specifying the LengthUnit enum by qualifying it

# with the type of the enum: UnitType

unitType = UnitType.LengthUnit

For a complete list of enum constants please see UDP/UDM Constants.

Methods

Methods are described in IUDPExtension methods, IUDMExtension methods, and UDMFunctionLibrary listed further in this document. A separate chapter includes a UDP IronPython example of fillet and chamfer.

The main differences in functions parameters (from C implementation):

Output Parameters

The rule for the output parameters is as follows:

# one output parameter; return value is ignored

udmDefinition = udmFunctionLibrary.GetDefinition()

 

# one output parameter; return value must be preserved. return
# and output values are packed into the return tupe, in order

(lRet, partIdsList) = udpFunctionLibrary.DetachFaces(nPartIds, faceIdsList)

# Two output parameter; return value must be preserved

# the return tuple is (returnVal, output1, output2)

(bRet, udpPositionLow, udpPositionHigh) = udmFunctionLibrary.GetBoundingBox(partId,exact);

Comparison with C function:

C

Python

bool getDefinition(UDMDefinition* udmDefinition,

void* callbackData );

 

where udmDefinition is an output parameter

 

udmDefinition = udmFunctionLibrary.GetDefinition()

 

(Note: callbackData is omitted in py interface)

long detachlFaces( int nFacesAndPartIds,

long* faceIds,

long* partIds,

void* callbackData);

 

where partIds is an output parameter

(bRet, partIds) = udmFunctionLibrary.DetachlFaces(nFacesAndPartIds, faceIds)

 

(Note: callbackData is omitted in py interface)

'List Size' Parameters

The rule for the 'list size' is as follows:

Example:

# input list, input list size

lret = udpFunctionLibrary.Unite(objectIds)

 

# output list, output list size

faceIdList = udmFunctionLibrary.GetAllFaces(PartId)

 

# output list, input list size

(lret, partIdList) = udpFunctionLibrary.DetachFaces(listSize, faceIdList)

Comparison with C function:

C

Python

bool getAllFaces( long partId,

long* numFaces,

long** faceIds,

void* callbackData);

 

where numFaces and faceIds are output parameters and numFaces is the size of faceId.

faceIds = udmFunctionLibrary.GetAllFaces(partId)

 

 

(ignore numFaces as redundant: folded into faceIds,

return value is omitted: folded into the faceIds is None check

callbackData is omitted)

long unite( long numObjects,

long* objectIds,

void* callbackData);

 

where numObjects and objectIds are input parameters and numObjects is the size of objectIds.

lret = udpFunctionLibrary.Unite(objectIds)

 

 

(ignore numObjects as redundant: folded into objectIds

callbackData is omitted)

long detachFaces( long nSize,

long* faceIds,

long* partIds,

void* callbackData);

 

where partIds is and output list and nSize is an input parameters and nSize is the size of partIds.

(lret, partIdList) = udpFunctionLibrary.DetachFaces(nSize, faceIds)

 

 

(nSize is not ignored,

callbackData is omitted)

Added Parameters

There is a special case in UDPFunctionLibrary: two functions - DuplicateAlongLine and DuplicateAroundAxis - have new integer listSize parameter added to their signatures.

This parameter defines the size of the output List. This is done for compliance with C++ geometry library as the size of the List must be predefined and this size is different from the existing parameter’s values.

Example:

(ret, cloneIDs) = funcLib.DuplicateAlongLine(partID, transVec, numCubes, cloneIdsSize)

(ret, cloneIDs) = funcLib.DuplicateAroundAxis(partID, axis, angle, nClones, cloneIdsSize)

Here cloneIdsSize is a new integer parameter.

Comparison with C function:

C

Python

long duplicateAlongLine( long partId,

UDPVector transVector,

int nClones,

long* nClones,

void* callbackData);

(lret, cloneIds) = udmFunctionLibrary.DuplicateAlongLine(partId, transVec, nClones, cloneIdsSize)

 

 

(callbackData is omitted

cloneIdsSize is a new parameter)

long duplicateAroundAxis(

long partId,

UDPCoordinateSystemAxis axis,

double angle,

int nClones,

long* nClones,

void* callbackData);

(lret, cloneIds) = udmFunctionLibrary.DuplicateAroundAxis(partId, axis, angle, nClones, cloneIdsSize)

 

 

(callbackData is omitted

cloneIdsSize is a new parameter)