How to get the objects created by a part import? I have the following code
NXOpen::PartImporter *partImporter = workPart->ImportManager()->CreatePartImporter(); partImporter->SetFileName(path); partImporter->SetScale(1.0); partImporter->SetCreateNamedGroup(false); partImporter->SetImportViews(false); partImporter->SetImportCamObjects(false); //!!!partImporter->SetCreateNamedGroup(true); partImporter->SetLayerOption(NXOpen::PartImporter::LayerOptionTypeOriginal); partImporter->SetDestinationCoordinateSystemSpecification(NXOpen::PartImporter::DestinationCoordinateSystemSpecificationTypeWork); NXOpen::Matrix3x3 matrix; matrix.Xx = 1.0;matrix.Xy = 0.0;matrix.Xz = 0.0;matrix.Yx = 0.0;matrix.Yy = 1.0;matrix.Yz = 0.0;matrix.Zx = 0.0;matrix.Zy = 0.0;matrix.Zz = 1.0; NXOpen::NXMatrix *nXMatrix = workPart->NXMatrices()->Create(matrix); partImporter->SetDestinationCoordinateSystem(nXMatrix); NXOpen::Point3d destinationPoint(0.0, 0.0, 0.0); partImporter->SetDestinationPoint(destinationPoint); partImporter->Commit(); std::vector<NXOpen::NXObject *> committedObjects = partImporter->GetCommittedObjects(); partImporter->Destroy();
If I SetCreateNamedGroup(true) I get a single object vector with the created named group inside as expected.
But I don't want to create a named group. I expected GetCommittedObjects to return the objects imported in this case. But the vector is always empty.
2 possible workarounds:
Any other less complicated idea? Is the builder working as designed or is it a bug?
Hmmm... The documentation does decribe the behavior that you are seeing: "You can access the named group which is created when importing the part by accessing the object array returned from the method Builder::GetCommittedObjects after you execute the Builder::Commit on the NXOpen:artImporter ." In the absence of any mention of getting the objects any other way, I think it is probably working as designed.
I like your first possible workaround. It seems like much less overhead than trying to compare the two lists of objects collected before and after the import.