Showing results for 
Search instead for 
Do you mean 
Reply

Best way to delete component instance and its Assembly Constraints

[ Edited ]

In the past removing a component instance using

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 Man Wink 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 Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5
3 REPLIES

Re: Best way to delete component instance and its Assembly Constraints

(broken record mode) have you tried to record a journal?

I know in interactive NX7.5 I get a question when deleting a component to the effect of "Do you want to delete the associated constraints?"

 

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Best way to delete component instance and its Assembly Constraints

[ Edited ]

It should delete the associated constraints too. Check if you are missing some parameters, and also do a regenerate and update after it

Re: Best way to delete component instance and its Assembly Constraints

@Ken_A

Yep, tried recording a journal and as expected I got the prompt about deleting the constraints. I answered Yes and the journal simply contained some code to find the constraints using a journal identifier and adding them to the delete list.

 

@bidhukanta

I thought it should delete the constraints too, but it just doesn't.

 

I didn't explain in the original post, but the overall picture is like this:

I have some legacy C code that is handling component instances, but a colleague wrote a C++ library to deal with the new Assembly Constraints when we moved to NX8.5. So I added a method to this library to handle deleting instances.

It seems in NXOpen there is no concept of an Instance, so I was using some convoluted code to get the part from the instance and trying to locate any Assembly Constraints that referred to that part.

 

However, the solution I came up with in the end came about after I realised that a UFUN Part Occurence is the same thing as an NXOpen Component. And a Component has a method to get its Assembly Constraints. Once I got these I could simply add these to the delete list:

		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);

 

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5