DATAKIT SDK  V2026.4
StartAPIToParasolid.cpp File Reference

Functions

void ActivateApiOptions (Dtk_API *inoutMyApi)
 
void EnableReaders ()
 
int LaunchAPISampleToParasolid (int argc, char **argv)
 
Dtk_ErrorStatus ProcessCADFileToParasolid (const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
 
Dtk_ErrorStatus SetSchemaDirectory (Dtk_API *inoutMyApi)
 

Function Documentation

◆ ActivateApiOptions()

void ActivateApiOptions ( Dtk_API *  inoutMyApi)
8 {
9  DTK_UNUSED( inoutMyApi );
10 }

◆ 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 }

◆ LaunchAPISampleToParasolid()

int LaunchAPISampleToParasolid ( int  argc,
char **  argv 
)
32 {
33  // Enable all available Datakit readers.
34  EnableReaders();
35 
36  // Retrieve the current working directory so the Datakit API has a writable
37  // temporary directory available.
38 #ifndef Linux
39  wchar_t workingDirectory[ 1024 ];
40  wchar_t* retwc = _wgetcwd( workingDirectory, 1024 );
41  (void)retwc;
42 #else
43  char workingDirectory[ 1024 ];
44  getcwd( workingDirectory, 1024 );
45 #endif
46 
47  // Start the Datakit API.
48  Dtk_ErrorStatus errorStatus = dtkNoError;
49  cout << "Starting DATAKIT API" << endl;
50  Dtk_API* myAPI = Dtk_API::StartAPI( workingDirectory, errorStatus );
51  if( myAPI == NULL )
52  {
53  cout << "Cannot start DATAKIT API: " << errorStatus << endl;
54  return dtkErrorAPINotStarted;
55  }
56 
57  // Apply optional API settings (unit, tessellation quality, …).
58  ActivateApiOptions( myAPI );
59 
60  // Preserve native kernel data during reading if parasolid daata are stored in original file so that psw can write the
61  // original kernel geometry.
62  myAPI->ActivateKeepKernelData();
63 
64  // Set the schema directory
65  SetSchemaDirectory( myAPI );
66 
67  // Process each input file.
68  for( int i = 1; i < argc; ++i )
69  {
70  Dtk_string inputFile = argv[ i ];
71 
72  time_t startTime;
73  time( &startTime );
74 
75  // Output is written alongside the input file (empty folder = same dir).
76  Dtk_ErrorStatus curError = ProcessCADFileToParasolid( inputFile, "" );
77 
78  time_t stopTime;
79  time( &stopTime );
80 
81  if( curError != dtkNoError )
82  {
83  cout << "Error processing file " << inputFile.c_str()
84  << " (" << dtkTypeError( curError ).c_str() << ")" << endl;
85  }
86  else
87  {
88  double elapsedTime = difftime( stopTime, startTime );
89  cout << "File " << inputFile.c_str()
90  << " processed in " << elapsedTime << " s" << endl;
91  }
92  }
93 
94  // Stop the Datakit API and release all resources.
95  Dtk_API::StopAPI( myAPI );
96  cout << "Stopping DATAKIT API" << endl;
97 
98  return 0;
99 }

◆ ProcessCADFileToParasolid()

Dtk_ErrorStatus ProcessCADFileToParasolid ( const Dtk_string &  inInputFile,
const Dtk_string &  inOutputFolder 
)
20 {
21  Dtk_API* myAPI = Dtk_API::GetAPI();
22 
23  cout << "Processing file: " << inInputFile.c_str() << endl;
24 
25  // Optionally retrieve and display the source file version.
26  Dtk_string fileVersion;
27  Dtk_ErrorStatus stError = myAPI->GetFileVersion( inInputFile, fileVersion );
28  if( fileVersion.is_not_NULL() )
29  cout << "File version: " << fileVersion.c_str() << endl;
30  if( stError != dtkNoError )
31  {
32  cout << "Error retrieving file version: " << dtkTypeError( stError ).c_str() << endl;
33  return stError;
34  }
35 
36  // Optional: activate a log file to capture reader diagnostics.
37  myAPI->SetLogFile( "DtkLogFile.txt" );
38 
39  // Initialise the Parasolid writer to write a .x_t file alongside the input.
40  Dtk_ErrorStatus stErrorPsw = PswWriteInit( inInputFile, inOutputFolder );
41 
42  // Open the source document.
43  Dtk_MainDocPtr tmpDoc;
44  Dtk_ErrorStatus err = myAPI->OpenDocument( inInputFile, tmpDoc );
45 
46  if( err == dtkNoError && tmpDoc.IsNotNULL() )
47  {
48  // Traverse the document and write Parasolid output.
49  if( stErrorPsw == dtkNoError )
50  PswWriteDocument( tmpDoc );
51  }
52  else
53  {
54  cout << "Error OpenDocument: " << dtkTypeError( err ).c_str() << endl;
55  }
56 
57  // Close the source document and release its resources.
58  myAPI->EndDocument( tmpDoc );
59 
60  // Finalise and close the Parasolid output.
61  PswWriteEnd();
62 
63  return err;
64 }

