DATAKIT API  V2025.1
Through Assemblies

Sample to write a Dtk_MainDoc
Sample to write a Dtk_Component
Sample to write a Dtk_Component type Instance
Sample to write a Dtk_Component type Prototype
Selection Set sample

Sample to write a Dtk_MainDoc

#include "datakit.h"
#include "../../WritingSample/PdfWrite/PdfWrite.hpp"
//This function is a sample on how to write document
// Dtk_Document represent Assembly tree of model
{
//First we get the root component in the document
Dtk_ComponentPtr RootComponent = inDocument->RootComponent();
//if no Error we write the Component
if (RootComponent.IsNotNULL())
{
{
PdfInitComponent(RootComponent);
}
//Go Through the Root Component and children
WriteComponent(RootComponent);
{
}
return dtkNoError;
}
}

Sample to write a Dtk_Component

#include "datakit.h"
#include "../../WritingSample/XmlWrite/XmlWrite.hpp"
//This function is a sample on how to write component :it is recursive function
// Dtk_Component can be an instance, a prototype and have children
{
//Datakit component are given in MM, if original model had other unit you can get it with GetConceptionUnitScale()
// UnitFactor = 25.4 for inch
double UnitFactor;
Dtk_ErrorStatus err = inComponent->GetConceptionUnitScale(UnitFactor);
//GetName
Dtk_string ComponentName = inComponent->Name();
//GetAttributes
Dtk_InfoPtr attributes = inComponent->GetInfos();
if (attributes.IsNotNULL())
{
int CompoActivationStatus = attributes->GetActivationFlag(); // if CompoActivationStatus == 0 Component and his children aren't visible
int CompoBlankedStatus = attributes->GetBlankedStatus(); // if CompoBlankedStatus == 1 Component and his children aren't visible
Dtk_RGB CompoColor = attributes->GetColor(); // if CompoBlankedStatus == 1 Component and his children are using this color
}
//You can GetPreview if you want to handle it
Dtk_PreviewPtr TmpPreview = inComponent->GetPreview();
if (TmpPreview.IsNotNULL())
{
Dtk_Int32 size = TmpPreview->GetStreamSize();
char *jpgimage = TmpPreview->GetStream();
Dtk_string Preview_name = "ComponentPreview.jpg";
FILE *jpg = Preview_name.OpenFile("wb");
if (jpg)
{
fwrite(jpgimage, sizeof(char), size, jpg);
fclose(jpg);
}
}
{
XmlInitComponent(inComponent);
}
//You have 4 types for Component
Dtk_Component::ComponentTypeEnum type = inComponent->ComponentType();
switch (type)
{
//Instance represent a prototype with a matrix placement
{
WriteInstance(inComponent, inMatrix);
break;
}
//Prototype (you have to check if you ever read and write it to don't waste time)
//you can use the method inComponent->GetID() to get Unique ID for Component
{
WritePrototype(inComponent, inMatrix);
break;
}
//Catalog Component represent a choice of several possible configuration
//(like scene in catiav5, workspace in catiav4, configuration in solidworks)
//Default is the first child
{
Dtk_string name = inComponent->Name();//Component name
Dtk_Size_t numComp = inComponent->GetNumChildren();
if (numComp > 0)
{
{
for (i = 0; i < numComp; i++)
{
Dtk_ComponentPtr child = inComponent->GetChild(i);
}
}
Dtk_Int32 defaultindex = inComponent->GetDefaultChildInCatalog(); //Get Default child to use
Dtk_ComponentPtr defaultchoice = inComponent->GetChild(defaultindex);
if (defaultchoice.IsNotNULL())
{
WriteComponent(defaultchoice, inMatrix);
}
}
//if you don't want to use default you have to scan all children and choose the one you want to convert (see their name)
break;
}
//Component containing only children
{
Dtk_string name;
Dtk_Size_t NumChildren;
name = inComponent->Name();//Component name
NumChildren = inComponent->GetNumChildren();
for (i = 0; i < NumChildren; i++)
{
Dtk_ComponentPtr child = inComponent->GetChild(i);
WriteComponent(child, inMatrix);
}
break;
}
}
{
}
return dtkNoError;
}

Sample to write a Dtk_Component type Instance

#include "datakit.h"
#include "../../WritingSample/PdfWrite/PdfWrite.hpp"
#include "../../WritingSample/XmlWrite/XmlWrite.hpp"
//This function is a sample on how to write component :it is recursive function
// Dtk_Component can be an instance, a prototype and have children
{
//Instance represent a prototype with a matrix placement
Dtk_string ComponentName;
ComponentName = inComponent->Name();//Component name
Dtk_ComponentPtr prototype = inComponent->GetChild(0);
Dtk_transfo matrix = inComponent->TransformationMatrix();
Dtk_ID pdfInstID = 0;
Dtk_ID childID = inComponent->GetChild(0)->GetID();
{
pdfInstID = PdfInitInstance(inComponent);
}
//Dtk_transfo newMatrix = inMatrix * matrix;
//you have to write matrix and instance the prototype
WriteComponent(prototype, Dtk_transfo());
{
PdfEndInstance(pdfInstID, childID);
}
if (ComponentProcessed.find(childID) < 0)
{
ComponentProcessed.push_back(childID);
}
return dtkNoError;
}

Sample to write a Dtk_Component type Prototype

