DATAKIT SDK  V2026.4
Using Parasolid
Note
Datakit packages do not include a Parasolid distribution. It is therefore the integrator's responsibility to set up their Parasolid environment.

Compile and link the Datakit integration sources against the headers/libraries of your Parasolid version.

Using Datakit SDK for Parasolid needs to :

  • go through assembly and construction tree like standard integration
  • then for Dtk_Node with type Dtk_Node::BodyType you can access to the Dtk_Body and convert it into Parasolid stream (in memory or through file)
  • load it into your existing parasolid session.

The following sample show you how to convert a Dtk_Body to a Parasolid :

Note
The source code lines checking import parasolid are commented to avoid dependencies
//.WriteNodeForParasolid
#include "datakit.h"
#include "psw/psw.hpp"
#include <map>
using namespace std;
// Function to write a body to a Parasolid file or memory stream
{
Dtk_tab<Dtk_ID> bodyIds;
DtkErrorStatus errf, err;
Dtk_InfoPtr infBody = inBody->info();
if( infBody.IsNULL() )
{
infBody = Dtk_Info::Create();
}
// Add custom attributes to the body and its faces, edges, and vertices
// Custom attributes are stored in the Parasolid file and can be retrieved later
// For example, you can use the following code to retrieve the custom attributes from a Parasolid file:
infBody->AddCustomerDefinedAttribute( L"my_body_id", inBody->get_info()->GetId() );
// You can also add custom attributes as string
infBody->AddCustomerDefinedAttribute( L"my_feature", Dtk_string( L"created_from_feature" ) );
for( size_t i = 0; i < inBody->GetNumTopologicalEntities( DTK_TYPE_UNKNOWN ); i++ )
{
Dtk_FacePtr face = Dtk_FacePtr::DtkDynamicCast( inBody->GetPtr( i ) );
if( face.IsNotNULL() && face->get_info().IsNotNULL() )
{
face->get_info()->AddCustomerDefinedAttribute( L"my_face_id", face->get_info()->GetId() );
}
Dtk_EdgePtr edge = Dtk_EdgePtr::DtkDynamicCast( inBody->GetPtr( i ) );
if( edge.IsNotNULL() && edge->get_info().IsNotNULL() )
{
edge->get_info()->AddCustomerDefinedAttribute( L"my_edge_id", edge->get_info()->GetId() );
}
Dtk_VertexPtr vertex = Dtk_VertexPtr::DtkDynamicCast( inBody->GetPtr( i ) );
if( vertex.IsNotNULL() && vertex->get_info().IsNotNULL() )
{
vertex->get_info()->AddCustomerDefinedAttribute( L"my_vertex_id", vertex->get_info()->GetId() );
}
}
// Initialize the Parasolid file in memory
Dtk_tab<char> outParasolidStream;
errf = psw_InitFile( outParasolidStream, 0 );
// Initialize the Parasolid file on disk (uncomment the following lines to write to disk)
// The filename is constructed using the body name and ID to ensure uniqueness
//Dtk_string myFilename = infBody->GetName() +"_";
//myFilename.add_int( infBody->GetId() );
//myFilename += "_myxbfile.x_b";
//errf = psw_InitFile( myFilename ,1,270);
// Write the body to the Parasolid file or memory stream
err = psw_WriteBody( inBody, bodyIds );
// End the Parasolid file and write the body IDs to the output file or memory stream
errf = psw_EndFile( bodyIds );
// The following code is commented out because it requires the Parasolid kernel headers and libraries to be linked
// It allows to read the Parasolid file from memory and transmit it to an existing Parasolid session
//// #include "Include_pskernel\parasolid_kernel.h"
//// PK_PART_receive_o_t recvOpts;
//// PK_PART_receive_o_m( recvOpts );
//// int nParts = 0;
//// PK_PART_t* parts = nullptr;
//// PK_MEMORY_block_t block;
//// block.next = nullptr;
//// block.n_bytes = static_cast< size_t >( outParasolidStream.size() );
//// block.bytes = &outParasolidStream.GetArray()[ 0 ];
////// Load stream into Parasolid memory and receive the parts (bodies) from it
//// PK_ERROR_code_t pkErr = PK_PART_receive_b( block, &recvOpts, &nParts, &parts);
////// Control by dumping a file
////PK_PART_transmit_o_t transmit_option;
////PK_PART_transmit_o_m( transmit_option );
////pkErr = PK_PART_transmit( nParts, parts, "xmtControlFile", &transmit_option );
if( err == dtkNoError )
{
for( Dtk_Size_t i = 0; i < bodyIds.size(); ++i )
outIds.push_back( bodyIds[ i ] );
}
else
{
cout << "Warning: psw_WriteBody failed: " << dtkTypeError( err ).c_str() << endl;
}
}
Dtk_Info::Create
static Dtk_SmartPtr< Dtk_Info > Create()
Calls default constructor to allocate a new object.
Dtk_Entity::get_info
Dtk_InfoPtr get_info() const
DTK_TYPE_UNKNOWN
@ DTK_TYPE_UNKNOWN
Definition: define.h:26
psw_InitFile
DtkErrorStatus psw_InitFile(const Dtk_string &inFileOut, Dtk_bool muteMode, Dtk_Int32 inVersion=180)
Initialise a file to be written.
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
Dtk_Info::AddCustomerDefinedAttribute
Dtk_ErrorStatus AddCustomerDefinedAttribute(Dtk_string name, Dtk_Val val)
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:711
psw.hpp
WriteBodyForParasolid
void WriteBodyForParasolid(Dtk_BodyPtr inBody, Dtk_tab< Dtk_ID > &outIds)
Definition: WriteBodyForParasolid.cpp:12
WriteParasolid.hpp
Dtk_SmartPtr< Dtk_Face >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Face > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr::IsNULL
Dtk_bool IsNULL() const
Definition: util_ptr_dtk.hpp:118
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.
psw_WriteBody
Dtk_ErrorStatus psw_WriteBody(Dtk_BodyPtr &inBody)
Writes a Body of a 3D part (3D content of a product), of any kind (solid, shell / faces,...
datakit.h
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:503
psw_EndFile
DtkErrorStatus psw_EndFile(Dtk_tab< Dtk_ID > &inTabIds, Dtk_bool binForceListOfBody=DTK_FALSE)
Ends the writing of the Parasolid (x_t or x_b) file.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:416
Dtk_Info::GetId
int GetId() const