◆ SetSchemaDirectory()

Dtk_ErrorStatus SetSchemaDirectory ( Dtk_API *  inoutMyApi)
83 {
84  Dtk_ErrorStatus schemaStatus;
85 
86  // Define the schema directory path.
87  Dtk_string schemaDirectory = "./Schema";
88 
89 #ifndef Linux
90  char tmpFullPathSchemaDir[_MAX_PATH];
91 
92  if (_fullpath(tmpFullPathSchemaDir, schemaDirectory.c_str(), _MAX_PATH) != NULL)
93  schemaStatus = inOutMyApi->SetSchemaDir(tmpFullPathSchemaDir);
94  else
95  schemaStatus = inOutMyApi->SetSchemaDir(schemaDirectory);
96 #else
97  schemaStatus = inOutMyApi->SetSchemaDir(schemaDirectory);
98 #endif
99 
100 #ifdef USE_PSKERNEL
101  if (schemaStatus != dtkNoError)
102  {
103  std::cout << "Schema directory error (required for readers based on PsKernel or CADDS): "
104  << dtkTypeError(schemaStatus).c_str() << std::endl;
105  }
106 #endif
107 
108  return schemaStatus;
109 }
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()
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()
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()
SetSchemaDirectory
Dtk_ErrorStatus SetSchemaDirectory(Dtk_API *inoutMyApi)
Definition: LibReadersSample/RunThroughAPI/GetStarted/EnableReaders.cpp:82
CatiaV4Reader::Enable
static Dtk_bool Enable()
ActivateApiOptions
void ActivateApiOptions(Dtk_API *inoutMyApi)
Definition: ActivateApiOptions.cpp:7
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)
RevitReader::Enable
static Dtk_bool Enable()
dtkErrorAPINotStarted
@ dtkErrorAPINotStarted
Definition: error_dtk.hpp:109
ProeReader::Enable
static Dtk_bool Enable()
CaddsReader::Enable
static Dtk_bool Enable()
InvReader::Enable
static Dtk_bool Enable()
PswWriteEnd
Dtk_ErrorStatus PswWriteEnd()
Definition: WriteParasolid.cpp:442
ProCeraReader::Enable
static Dtk_bool Enable()
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.
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
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()
UsdReader::Enable
static Dtk_bool Enable()
PswWriteDocument
void PswWriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteParasolid.cpp:349
XmtReader::Enable
static Dtk_bool Enable()
ProcessCADFileToParasolid
Dtk_ErrorStatus ProcessCADFileToParasolid(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: OpenDocumentToParasolid.cpp:18
Dtk_API::ActivateKeepKernelData
void ActivateKeepKernelData()
Keep Kernel Data option (see "How to use KeepKernelData option")
FbxReader::Enable
static Dtk_bool Enable()
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
PswWriteInit
Dtk_ErrorStatus PswWriteInit(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: WriteParasolid.cpp:388
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()
QifReader::Enable
static Dtk_bool Enable()
DTK_UNUSED
#define DTK_UNUSED(a)
Definition: define.h:729
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
EnableReaders
void EnableReaders()
Definition: LibReadersSample/RunThroughAPI/GetStarted/EnableReaders.cpp:12
Dtk_API
Definition: dtk_api.hpp:75
AcisReader::Enable
static Dtk_bool Enable()