Assembly: Make pre-solve and reverse move all the downstream parts (#24193)

This commit is contained in:
PaddleStroke
2025-10-07 18:44:11 +02:00
committed by GitHub
parent c64f06c3ad
commit 6282dd48bb
3 changed files with 105 additions and 61 deletions

View File

@@ -148,5 +148,28 @@ class AssemblyObject(Part):
Args:
fileName: The name of the file where the ASMT will be exported."""
...
@constmethod
def getDownstreamParts(
self, start_part: "App.DocumentObject", joint_to_ignore: "App.DocumentObject", /
) -> list["App.DocumentObject"]:
"""
Finds all parts connected to a start_part that are not connected to ground
when a specific joint is ignored.
getDownstreamParts(start_part, joint_to_ignore) -> list
This is used to find the entire rigid group of unconstrained components that
should be moved together during a pre-solve operation or a drag.
Args:
start_part: The App.DocumentObject to begin the search from.
joint_to_ignore: The App.DocumentObject (a joint) to temporarily
suppress during the connectivity check.
Returns:
A list of App.DocumentObject instances representing the downstream parts.
"""
...
Joints: Final[list]
"""A list of all joints this assembly has."""

View File

@@ -198,3 +198,36 @@ Py::List AssemblyObjectPy::getJoints() const
return ret;
}
PyObject* AssemblyObjectPy::getDownstreamParts(PyObject* args) const
{
PyObject* pyPart;
PyObject* pyJoint;
// Parse the two arguments: a part object and a joint object
if (!PyArg_ParseTuple(args,
"O!O!",
&(App::DocumentObjectPy::Type),
&pyPart,
&(App::DocumentObjectPy::Type),
&pyJoint)) {
return nullptr;
}
auto* part = static_cast<App::DocumentObjectPy*>(pyPart)->getDocumentObjectPtr();
auto* joint = static_cast<App::DocumentObjectPy*>(pyJoint)->getDocumentObjectPtr();
// Call the C++ method
std::vector<Assembly::ObjRef> downstreamParts =
this->getAssemblyObjectPtr()->getDownstreamParts(part, joint);
// Convert the result into a Python list of DocumentObjects
Py::List ret;
for (const auto& objRef : downstreamParts) {
if (objRef.obj) {
ret.append(Py::Object(objRef.obj->getPyObject(), true));
}
}
return Py::new_reference_to(ret);
}