Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

NX Open selection dialog filter

Status
Not open for further replies.

PabloAZ

Aerospace
Joined
Nov 28, 2013
Messages
2
Location
US
Hi everyone,

I have a few days programming Journals for NX in java and right now I'm stuck with a dialog option.

I have a selection dialog created (aside with some buttons) but I can't find the way to add a filter to it so when the dialog pops up to the user he/she is only able to select components (not solid, facets, curves, etc.)

I found the following object within API documentation (addFilterHandler) but I'm having a hard time to give it the adequate variables to make it work.

Below are two parts of the code including what I'm trying to tweak:

---------------
---------------
public static Session theSession = null;
public static UI theUI = null;
static Menu_MoveCSYS theMenu_MoveCSYS;
private String theDialogName;
private nxopen.blockstyler.BlockDialog theDialog;
private nxopen.blockstyler.UIBlock group0;// Block type: Group
private nxopen.blockstyler.UIBlock selection0;// Block type: Selection
private nxopen.blockstyler.UIBlock group01;// Block type: Group
private nxopen.blockstyler.UIBlock button0;// Block type: Button
private nxopen.blockstyler.UIBlock button01;// Block type: Button
private nxopen.blockstyler.UIBlock button02;// Block type: Button
...
..
.
theSession = (Session)SessionFactory.get("Session");
theUI = (UI)SessionFactory.get("UI");
theDialogName = "C:\\ACTIVEPROCESS\\ActiveProcessWorkSpace\\MoveCSYS\\Other\\Menu_MoveCSYS.dlx";
theDialog = theUI.createDialog(theDialogName);
theDialog.addApplyHandler(this);

theDialog.addFilterHandler(BlockDialog.Filter( selection0 , [HERE IS WHERE I DON'T KNOW WHAT TO ENTER]));

/*
* In the API I found the following method for a Dialog:
* BlockDialog.addFilterHandler(BlockDialog.Filter cb)
* Then the BlockDialog.Filter method has the following data:
* it has an int method that needs the selection block (selection0, and some sort of TaggedObject type object):
* int filter(UIBlock selectionBlock, TaggedObject selectedObject);
*/

theDialog.addUpdateHandler(this);
theDialog.addCancelHandler(this);
theDialog.addInitializeHandler(this);
theDialog.addDialogShownHandler(this);

----------
----------

Do you have any idea that may solve this issue? I can't leave it to the user to be able to select other stuff different from components because the program would fail.

Thanks in advance for your help & time!
 
Hi,
What you need to do is have your class implement the interface BlockDialog.Filter:
Java:
public class MyBlockDialog implements BlockDialog.Filter
{
}
Then you are compelled to create a method named filter that accepts 2 arguments:
Java:
@Override
public final int filter(nxopen.blockstyler.UIBlock block,
	nxopen.TaggedObject selectedObject) {
	// Insert your code here to filter the object (check its type, name, or whatever)
	// This method will be called for ALL selection blocks on your dialog. To have
	// different filters for each selection block, check the name of the 'block'
	// parameter.
}
Finally you need to tell the system to use this filter callback. Java is a bit different to other languages here, you can't pass a pointer to the callback, instead you have said that your class implements that callback. So all you have to do is pass your class into the addFilterHandler() method:
Java:
theDialog.addFilterHandler(this);
This is the line of code you were having problems with.
 
Hi grinch33!

Thanks a lot for your answer! I tried what you said without luck and I got stuck with BlockStyler coding; I think I may be missing something within the constructor method as well as being able to filter the components inside the filter callback (I did not know how to indicate the program when the selected item is a component or not). Because of project delivery time matters, I decided to switch to use UIStyler coding, which was way easier to figure out. Now it works like a charm! I'll keep trying with BlockStyler on an upcoming project and I will post the results whenever I have them ready :).

Finally what I did with UIStyler was to add construct, selection and filter handlers for the Dialog; I put a tripleMask filter inside the construct handler, some actions inside the selection handler to manage a counter of selected/de-selected items and some other actions inside the filter one. =)



Enjoy your holidays!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top