#include "datakit.h"
#include "../../WritingSample/PdfWrite/PdfWrite.hpp"
#include "../../WritingSample/XmlWrite/XmlWrite.hpp"
#include "../ThroughData/WriteNode.hpp"
//To Flatten Assemblies
void WritePrototype(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
{
Dtk_ID ComponentID = inComponent->GetID();
Dtk_Int32 ComponentIndex;
ComponentIndex = ComponentProcessed.find(ComponentID);
if (ComponentIndex == -1)
{
Dtk_NodePtr RootNode;
//it can also contain some instances
Dtk_Size_t NumChildren = inComponent->GetNumChildren();
for (i = 0; i < NumChildren; i++)
{
Dtk_ComponentPtr child = inComponent->GetChild(i);
WriteComponent(child, inMatrix);
}
//Get the Construction tree for this prototype
if (inComponent->ComponentAvailability() == Dtk_Component::ComponentMissing)
else
err = inAPI->ReadComponent(inComponent, RootNode);
//a RootNode= NULL with err == dtkNoError means that component is empty
if (err == dtkNoError && RootNode.IsNotNULL())
{
// Set matrix to apply to all node if you flat assemblies
CurrentMatrix = inMatrix;
//Go Through the Root Node and children
WriteNode(RootNode);
{
XmlWriteGlobalDataSet(inComponent->GetGlobalDataSet());
Dtk_Size_t NumMetaData;
NumMetaData = inComponent->GetNumMetaData();
if (NumMetaData)
{
for (i = 0; i < NumMetaData; i++)
{
XmlWriteMetaData( inComponent->GetMetaData(i));
}
}
}
}
{
PdfWriteMetaData(inComponent);
}
//We close the opened Component and free his construction tree
err = inAPI->EndComponent(inComponent);
}
else
{
//Get the prototype you ever write
//The Component has a unique ID given by GetID to help to map it with your Write ID
{
}
}
}
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:689
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
Dtk_Info::GetBlankedStatus
int GetBlankedStatus() const
Retrieves the entity Blanked Status.
Dtk_Component::CatalogComponentType
@ CatalogComponentType
Definition: dtk_maindoc.hpp:579
dtkErrorFileNotExist
@ dtkErrorFileNotExist
Definition: error_dtk.hpp:95
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
XmlInitComponent
void XmlInitComponent(Dtk_ComponentPtr inComponent)
Definition: XmlWrite.cpp:50
XmlWriteMetaData
void XmlWriteMetaData(const Dtk_MetaDataPtr &inMetaData)
Definition: XmlWrite.cpp:130
XmlEndComponent
void XmlEndComponent()
Definition: XmlWrite.cpp:57
PdfWriteMetaData
void PdfWriteMetaData(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:117
XmlWriteGlobalDataSet
void XmlWriteGlobalDataSet(const Dtk_GlobalDataSetPtr &inSelectionSet)
Definition: XmlWrite.cpp:124
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
WriteDocument
Dtk_ErrorStatus WriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteDocument.cpp:12
PdfEndInstance
void PdfEndInstance(Dtk_ID pdfInstID, Dtk_ID childID)
Definition: PdfWrite.cpp:108
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Dtk_Info::GetColor
Dtk_RGB GetColor() const
Retrieves the entity color as Dtk_RGBA values.
Dtk_Info::GetActivationFlag
int GetActivationFlag() const
Dtk_API::EndComponent
Dtk_ErrorStatus EndComponent(Dtk_ComponentPtr &inComponent)
EndComponent.
Dtk_string::OpenFile
FILE * OpenFile(const Dtk_string &inRights) const
File Utility : Open a file with the given rights.
WriteComponent
Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix=Dtk_transfo())
Definition: WriteComponent.cpp:9
WritePrototype
void WritePrototype(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WritePrototype.cpp:14
Dtk_Component::VirtualComponentType
@ VirtualComponentType
Definition: dtk_maindoc.hpp:580
WriteComponent.hpp
Dtk_Component::InstanceComponentType
@ InstanceComponentType
Definition: dtk_maindoc.hpp:577
inputFileName
Dtk_string inputFileName
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
PdfInstanceExistingPrototype
void PdfInstanceExistingPrototype(Dtk_ID ComponentIndex)
Definition: PdfWrite.cpp:138
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:687
Dtk_Component::ComponentTypeEnum
ComponentTypeEnum
Definition: dtk_maindoc.hpp:576
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
WriteInstance
Dtk_ErrorStatus WriteInstance(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WriteInstance.cpp:14
CurrentMatrix
Dtk_transfo CurrentMatrix
Definition: WritePrototype.cpp:11
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
PdfInitInstance
Dtk_ID PdfInitInstance(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:90
ComponentProcessed
Dtk_tab< Dtk_ID > ComponentProcessed
Definition: WritePrototype.cpp:12
datakit.h
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
Dtk_Component::PrototypeComponentType
@ PrototypeComponentType
Definition: dtk_maindoc.hpp:578
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
Dtk_Component::ComponentMissing
@ ComponentMissing
Definition: dtk_maindoc.hpp:567
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)
WriteNode
Dtk_ErrorStatus WriteNode(Dtk_NodePtr inNode)
Definition: WriteNode.cpp:16
Dtk_RGB
Definition: dtk_rgb.hpp:7
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:26
dtkErrorNullPointer
@ dtkErrorNullPointer
Definition: error_dtk.hpp:23
Dtk_API
Definition: dtk_api.hpp:75
PdfEndComponent
void PdfEndComponent()
Definition: PdfWrite.cpp:151
PdfInitComponent
Dtk_ID PdfInitComponent(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:143