DATAKIT API  V2025.1
Plmxml Write Samples

Table Of Contents:


Full samples source code

0.Introduction

PLMXML allows to write assemblies, where each leaf is a part written in another format. For our examples, we will write JT leaves, using Datakit JT Writer.

Before writing PLMXML files, you need to initialise Datakit API.

Checking the main, we need to :

  • start Datakit API with Dtk_API::StartAPI function, and precise the working directory as its mandatory first parameter
  • intialise tessellation, request for JT writer, we will need it to store Dtk_BodyPtr
  • We remove wire creation while tessellating.
  • stop Datakit API at the end with Dtk_API::StopAPI

    //start_of_plmxmlwmain
    int PlmxmlWriteSample(const Dtk_string& inResultDirectory)
    {
    std::cout << endl << "----------------------------------------------" << endl;
    std::cout << "Plmxml Write start" << endl;
    tess_InitTesselation("./", 0.005); // For JT : Init Tessellation : working directory and default tolerance (needed for writing bodies)
    tess_ComputeBoundariesFromMesh(0); // Disable wire creation on mesh during Brep tessellation.
    int err = PlmxmlwritesampleJT(inResultDirectory);
    tess_EndTesselation(); // End of tessellation
    std::cout << "Plmxml Write end" << endl;
    return err;
    }
    //end_of_plmxmlwmain

1.Assembly sample

This is a sample writing a simple assembly with instances, and metadatas.

//start_of_plmxmlwsample
template <typename T>
inline void Shift(T& mesh, double sh)
{
t.addTranslate(Dtk_dir(sh, 0, 0));
mesh->Transform(t);
}
{
Dtk_Jtw_Interface J(ficname,err);
CHECK_OK(err);
CHECK_OK(J.AddBody(body));
return dtkNoError;
}
{
// create JT leaves
Dtk_string outputDirectory = inResultDirectory + L"dtk/Plmxml/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
Dtk_string axlename = outputDirectory + L"axle.jt";
Dtk_string wheelname = outputDirectory + L"wheel.jt";
Dtk_string plmxmlfile = outputDirectory + L"sample1.plmxml";
CHECK_OK(CreateJtFileForPLMXML(axlename, axle));
CHECK_OK(CreateJtFileForPLMXML(wheelname, wheel));
// prepare datas for PLMXML
Dtk_Int64 id_of_wheel = 1;
Dtk_Int64 id_of_axles = 2;
Dtk_dir X(1, 0, 0);
Dtk_dir Y(0, 1, 0);
Dtk_dir Z(0, 0, 1);
// create PLMXML
Dtk_Plmxmlw_Interface P(plmxmlfile, err, 0.001); // scale millimeters to meters
CHECK_OK(err);
CHECK_OK(P.OpenInstance("RootNode")); // Rootnode creation
CHECK_OK(P.OpenInstance("Axles", id_of_axles)); // open Axles, give an ID for future reinstance, placement by default : identity matrix
CHECK_OK(P.OpenInstance("Axle")); // open
CHECK_OK(P.SetExternFic(axlename));
CHECK_OK(P.CloseLastInstance()); // close Axle
CHECK_OK(P.OpenInstance("Wheels")); // open
CHECK_OK(P.OpenInstance("Wheel", id_of_wheel, Dtk_transfo(X, Y, Z, Dtk_pnt(0, 0, 5)))); // open instance
CHECK_OK(P.SetExternFic(wheelname));
CHECK_OK(P.CloseLastInstance()); // close Wheel
CHECK_OK(P.OpenInstance("Wheel2", id_of_wheel, Dtk_transfo(X, -Y, -Z, Dtk_pnt()), meta1)); // open reinstance
CHECK_OK(P.CloseLastInstance()); // reinstancied : must close Wheel immediatly.
CHECK_OK(P.CloseLastInstance()); // close Wheels
CHECK_OK(P.CloseLastInstance()); // close Axles
CHECK_OK(P.OpenInstance("Axles2", id_of_axles, Dtk_transfo(X, Y, Z, Dtk_pnt(10, 0, 0)),meta2)); // reinstance whole subassembly with matrix
CHECK_OK(P.CloseLastInstance()); // reinstancied : must close Wheel immediatly.
CHECK_OK(P.CloseLastInstance()); // close RootNode
std::cout << "=> " << plmxmlfile.c_str() << endl;
return dtkNoError;// Automatic Finish while P released
}
//end_of_plmxmlwsample

