Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

nxopen proximity example

[ Edited ]

Hello everyone,

 

please, I would like to know if someone has a demo build in Java for proximity search term? I'm trying to get number and identification of parts that are affected with proximity box.

 

Every information is welcome.

 

Thank you very much,

Alen

 

 

EDIT:

First acquire UFSession and then call .fltr to compare component boxes.

theUFSession.fltr().isObjInsideBoxZone(distance, component1.tag(), component2.tag())

 

9 REPLIES
Solution
Solution
Accepted by topic author AlenZ
‎08-26-2015 04:32 AM

Re: nxopen proximity example

 

Good morning.  You can probably do this in Java, but you are going to need to use some wrapped Open C calls.  You will need to look at these in the Open C Reference Guide, even if you want to use them in Java, because that is the document that explains the arguments, and how to use them.

 

So in the Open C Reference Guide, scroll down to the chapter called UF_FLTR and open it.

 

Read the Overview, then have a look at these functions:

 

UF_FLTR_create_box_zone

 

UF_FLTR_is_obj_inside_box_zone

 

UF_FLTR_is_obj_intsct_zone

 

Regards,

 

Steve

 

Re: nxopen proximity example

Hey Steve,

 

it never crossed my mind to have a look at documentation other than for Java. Tomorrow at work I'll take a look. Thank you for the info.

 

Still, any further information is welcome.

 

Kind regards,

Alen

Re: nxopen proximity example

[ Edited ]

You might want to also have a look to:

 

NXOpen::Assemblies::SearchTermBuilder

 

 

and its derivated classes like:

 

NXOpen::Assemblies::BoxSearchTermBuilder
NXOpen::Assemblies::ProximitySearchTermBuilder

 


 

They might very well suit your need.

Re: nxopen proximity example

[ Edited ]

Open C Reference guide suggests building box zone and has nothing related to 'proximity' as Java, .NET and other have (even this is it but not called proximity). It helps to understand how box zone works.

 

1. big question: Now, when I actually want to get proximity results, where should I start? From BoxSearchTermBuilder or ProximitySearchTermBuilder?

 

2. fact: I have 'ComponentAssembly c = part1.componentAssembly();' - I guess I need to build on top of this c (ComponentAssembly) to get the results? How to specify/tag a component on which I want to apply proximity search and how to acquire results?

 

3. question: How to get SearchResultElement[] to set setSeeds(SearchResultElement[] seeds) in ProximitySearchTermBuilder?

 

I highly appreciate any comment. Java example would be great.

 

Thank you for your time.

Re: nxopen proximity example

Can anyone provide step-by-step on how to get search results using proximity?

Thank you very much. This is the only place I can ask for support.

Re: nxopen proximity example

Has any got a code sample for this? I am attempting to do the same task in one of my programs. 

DHuskic Nx 9

Re: nxopen proximity example

[ Edited ]

This can help. It goes through all components and outputs results in console.

    // extract box and distance
    public static void proximity (List<Component> components, UFSession UFS, Part part) throws NXException, RemoteException {
    	Unit unitMillimeter = (Unit)part.unitCollection().findObject("MilliMeter");
    	Component[] c = components.toArray(new Component[components.size()]);        
    	for (int i = 1; i < c.length; i++) {
    		out.println(i + "/" + (c.length-1));
    		// box
			for (int j = 1; j < c.length; j++) {
				double boxSize = 15;
				boolean inBox = UFS.fltr().isObjInsideBoxZone(boxSize, c[i].tag(), c[j].tag());
				if (inBox && c[i] != c[j] && c[j].getChildren().length == 0 && c[i].getChildren().length == 0) {
					// inside box
					out.println("Box: " + c[i].displayName() + " catches box of " + c[j].displayName());
					
			        double[] corner = UFS.fltr().askBoxZone(c[i].tag()).corner;
			        double boxVolume = (2 * corner[0]) * (2 * corner[1]) * (2 * corner[2]);
			        EstabCompProps1Data modelVolume = UFS.weight().estabCompProps1(c[i].tag(), 0.9, false, UFWeight.UnitsType.UNITS_KMM);
			        double componentVolume = modelVolume.properties.volume;
			        double volumeRatio = componentVolume / boxVolume;
                }
			}
    		// distance
			for (int k = i; k < c.length; k++) {
				double minDistance = 10.00;
		        MeasureDistance measureDistance = part.measureManager().newDistance(unitMillimeter, nxopen.MeasureManager.MeasureType.MINIMUM, c[i], c[k]);
		        double distance = measureDistance.getValue();
		        measureDistance.dispose();
		        if (distance <= minDistance && distance != 0 && c[i] != c[k] && c[k].getChildren().length == 0 && c[i].getChildren().length == 0) {
		        	// until minimum distance
		        	out.println("Distance: " + c[i].displayName() + " close to " + c[k].displayName());
				}
		        if (distance == 0 && c[i] != c[k] && c[k].getChildren().length == 0 && c[i].getChildren().length == 0) {
		        	// components touch
		        	out.println("Touch/Intrusion: " + c[i].displayName() + " in contact with " + c[k].displayName());
				}
			}
		}
        
        // do something
        
    }

 

Important lines are:

boolean inBox = UFS.fltr().isObjInsideBoxZone(boxSize, c[i].tag(), c[j].tag());

and

 

MeasureDistance measureDistance = part.measureManager().newDistance(unitMillimeter, nxopen.MeasureManager.MeasureType.MINIMUM, c[i], c[k]);

double distance = measureDistance.getValue();

Those are two seperate things but distance could also help you Smiley Happy

 

 

You need to use: 

import nxopen.UFSession;

Example of a call:

.proximity(allComponents, theUFSession, rootPart);

All components:

public static List<Component> allComponents = new ArrayList<Component>();

 

It's ugly but I hope you get the idea. Learn how to select components and you are good with isObjInsideBoxZone.

 

Kind regards,

Alen

Re: nxopen proximity example

[ Edited ]

When attempting to use the NXOpen.UF.UFFltr.CreateBoxZone function, I am receiving a runtime error of: NX License Error: License server system does not support this feature. [ -18 ]. 

 

ufSes.Fltr.CreateBoxZone(targetComponent(0).Tag, "Target", centroid, corner, orientation, zoneTag)

 

When attempting to use the NxOpen.UF.UFFItr.IsObjIntsctZone function, I am receiving the runtime error of:  NXOpen.NXException: Internal error: an attempt was made to access an attribute not in the relevant class. This is when I use component tags for both inputs.

 

ufSes.Fltr.IsObjIntsctZone(0.0, targetComponent(0).Tag, components(0).Tag, flag2)

 

When attempting to use the NxOpen.UF.UFFItr.IsObjInsideBoxZone, I am not receiving any errors and the boolean output is correct. It returns true when components(0) is completely within targetComponent(0), else false.

 

ufSes.Fltr.IsObjInsideBoxZone(0.5, targetComponent(0).Tag, components(0).Tag, flag)

 

Some background information:

targetComponent(0) and components(0) are of type Component.

NX 9.0.3.4 MP13
VB.net
Visual Studio 2015

Re: nxopen proximity example

"When attempting to use the NXOpen.UF.UFFltr.CreateBoxZone function, I am receiving a runtime error of: NX License Error: License server system does not support this feature. [ -18 ]."

 

The .CreateBoxZone function requires an advanced assemblies license. The message indicates that NX was not able to access the proper license to run the function.