Showing results for 
Search instead for 
Did you mean: 

Java: User Defined Object headache


I am currently working on some code to add a User Defined Object to a Component.  Is my understanding correct in thinking that the UDO is added to the component in the context of thework part?


So, I am essentually makin g these calls.  Depending on how I tweek different things (such as changing the work part to differnt things), I get an error message that states "Cannot link UDO to objects outside of work part'.  And to be clear, in my code the component is a child of the work component.  So I don't get it.  Please help.  I'm not on day 1 of this issue.

		// 'comp' is the component that needs the UDO associated with it

		Session session = (Session) SessionFactory.get("Session");
		Part origWorkPart =;

		// If the component does not have the workpart as a parent, change the workpart to the root part.
		Component tempComp = comp;
		boolean workPartIsAParent = false;
		while (comp.parent() != null) {
			tempComp = tempComp.parent();
			if (((Part)tempComp.prototype()) == origWorkPart) {
				workPartIsAParent = true;

		// At this point, 'comp' is found to not have the work parent as one of it's parents.
		if (!workPartIsAParent) {
			// Next 2 lines:
			// I tried parent() and it fails.
			// I tried parent().parent() and it fails.
			// when 'origWorkPart' is OK and woirk parts don't need to change,
			//         parent().parent().prototype() is the workpart relative to 'comp'.
			Part newWorkPart = (Part) comp.parent().prototype();;
			// TODO: Do I need to find the new 'comp' since I changed work parts?
			//       I tried this (code not in post and it did not help)

		try {
			UserDefinedClass udc = session.userDefinedClassManager().getUserDefinedClassFromClassName(

			// Ya, I tried a few things:
			UserDefinedObject[] udos =; // worked?  maybe?
//			UserDefinedObject[] udos = getPart().getPart().userDefinedObjectManager().getUdosOfClass(udc); // ORIG
//			UserDefinedObject[] udos = part.userDefinedObjectManager().getUdosOfClass(udc); // Try this

			UserDefinedObject assemblyUDO = null;
			boolean compIsLinked = false;
			if (udos.length > 0) {
				// always seems to be size of 0, code cut out since this
				// code NEVER executes.  (I'm maintaining old code.)
			} else {
				// length is 0:
				assemblyUDO =;

			if (!compIsLinked) {
				NXLogger.println("+++++ pushing link to comp: " + getAttr(NxObjAttrStringKey.PART_NUM));
				// NOTE: assemblyUDO is never null in my code
					new UserDefinedObject.LinkDefinition[] { new UserDefinedObject.LinkDefinition(
							comp, LinkStatus.UP_TO_DATE) });
		} finally {
			// change work part back to the original work part
			if (!workPartIsAParent) {;

Re: Java: User Defined Object headache

Siemens Creator Siemens Creator
Siemens Creator

Sorry, it was a mistake; I commented the line adding link to the UDO in the same time. Smiley Sad


Hi RunningMan.


I had the same problem while selecting some objects (links feature to other part geometry) and after testing many things I find a solution.

This is an extract of my c++ code to create an UDO.


      UserDefinedObjectManager* myUDOmanager = workPart->UserDefinedObjectManager();
      UserDefinedClass* replayUDOclass = theSession->UserDefinedClassManager()->GetUserDefinedClassFromClassName("Replay");
      UDO = myUDOmanager->CreateUserDefinedObject(replayUDOclass);

The solution is the last line: set interpart delay to true.

You may find something similar in Java.


I wish it solve your problem too.