diff --git a/Param/Node/NodeUtil.h b/Param/Node/NodeUtil.h index 8f95fdb6145c5beda465206e25f8a3fab93b4dc4..b129278888235c13d59b7d30021705cbe9a023f7 100644 --- a/Param/Node/NodeUtil.h +++ b/Param/Node/NodeUtil.h @@ -48,10 +48,13 @@ template <typename T> std::vector<const T*> AllDescendantsOfType(const INode& no std::vector<const T*> result; for (const auto* child : node.nodeChildren()) { ASSERT(child); - if (const auto* t = dynamic_cast<const T*>(child)) - result.push_back(t); + // Since this function is used to define objects in the generated Python script, the order + // of the elements is important. The parent may call its children => the children must be + // defined before. So first add all children/descendants to the output vector. for (const auto* t : AllDescendantsOfType<T>(*child)) result.push_back(t); + if (const auto* t = dynamic_cast<const T*>(child)) + result.push_back(t); } return result; } diff --git a/Sim/Export/SampleToPython.cpp b/Sim/Export/SampleToPython.cpp index d276f15736bd47dba6f1bd397e6963129e7b143f..e6f6198d5dc5421b531ffa16948e970f051a35ea 100644 --- a/Sim/Export/SampleToPython.cpp +++ b/Sim/Export/SampleToPython.cpp @@ -524,11 +524,11 @@ std::string SampleToPython::sampleCode(const MultiLayer& sample) for (const auto* x : NodeUtil::AllDescendantsOfType<Particle>(sample)) objHandler.insertModel("particle", x); for (const auto* x : NodeUtil::AllDescendantsOfType<Compound>(sample)) - objHandler.insertModel("particle", x); + objHandler.insertModel("compound", x); for (const auto* x : NodeUtil::AllDescendantsOfType<CoreAndShell>(sample)) - objHandler.insertModel("particle", x); + objHandler.insertModel("coreshell", x); for (const auto* x : NodeUtil::AllDescendantsOfType<Mesocrystal>(sample)) - objHandler.insertModel("particle", x); + objHandler.insertModel("mesocrystal", x); for (const auto* x : NodeUtil::AllDescendantsOfType<Lattice2D>(sample)) objHandler.insertModel("lattice", x); for (const auto* x : NodeUtil::AllDescendantsOfType<Lattice3D>(sample))