DATAKIT SDK  V2026.4
BomStartAPI.cpp File Reference

Functions

void EnableReaders ()
 
int LaunchBillOfMaterialSample (int argc, char **argv)
 
static Dtk_ErrorStatus ProcessFile (const Dtk_string &inFilePath)
 

Function Documentation

◆ EnableReaders()

void EnableReaders ( )
13 {
14  // Supported formats and their extensions:
15  // Acis: .sat
16  // Catiav4: .model (2D/3D), .session, .dlv
17  // Catiav5: .CATDrawing, .CATPart, .CATProduct
18  // Cgr: .cgr
19  // Dwg: .dwg
20  // Iges: .igs, .iges
21  // Inventor: .ipt, .iam
22  // Jt: .jt
23  // Parasolid: .x_t, .x_b, .xmt
24  // Proe: .prt, .asm
25  // Solid Edge: .par, .asm
26  // Solidworks: .sldprt, .sldasm
27  // Step: .step, .stp
28  // UG NX: .prt (2D/3D)
29  // Vda: .vda
30  // ZW3D: .z3prt, .z3asm, .z3
31 
32  // Enable the readers you want to use.
35 #ifndef Linux
36 #ifndef ARM64
38 #endif
39 #endif
62 #ifdef USE_PSKERNEL
64 #else
66 #endif
78 }

◆ LaunchBillOfMaterialSample()

int LaunchBillOfMaterialSample ( int  argc,
char **  argv 
)
78 {
79  // Retrieve the current working directory (used as Datakit's working dir).
80 #ifndef Linux
81  wchar_t workingDirectory[1024];
82  _wgetcwd(workingDirectory, 1024);
83 #else
84  char workingDirectory[1024];
85  getcwd(workingDirectory, 1024);
86 #endif
87 
88  std::cout << "Starting DATAKIT API..." << std::endl;
89 
90  // Enable all required readers before starting the API.
91  EnableReaders();
92 
93  // Start the Datakit API.
94  Dtk_ErrorStatus errorStatus = dtkNoError;
95  Dtk_API *myApi = Dtk_API::StartAPI(workingDirectory, errorStatus);
96  if (myApi == NULL)
97  {
98  std::cout << "Error: cannot start DATAKIT API (code: " << errorStatus << ")" << std::endl;
99  return errorStatus;
100  }
101  std::cout << "DATAKIT API started successfully." << std::endl;
102 
103  // Process each input file provided on the command line.
104  int returnCode = 0;
105  for (int i = 1; i < argc; ++i)
106  {
107  Dtk_string inputFile(argv[i]);
108  Dtk_ErrorStatus fileErr = ProcessFile(inputFile);
109  if (fileErr != dtkNoError)
110  returnCode = static_cast<int>(fileErr);
111  }
112 
113  // Stop the Datakit API and release all resources.
114  Dtk_API::StopAPI( myApi );
115  std::cout << std::endl << "DATAKIT API stopped." << std::endl;
116 
117  return returnCode;
118 }

◆ ProcessFile()

