Interface PartInstanceInfoInterface

The PartInstanceInfoInterface interface is used to store properties about a part instance and its genealogy.

The PartInstanceInfoInterface is retrieved when using a IdCardGetterInterface.retrieveIdCard i.e. when the metadata attached to a part instance are retrieved.

The interface provides information about

If you query multiple part instances when using IdCardGetterInterface.retrieveIdCard, IdCardGetterInterface.getPartInstanceInfos will return an array of PartInstanceInfoInterface of the same size.

The following code snippet allows to get the metadata of a part instance by the IdCardGetterInterface. Such a code may be triggered while receiving the IdCardGetterInterfaceSignal.IdCardReady of the IdCardGetterInterface.

/** 
* Sample to illustrate the use of an IdCardGetterInterface with the parsing of
* PartInstanceInfoInterface to display some information about a part instance.
*/
import {
WorkingSetInterface, IdCardGetterInterface, IdCardGetterInterfaceSignal,
InfiniteEvent, PartInstanceInfoInterface, DataSessionInterface, AncestryInstanceMetadataInterface, DocumentContentInterface
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// created previously
let lVisibilityContext : WorkingSetInterface;
// the `part instance id` to get
let lPartInstanceId : number;
// what to do when we have retrieved id card information ?
let onIdCardReady : (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) => void;

// create an idCardGetter
const lIdCardGetterInterface : IdCardGetterInterface = lDataSession.createIdCardGetter();
// what to do when result is ready ?
lIdCardGetterInterface.addEventListener(IdCardGetterInterfaceSignal.IdCardReady, onIdCardReady);

// onIdCardReady will be called when data is available
onIdCardReady = (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
if (lIdCardGetterInterface.getLastError() !== undefined) {
// do nothing in case of error
// perhaps some GUI code ?
}
const lPartInstanceInfos : Array<PartInstanceInfoInterface> | undefined = lIdCardGetterInterface.getPartInstanceInfos();
if (!lPartInstanceInfos || lPartInstanceInfos.length !== 1)
{
// no data (isCancelled ?)
return;
}
// we required only one `part instance`, as such, only one result should be retrieved
// iterate over the instantiation chain, but take the first chain since one `part instance` retrieved
const lCurrentChain : PartInstanceInfoInterface = lPartInstanceInfos[0];

// iterate over the metadata infos
const lAllInstanceMetadata : Array<AncestryInstanceMetadataInterface> = lCurrentChain.getAncestorInstanceInfos();

// number of items
const lNbAncestors : number = lAllInstanceMetadata.length;
const lOffsetToPartInstance : number = lNbAncestors - 1;
// we get the `part` metadata of the given `part instance` (and not their parents - grand parents) => lNbAncestors-1
const lCurrentInstanceInfos : AncestryInstanceMetadataInterface = lAllInstanceMetadata[lOffsetToPartInstance];
const lPartMetadataDocuments : Array<DocumentContentInterface> = lCurrentInstanceInfos.getPartMetadataDocuments();
if (lPartMetadataDocuments.length === 0)
{
console.log('this part instance has no part metadata documents');
return;
}
// and we only care with the first document, but many documents may be attached
const lPartMetadata : Object = lPartMetadataDocuments[0].getDocumentContent();
// some fancy output
console.log(JSON.stringify(lPartMetadata));

// get the visibility info in order to get information about the `part instance`
if (lCurrentInstanceInfos.isDisplayable())
{
console.log('this part instance is displayable');
}
};

// trigger the retrieval
lIdCardGetterInterface.retrieveIdCard(lPartInstanceId, lVisibilityContext);

or with async calls :
/** 
* Sample to illustrate the asynchronous use of an IdCardGetterInterface with the parsing of
* PartInstanceInfoInterface to display some information about a part instance.
*/
import {
WorkingSetInterface, IdCardGetterInterface, AsyncPartInstanceInfoResult,
AsyncResultReason, PartInstanceInfoInterface, DataSessionInterface, AncestryInstanceMetadataInterface, DocumentContentInterface
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// created previously
let lVisibilityContext : WorkingSetInterface;
// the `part instance id` to get
let lPartInstanceId : number;
// what to do when we have retrieved id card information ?

// create an idCardGetter
const lIdCardGetterInterface : IdCardGetterInterface = lDataSession.createIdCardGetter();

const fetchIdCard = async () : Promise<void> =>
{
// trigger the retrieval
const lResult : AsyncPartInstanceInfoResult = await lIdCardGetterInterface.asyncRetrieveIdCard(lPartInstanceId, lVisibilityContext);
if (lResult.reason !== AsyncResultReason.ARR_Success) {
// do nothing in case of error
// perhaps some GUI code ?
}

const lPartInstanceInfos : Array<PartInstanceInfoInterface> | undefined = lIdCardGetterInterface.getPartInstanceInfos();
console.assert(lPartInstanceInfos === lResult.value);
if (!lPartInstanceInfos || lPartInstanceInfos.length !== 1)
{
// no data (isCancelled ?)
return;
}
// we required only one `part instance`, as such, only one result should be retrieved
// iterate over the instantiation chain, but take the first chain since one `part instance` retrieved
const lCurrentChain : PartInstanceInfoInterface = lPartInstanceInfos[0];

// get all metadata hierarchy
const lAllInstanceMetadata : Array<AncestryInstanceMetadataInterface> = lCurrentChain.getAncestorInstanceInfos();

// number of items
const lNbAncestors : number = lAllInstanceMetadata.length;
const lOffsetToPartInstance : number = lNbAncestors - 1;

// we get the `part` metadata of the given `part instance` (and not their parents - grand parents) => lNbAncestors-1
const lCurrentInstanceInfos : AncestryInstanceMetadataInterface = lAllInstanceMetadata[lOffsetToPartInstance];
const lPartMetadataDocuments : Array<DocumentContentInterface> = lCurrentInstanceInfos.getPartMetadataDocuments();
if (lPartMetadataDocuments.length === 0)
{
console.log('this part instance has no part metadata documents');
return;
}
// and we only care with the first document, but many documents may be attached
const lPartMetadata : Object = lPartMetadataDocuments[0].getDocumentContent();
// some fancy output
console.log(JSON.stringify(lPartMetadata));

// get the visibility info in order to get information about the `part instance`
if (lCurrentInstanceInfos.isDisplayable())
{
console.log('the last child of the part instance is displayable');
}
};

fetchIdCard();

Please make sure the destination browser supports promises before using async calls.
Data Retrievers

interface PartInstanceInfoInterface {
    getAABB(): AABB;
    getAncestorInstanceInfos(): AncestryInstanceMetadataInterface[];
    getInstanceId(): number;
    getObbDiagonalSquared(): number;
    isDisplayable(): boolean;
    isInstanceLeaf(): boolean;
}

Methods

  • Gets the Axis Aligned Bounding Box of the part instance this object refers to.

    DO NOT modify in place this object, this results in undefined behavior.

    Returns AABB

    const
    The Axis Aligned BoundingBox of this part instance.

    See

    AABB

  • Gets the square of the diagonal of the Oriented Bounding Box of this part instance.

    If this part instance is not a leaf, returns -1.

    Returns number

    The square of the diagonal of the Oriented Bounding Box of this part instance.

  • Tells if this instance is displayable.

    Returns boolean

    true if this instance is displayable, i.e. it is represented by some geometry(ies).

  • Tells if this part instance is a leaf, which means it has no child.

    Returns boolean

    true if the part instance this object refers to is a leaf.