DATAKIT SDK  V2026.2
Get Started

Enable the readers you need
Start Dtk_API
Open a Dtk_MainDoc from any format

Enable the readers you need

//*********************************************************************************************************************
// This file demonstrates how to enable Datakit readers for various CAD and neutral formats.
// It also shows how to set the schema directory required for certain readers (UG NX, SolidWorks, Solid Edge, CADDS).
//*********************************************************************************************************************
#include "datakit.h"
// If you want to link with libraries using PsKernel, uncomment the following line:
// #define USE_PSKERNEL
// Enables all supported readers in the Datakit API.
{
// Supported formats and their extensions:
// Acis: .sat
// Catiav4: .model (2D/3D), .session, .dlv
// Catiav5: .CATDrawing, .CATPart, .CATProduct
// Cgr: .cgr
// Dwg: .dwg
// Iges: .igs, .iges
// Inventor: .ipt, .iam
// Jt: .jt
// Parasolid: .x_t, .x_b, .xmt
// Proe: .prt, .asm
// Solid Edge: .par, .asm
// Solidworks: .sldprt, .sldasm
// Step: .step, .stp
// UG NX: .prt (2D/3D)
// Vda: .vda
// ZW3D: .z3prt, .z3asm, .z3
// Enable the readers you want to use.
#ifndef Linux
#ifndef ARM64
#endif
#endif
#ifdef USE_PSKERNEL
#else
#endif
}
// Sets the Schema directory required for readers based on PsKernel (UG NX, SolidWorks, Solid Edge) or CADDS.
// Returns the status of the operation.
{
Dtk_ErrorStatus schemaStatus;
// Define the schema directory path.
Dtk_string schemaDirectory = "./Schema";
#ifndef Linux
char tmpFullPathSchemaDir[_MAX_PATH];
if (_fullpath(tmpFullPathSchemaDir, schemaDirectory.c_str(), _MAX_PATH) != NULL)
schemaStatus = inOutMyApi->SetSchemaDir(tmpFullPathSchemaDir);
else
schemaStatus = inOutMyApi->SetSchemaDir(schemaDirectory);
#else
schemaStatus = inOutMyApi->SetSchemaDir(schemaDirectory);
#endif
#ifdef USE_PSKERNEL
if (schemaStatus != dtkNoError)
{
std::cout << "Schema directory error (required for readers based on PsKernel or CADDS): "
<< dtkTypeError(schemaStatus).c_str() << std::endl;
}
#endif
return schemaStatus;
}

Start Dtk_API

//********************************************************************************************
// This sample reads input files via the Datakit API and creates PDF and XML output files
// in the same directory as the input files.
// It can optionally generate an XML dump of features from the input files.
//********************************************************************************************
#include <time.h>
#include "datakit.h"
#include "../../TesselationEngine/TesselationEngine.hpp"
#include "../../WritingSample/PdfWrite/PdfWrite.hpp"
#include "../../WritingSample/XmlWrite/XmlWrite.hpp"
#ifdef Linux
#include <unistd.h>
#endif
// Function declarations
extern void EnableReaders();
extern void ActivateApiOptions(Dtk_API *inoutMyApi);
extern void ActivateFeatureDump(Dtk_bool inDumpFeature);
extern Dtk_ErrorStatus ProcessCADFile(const Dtk_string& inInputFile, const Dtk_string& inOutputFolder);
// Entry point for processing files via Datakit API.
// Reads input files and generates PDF and XML output files.
// Arguments: list of input files to process.
int LaunchAPISample(int argc, char **argv)
{
////////// Project Options //////////
// Activate/Deactivate 3D PDF file creation (geometry, PMI, assembly, materials, etc.)
// This option requires Datakit tessellation.
// Activate/Deactivate dumping of DTK classes to XML file.
// Activate/Deactivate dumping of features (only for CatiaV5, Proe, UG NX).
////////// End Project Options //////
// Enable the readers you want to use.
// Set working directory for Dtk_API.
#ifndef Linux
wchar_t temporaryWorkingDirectory[1024];
wchar_t *retwc;
retwc = _wgetcwd(temporaryWorkingDirectory, 1024);
#else
char temporaryWorkingDirectory[1024];
getcwd(temporaryWorkingDirectory, 1024);
#endif
std::cout << "Starting DATAKIT API..." << std::endl;
// Start DATAKIT API with the working directory.
Dtk_ErrorStatus errorStatus = dtkNoError;
Dtk_API *myApi = Dtk_API::StartAPI(temporaryWorkingDirectory, errorStatus);
if (myApi == NULL)
{
// Report error if API fails to start.
std::cout << "Can't start DATAKIT API (error code: " << errorStatus << ")" << std::endl;
}
else
{
// Report successful API start.
std::cout << "DATAKIT API started successfully." << std::endl << std::endl;
}
// Activate additional API options.
// Initialize tessellation library if PDF export is enabled.
{
}
// Set Schema directory (required for some readers).
// Supported extensions: sat, prt, asm, igs, iges, jt, vda, CATDrawing, CATPart, CATProduct,
// cgr, model, x_t, x_b, xmt, par, sldprt, step, stp, ipt, iam, dwg, and more.
// Integration is identical for all supported file types.
// Process each input file.
for (int i = 1; i < argc; i++)
{
Dtk_string inputFile = argv[i];
// Start measuring processing time.
time_t startTime;
time(&startTime);
// Process the current file.
Dtk_ErrorStatus curError = ProcessCADFile(inputFile, "");
// Stop measuring processing time.
time_t stopTime;
time(&stopTime);
if (curError)
{
// Report any errors encountered during processing.
std::cout << "Error processing file: " << inputFile.c_str()
<< " (" << dtkTypeError(curError).c_str() << ")" << std::endl;
}
else
{
// Report successful processing time.
double elapsedTime = difftime(stopTime, startTime);
std::cout << "File: " << inputFile.c_str()
<< " successfully processed in " << elapsedTime << " s" << std::endl << std::endl;
}
}
// Close tessellation kernel if PDF export is enabled.
{
}
// Stop DATAKIT API at the end.
std::cout << "Stopping DATAKIT API" << std::endl;
return 0;
}