static Dtk_ErrorStatus ProcessFile ( const Dtk_string &  inFilePath)
static
22 {
23  Dtk_API *myApi = Dtk_API::GetAPI();
24 
25  std::cout << "Processing: " << inFilePath.c_str() << std::endl;
26 
27  // Retrieve and display the file version (format-specific version string).
28  Dtk_string fileVersion;
29  Dtk_ErrorStatus err = myApi->GetFileVersion(inFilePath, fileVersion);
30  if( fileVersion.is_not_NULL() )
31  {
32  // Display the file version.
33  std::cout << "File version: " << fileVersion.c_str() << std::endl;
34  }
35 
36  if( err != dtkNoError )
37  {
38  // Report error if unable to get file version.
39  std::cout << "Unable to get file version (error code: " << dtkTypeError( err ).c_str() << ")" << std::endl;
40  return err;
41  }
42 
43  // Set a log file for reader diagnostics (missing sub-files, etc.).
44  Dtk_string logFilePath = inFilePath.filename() + Dtk_string("-bom.log");
45  myApi->SetLogFile(logFilePath);
46 
47  // Open the document and obtain the root component.
48  Dtk_MainDocPtr doc;
49  err = myApi->OpenDocument(inFilePath, doc);
50  if (err != dtkNoError || doc.IsNULL())
51  {
52  std::cout << "Error: unable to open document (code: "
53  << dtkTypeError(err).c_str() << ")\n";
54  return (err != dtkNoError) ? err : dtkErrorNullPointer;
55  }
56 
57  // Collect the BOM entries by traversing the assembly tree.
58  Dtk_tab<BomEntry> bomEntries;
59  CreateBomForMainDoc(doc, bomEntries);
60 
61  // Print the hierarchical BOM tree.
62  PrintBom(bomEntries);
63 
64  // Print a summary of unique parts and their occurrence counts.
65  PrintBomSummary(bomEntries);
66 
67  myApi->EndDocument( doc );
68 
69  return dtkNoError;
70 }
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()
DwgDtkReader::Enable
static Dtk_bool Enable()
GltfReader::Enable
static Dtk_bool Enable()
StlReader::Enable
static Dtk_bool Enable()
SwReader::Enable
static Dtk_bool Enable()
_3dmReader::Enable
static Dtk_bool Enable()
JtReader::Enable
static bool Enable()
CerconReader::Enable
static Dtk_bool Enable()
Dtk_API::StartAPI
static Dtk_API * StartAPI(const Dtk_string &inTemporyDirectory, Dtk_ErrorStatus &outErrorCode, const Dtk_string &inCustomerID=Dtk_string())
Start DATAKIT API.
F3dReader::Enable
static Dtk_bool Enable()
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
PlmXmlReader::Enable
static Dtk_bool Enable()
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)
ProcessFile
static Dtk_ErrorStatus ProcessFile(const Dtk_string &inFilePath)
Definition: BomStartAPI.cpp:21
RevitReader::Enable
static Dtk_bool Enable()
ProeReader::Enable
static Dtk_bool Enable()
CaddsReader::Enable
static Dtk_bool Enable()
InvReader::Enable
static Dtk_bool Enable()
ProCeraReader::Enable
static Dtk_bool Enable()
EnableReaders
void EnableReaders()
Definition: LibReadersSample/RunThroughAPI/GetStarted/EnableReaders.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.
Dtk_string::filename
Dtk_string filename() const
File Utility : Retrieves the filename in Dtk_string form.
CatiaV5Reader::Enable
static Dtk_bool Enable()
IgesReader::Enable
static Dtk_bool Enable()
CatiaV6Reader::Enable
static Dtk_bool Enable()
IfcReader::Enable
static Dtk_bool Enable()
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr::IsNULL
Dtk_bool IsNULL() const
Definition: util_ptr_dtk.hpp:118
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.
PrintBomSummary
void PrintBomSummary(const Dtk_tab< BomEntry > &inBomEntries)
Definition: BillOfMaterial.cpp:178
CerecReader::Enable
static Dtk_bool Enable()
CreoviewReader::Enable
static Dtk_bool Enable()
UsdReader::Enable
static Dtk_bool Enable()
XmtReader::Enable
static Dtk_bool Enable()
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
FbxReader::Enable
static Dtk_bool Enable()
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
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:151
VdaReader::Enable
static Dtk_bool Enable()
SolidEdgeReader::Enable
static Dtk_bool Enable()
CreateBomForMainDoc
void CreateBomForMainDoc(Dtk_MainDocPtr inMainDoc, Dtk_tab< BomEntry > &outBomEntries)
Definition: BillOfMaterial.cpp:24
QifReader::Enable
static Dtk_bool Enable()
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
dtkErrorNullPointer
@ dtkErrorNullPointer
Definition: error_dtk.hpp:23
PrintBom
void PrintBom(const Dtk_tab< BomEntry > &inBomEntries)
Definition: BillOfMaterial.cpp:133
Dtk_API
Definition: dtk_api.hpp:75
AcisReader::Enable
static Dtk_bool Enable()