Best way to delete component instance and its Assembly Constraints
Best way to delete component instance and its Assembly Constraints
(OP)
In the past removing a component instance using
automatically removed any Mating Conditions for that instance.
However since moving to NX8.5 (and using Assembly Constraints) the Assemby Constraints do not get deleted using this function, instead they are left in the part with the constraint definition partially unset.
To reproduce the old behaviour I've been interrogating the instance to get the constraints and deleting them before remoing the instance, which is quite a bit of code.
Recently someone pointed out that I have a bug in this code. So I thought I'd ask you experts
if there was a better way.
Interactively when you delete an instance you get asked if you'd like to delete the Assembly Constraints, but is there some way to do this automatically in code?
Or to put it another way, if deleting the constraints automatically is not possible, what is the easiest way to find the constraints that position a given component instance?
CODE -->
UF_ASSEM_remove_instance()
However since moving to NX8.5 (and using Assembly Constraints) the Assemby Constraints do not get deleted using this function, instead they are left in the part with the constraint definition partially unset.
To reproduce the old behaviour I've been interrogating the instance to get the constraints and deleting them before remoing the instance, which is quite a bit of code.
Recently someone pointed out that I have a bug in this code. So I thought I'd ask you experts
if there was a better way.Interactively when you delete an instance you get asked if you'd like to delete the Assembly Constraints, but is there some way to do this automatically in code?
Or to put it another way, if deleting the constraints automatically is not possible, what is the easiest way to find the constraints that position a given component instance?
Graham Inchley, Systems Developer, Sandvik Coromant. www.sandvik.com
HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5





RE: Best way to delete component instance and its Assembly Constraints
We have a library of functions written in C. With the introduction of NX8.5 and Assembly Constraints the C code can no longer provide all the required functionality. To save having to rewrite the whole thing we created a C++ library to just cover the new NX8.5 stuff, and have the C library call that when required. It is in this C++ library that I was having problems. What I was doing was passing into a C++ function a tag_t of a component instance.
The solution I came up with was to get the Part Occurrence of the instance and then using NXObjectManager get the NXObject of that Part Occurrence and cast it to Component.
This then allowed me to use the function GetConstraints provided by Component. Once I have the constraints I can simply delete them.
CODE --> C++
DllExport int ASSYCONSTRAINT_RemoveConstraintsFromInstance(tag_t instance) { char Msg[133]; try{ tag_t partOccToCheck=UF_ASSEM_ask_part_occ_of_inst(NULL_TAG,instance); Session *theSession = Session::GetSession(); Assemblies::Component *comp=dynamic_cast<Assemblies::Component *>(NXObjectManager::Get(partOccToCheck)); std::vector<Positioning::ComponentConstraint *> constraints=comp->GetConstraints(); Session::UndoMarkId undoId = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Delete constraints"); for(std::vector<Positioning::ComponentConstraint *>::iterator it = constraints.begin(); it != constraints.end(); ++it) { theSession->UpdateManager()->AddToDeleteList(*it); } theSession->UpdateManager()->DoUpdate(undoId); theSession->DeleteUndoMark(undoId, NULL); } catch(NXOpen::NXException &exception) { strcpy(Msg, exception.GetMessage()); UGCLOG_ErrorNX(exception.ErrorCode(), Msg, "Failed to get list of constraints instance is involved in"); return FALSE; } return TRUE; }CODE --> C++
Graham Inchley, Systems Developer, Sandvik Coromant. www.sandvik.com
HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
RE: Best way to delete component instance and its Assembly Constraints
Thanks for posting the discovery and background details.
The delete requires converting the vector of pointers into an array of NXObjects.
CODE --> NXOpen_API
public: int AddToDeleteList( array<NXObject> objects )HTH, Joe
RE: Best way to delete component instance and its Assembly Constraints
I'm mainly programming in Java these days so dabbling in C++ is 'frustrating'. Could you give me a hint how to convert an array of ComponentConstraints to an array of NXObjects?
I presume I could iterate over the array I have and copy each one into a new NXObject array, but there must be a better way..
Graham Inchley, Systems Developer, Sandvik Coromant. www.sandvik.com
HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5