×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Best way to delete component instance and its Assembly Constraints

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

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. 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

(OP)
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 --> 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;
} 
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 --> C++

theSession->UpdateManager()->AddToDeleteList(constraints); 
Anyone who knows how to do this I'd appreciate it..

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

Hello Graham,

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

(OP)
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. 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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources