DATAKIT API  V2025.1
How to use Assembly Tree

After enabling readers you want to use, then starting the Dtk_API, you can call the OpenDocument method of the Dtk_API class to get a Dtk_MainDoc. It contains a root representing the Assembly Tree based on Dtk_Component.
Dtk_API contains a file search engine to set your preferences for searching for files that are part of an assembly : How to use Search File Engine

Here is a model sample and its corresponding representation in Dtk_Component :

Each Dtk_Component has a type, a name and children.
There are 4 different types:

  • Virtual Component contains only children
  • A Prototype represents a model that can have 0 or several children. It must be referenced by an instance or a catalog (except if he is root).
  • An Instance has only one child which is the prototype and a placement matrix.
  • A Catalog has one or several children representing the different possibilities for an Assembly Tree (such as Scene in CatiaV5). Default is given by method GetDefaultChildInCatalog();.


    From Dtk_Component you have to call ReadComponent to get corresponding Construction Tree.


    Dtk_Node RootNode;
    Dtk_string ComponentName = inComponent->Name();
    /*Get the Construction tree for this prototype */
    err = inAPI->ReadComponent( inComponent, RootNode );
    if (err == dtkNoError && RootNode.IsNotNULL())
    {
    user_WriteNode(RootNode);
    }
    /*We close the opened Component and free his construction tree*/
    err = inAPI->EndComponent(inComponent);



If you need only data for visualisation you can call ReadComponentGraphic();
This method gives you a set of meshes for 3D files and a set of drawing for 2D files. Not all files contains such information so result may be empty : In this case you have to call ReadComponent to get all data.

You can also get a corresponding image preview with GetPreview() method.




Dtk_string ComponentName = inComponent->Name();
/*Get the Image Preview for this prototype */
Dtk_Preview Preview = inComponent->GetPreview();
/*Get the Graphical data for this prototype */
err = inAPI->ReadComponentGraphic( inObject, GraphData );
if (err == dtkNoError && GraphData.IsNotNULL())
{
user_WriteGraphicalData(GraphData);
}
/*We close the opened Component and free his construction tree*/
err = inAPI->EndComponent(inComponent);






Note about how to use colors in Assembly Tree :

Dtk_Component colors should prevail on any other defined colors A single blue Cube could be instantiated as green and red :

  • Green and red colors are stored at Dtk_Component upper level(Instance type)
  • Blue is stored in Dtk_Component child (Prototype type) or in Construction Tree (Dtk_Node). At screen, you'll see one red cube and one green cube.
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Dtk_API::EndComponent
Dtk_ErrorStatus EndComponent(Dtk_ComponentPtr &inComponent)
EndComponent.
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
Dtk_Node
This is the Node Class The Dtk_Node object is used to retrieve informations in a Dtk_ComponentPtr obj...
Definition: dtk_maindoc.hpp:230
Dtk_Preview
This is the Dtk_Preview class.
Definition: util_ent_dtk.hpp:688
Dtk_GraphicalData
This is the Dtk_GraphicalData Class. The Dtk_GraphicalDataPtr object is used to store preview data It...
Definition: dtk_graphical.hpp:27
Dtk_API::ReadComponentGraphic
Dtk_ErrorStatus ReadComponentGraphic(const Dtk_ComponentPtr &inComponent, Dtk_GraphicalDataPtr &outGraphicalData)
Read graphical data from Component (Call EndComponent to free data allocated)
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_API::ReadComponent
Dtk_ErrorStatus ReadComponent(const Dtk_ComponentPtr &inComponent, Dtk_NodePtr &outRootNode)
Read Component from Assembly Tree (Call EndComponent to free data allocated)
Dtk_API
Definition: dtk_api.hpp:75