Lets see the function PlmxmlwritesampleJT. We provide the ouptput directory.

  • First, we create each parts. In our example, we create JT parts.
    We create 2 cylinders, axle and wheel, radius 0.2 meters, height 5 meters for axle, and radius 1 meter and height 1 meter for wheel.
    Note that PLMXML unit is in meters.
    Function CreateJtFileForPLMXML create the JT files, check Jt Writer documentation for more options for these files.
    You can check axle.jt and wheel.jt from this point into the inResultDirectory.
  • Next, we prepare datas for PLMXML, vectors X,Y,Z for assemblies matrices, metadatas, and id for reinstancied parts or subassemblies.
    meta1 will contain 2 datas ("One","Two"), meta2 will contain one data "Other"
  • Then creating the PLMXML
    The constructor needs plmxml file, gives back an output error (checked after), and also 0.001 : this is a scale between millimeters and meters, because we will provide all matrix in millimeters after, so we need to scale to meters.
    We open the RootNode.
    Then we create the node "Axles" : we provide id_of_axles because we will reinstance the whole subassembly "Axels" later. Note that you can provide id you want.
    We create subassembly "Axle", and then add the extern file "axlename" that is a JT file.
    We create subassembly "wheels"
    We create subassembly "wheel", providing id_of_wheel for later, and a matrix.
    For "wheel2" : we reuse id_of_wheel : it means we reinstanciate the same wheel (with another matrice), do not call SetExternFic anymore for wheel, juste CloseLastInstance immediatly
    We also provide "meta1" to "wheel2" instance.
    We close Wheels ans Axles.
    Then we reinstanciate whole Axles subassembly, calling it "Axles2", and reclose immediatly. We also provide "meta2"
    The destructor of P finish the process.



    Here is the result : we use JT2Go to see the result, and we retrieve the fullassembly




We see the metadatas on the selected instances.




We see unit is in meters.


Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
Dtk_Plmxmlw_Interface
Definition: plmxmlw.hpp:12
sampleWriter::CreateCyl
Dtk_BodyPtr CreateCyl(double radius, double height)
Definition: testcreatecube.cpp:1791
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
tess_InitTesselation
int tess_InitTesselation(Dtk_string inWorkingDirectory, double inTolerance)
Init the tesselation library.
PlmxmlwritesampleJT
Dtk_ErrorStatus PlmxmlwritesampleJT(const Dtk_string &inResultDirectory)
Definition: testlibplmxmlwrite.cpp:36
Dtk_Int64
int64_t Dtk_Int64
Definition: define.h:692
CreateJtFileForPLMXML
Dtk_ErrorStatus CreateJtFileForPLMXML(const Dtk_string &ficname, const Dtk_BodyPtr &body)
Definition: testlibplmxmlwrite.cpp:27
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
CHECK_OK
#define CHECK_OK(X)
Definition: testwriters.h:9
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
Dtk_MetaData::TypeParameter
@ TypeParameter
Definition: dtk_metadata.hpp:32
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
tess_ComputeBoundariesFromMesh
int tess_ComputeBoundariesFromMesh()
: Check value of option memorize noundaries of mesh
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
tess_EndTesselation
void tess_EndTesselation()
Free the data used by tesselation library.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:415
Dtk_Jtw_Interface
This is Jt Interface class used to write Jt files.
Definition: jtw.h:8
Shift
void Shift(T &mesh, double sh)
Definition: testlibplmxmlwrite.cpp:20
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
Dtk_Jtw_Interface::AddBody
Dtk_ErrorStatus AddBody(const Dtk_BodyPtr &inToWrite, const Dtk_tab< Dtk_Float32 > &makelods=Dtk_tab< Dtk_Float32 >(), Dtk_Float32 inLossytol=0)
Add a body into the current node.
PlmxmlWriteSample
int PlmxmlWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibplmxmlwrite.cpp:100
Dtk_MetaData::CreateMetaData
static Dtk_MetaDataPtr CreateMetaData(const MetaDataTypeEnum &inEnumType, Dtk_string inTitle, Dtk_string inValue, Dtk_string inValueType=Dtk_string(L"STRING"))
Create a Dtk_MetaDataPtr .