Open a Dtk_MainDoc from any format

//********************************************************************************************
// This sample reads input files via the Datakit API and creates PDF and XML output files
// in the same directory as the input files.
// It can optionally generate an XML dump of features from the input files.
//********************************************************************************************
#include "datakit.h"
#include "../../WritingSample/PdfWrite/PdfWrite.hpp"
#include "../../WritingSample/XmlWrite/XmlWrite.hpp"
#include "../ThroughAssemblies/WriteComponent.hpp"
// Global variable to track processed components (see WriteComponent.hpp)
// Processes a CAD file: it reads the file, writes PDF/XML outputs, and handles logging.
// Returns a Dtk_ErrorStatus indicating success (dtkNoError) or failure of the operation.
Dtk_ErrorStatus ProcessCADFile(const Dtk_string& inInputFile, const Dtk_string& inOutputFolder)
{
// Clear the list of processed components before starting.
// Get the current Datakit API instance.
std::cout << "Processing file: " << inInputFile.c_str() << std::endl;
// Retrieve and display the file version.
Dtk_string fileVersion;
Dtk_ErrorStatus stError = myApi->GetFileVersion(inInputFile, fileVersion);
if( fileVersion.is_not_NULL() )
{
// Display the file version.
std::cout << "File version: " << fileVersion.c_str() << std::endl;
}
if (stError != dtkNoError)
{
// Report error if unable to get file version.
std::cout << "Unable to get file version (error code: " << dtkTypeError(stError).c_str() << ")" << std::endl;
return stError;
}
// Set log file for the reader (inventory, missing files in assembly, etc.).
Dtk_string logFilePath = inInputFile.filename() + Dtk_string("-dtk.log");
myApi->SetLogFile( logFilePath );
// Initialize XML writing if XML export is enabled.
{
stErrorXml = XmlWriteInit(inInputFile, inOutputFolder);
}
// Initialize PDF writing if PDF export is enabled.
{
stErrorPdf = PdfInitWrite(inInputFile, inOutputFolder);
}
// Open the input file and obtain the corresponding document.
Dtk_ErrorStatus err = myApi->OpenDocument(inInputFile, tmpDoc);
// If successful, write the document (see WriteDocument.cpp)
if (err == dtkNoError && tmpDoc.IsNotNULL())
{
WriteDocument(tmpDoc);
}
else
{
// Report error if unable to open the document.
std::cout << "Error with OpenDocument (error code: " << err << " " << dtkTypeError(err).c_str() << ")" << std::endl;
}
// Close the opened document.
err = myApi->EndDocument(tmpDoc);
// Finalize XML writing if XML export is enabled.
{
}
// Finalize PDF writing if PDF export is enabled.
{
PdfEndWrite(inInputFile);
}
return err;
}
ObjReader::Enable
static Dtk_bool Enable()
Dtk_API::EndDocument
Dtk_ErrorStatus EndDocument(Dtk_MainDocPtr &inoutDocument)
Close a Document.
CgrReader::Enable
static Dtk_bool Enable()
SmgReader::Enable
static Dtk_bool Enable()
NavisReader::Enable
static Dtk_bool Enable()
LavaReader::Enable
static Dtk_bool Enable()
CgmReader::Enable
static Dtk_bool Enable()
DwgDtkReader::Enable
static Dtk_bool Enable()
GltfReader::Enable
static Dtk_bool Enable()
StlReader::Enable
static Dtk_bool Enable()
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
SwReader::Enable
static Dtk_bool Enable()
_3dmReader::Enable
static Dtk_bool Enable()
JtReader::Enable
static bool Enable()
ActivatePdfDump
void ActivatePdfDump(Dtk_bool inDumpPDF)
Definition: PdfWrite.cpp:24
CerconReader::Enable
static Dtk_bool Enable()
DTK_TRUE
#define DTK_TRUE
Definition: define.h:719
Dtk_API::StartAPI
static Dtk_API * StartAPI(const Dtk_string &inTemporyDirectory, Dtk_ErrorStatus &outErrorCode, const Dtk_string &inCustomerID=Dtk_string())
Start DATAKIT API.
InitTesselation
DtkErrorStatus InitTesselation()
Definition: TesselationEngine.cpp:18
F3dReader::Enable
static Dtk_bool Enable()
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
WriteDocument
Dtk_ErrorStatus WriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteDocument.cpp:14
PlmXmlReader::Enable
static Dtk_bool Enable()
SetSchemaDirectory
Dtk_ErrorStatus SetSchemaDirectory(Dtk_API *inOutMyApi)
Definition: EnableReaders.cpp:82
XmlWriteInit
Dtk_ErrorStatus XmlWriteInit(Dtk_string inInputFile, const Dtk_string &inOutputFolder)
Definition: XmlWrite.cpp:22
ActivateFeatureDump
void ActivateFeatureDump(Dtk_bool inDumpFeature)
Definition: WriteFeature.cpp:7
CatiaV4Reader::Enable
static Dtk_bool Enable()
StepReader::Enable
static Dtk_bool Enable()
Dtk_API::OpenDocument
Dtk_ErrorStatus OpenDocument(const Dtk_string &inInputFile, Dtk_MainDocPtr &outDocument)
Open a Document (call EndDocument to close it)
DTK_FALSE
#define DTK_FALSE
Definition: define.h:720
Dtk_bool
char Dtk_bool
Definition: define.h:717
RevitReader::Enable
static Dtk_bool Enable()
dtkErrorAPINotStarted
@ dtkErrorAPINotStarted
Definition: error_dtk.hpp:107
Dtk_API::SetSchemaDir
Dtk_ErrorStatus SetSchemaDir(const Dtk_string &inSchemaDir)
Set Schema Directory needed for Unigraphics, Parasolid, Solidedge, Solidworks and Jt readers.
ProeReader::Enable
static Dtk_bool Enable()
CaddsReader::Enable
static Dtk_bool Enable()
InvReader::Enable
static Dtk_bool Enable()
ProCeraReader::Enable
static Dtk_bool Enable()
ActivateXmlDump
void ActivateXmlDump(Dtk_bool inDumpXml)
Definition: XmlWrite.cpp:12
Zw3dReader::Enable
static Dtk_bool Enable()
Dtk_string::is_not_NULL
Dtk_bool is_not_NULL() const
UgReader::Enable
static Dtk_bool Enable()
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
EnableReaders
void EnableReaders()
Definition: EnableReaders.cpp:12
Dtk_string::filename
Dtk_string filename() const
File Utility : Retrieves the filename in Dtk_string form.
CatiaV5Reader::Enable
static Dtk_bool Enable()
PdfEndWrite
void PdfEndWrite(const Dtk_string &inInputFile)
Definition: PdfWrite.cpp:83
IgesReader::Enable
static Dtk_bool Enable()
EndTesselation
void EndTesselation()
Definition: TesselationEngine.cpp:47
CatiaV6Reader::Enable
static Dtk_bool Enable()
XmlWriteEnd
Dtk_ErrorStatus XmlWriteEnd()
Definition: XmlWrite.cpp:39
IfcReader::Enable
static Dtk_bool Enable()
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
DcmReader::Enable
static Dtk_bool Enable()
PsReader::Enable
static Dtk_bool Enable()
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
CerecReader::Enable
static Dtk_bool Enable()
CreoviewReader::Enable
static Dtk_bool Enable()
datakit.h
ProcessedComponents
Dtk_tab< Dtk_ID > ProcessedComponents
Definition: WritePrototype.cpp:16
ProcessCADFile
Dtk_ErrorStatus ProcessCADFile(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: OpenDocument.cpp:18
XmtReader::Enable
static Dtk_bool Enable()
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
LaunchAPISample
int LaunchAPISample(int argc, char **argv)
Definition: StartAPI.cpp:28
FbxReader::Enable
static Dtk_bool Enable()
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
PdfInitWrite
Dtk_ErrorStatus PdfInitWrite(const Dtk_string &inInputFileName, const Dtk_string &inOutputFolder)
Definition: PdfWrite.cpp:34
Dtk_API::GetFileVersion
Dtk_ErrorStatus GetFileVersion(const Dtk_string &inInputFile, Dtk_string &outVersion)
Independant method to get version of inInputFile.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:149
VdaReader::Enable
static Dtk_bool Enable()
SolidEdgeReader::Enable
static Dtk_bool Enable()
ActivateApiOptions
void ActivateApiOptions(Dtk_API *)
Definition: ActivateApiOptions.cpp:3
QifReader::Enable
static Dtk_bool Enable()
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:29
Dtk_API
Definition: dtk_api.hpp:75
AcisReader::Enable
static Dtk_bool Enable()