Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to delete component instance and its Assembly Constraints

Status
Not open for further replies.

grinch33

Mechanical
Jul 13, 2009
51
0
0
GB
In the past removing a component instance using
Code:
UF_ASSEM_remove_instance()
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 [smarty] 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. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Replies continue below

Recommended for you

For those of you that might be interested I found a solution. First some background..
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:
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;
}
One thing is that I had to add the Constraints to the delete list one-by-one because I couldn't figure out how to pass the vector of constraints. What I'd like to do is:
Code:
theSession->UpdateManager()->AddToDeleteList(constraints);
Anyone who knows how to do this I'd appreciate it..

Graham Inchley, Systems Developer, Sandvik Coromant. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Hello Graham,

Thanks for posting the discovery and background details.

The delete requires converting the vector of pointers into an array of NXObjects.

Code:
public:
int AddToDeleteList(
        array<NXObject> objects
)

HTH, Joe
 
Thanks Joe.
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. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Status
Not open for further replies.
Back
Top