Showing results for 
Search instead for 
Do you mean 
Reply

Block UI Styler: Create new file

Hi,

 

I try to use the "File Selection with Browse"- Block UI Styler element to create a new File. Whenever I enter a filename that doesn't yet exist, I get a error messagebox saying "The file does not exist" and the filename is removed from the edit field. Only existing files may be selected or typed. Is it possible to override this behaviour? I tried to define an update callback on the file selection element but the error message already appeared before the callback has been executed.

 

(NX 9.0.3.4)

 

Thanks

Wolfe

9 REPLIES

Re: Block UI Styler: Create new file

Unfortunately, this block cannot be used to create a new file. It is sorely in need of enhancement to match all of the capability of something like System.Windows.Forms.OpenFileDialog.

 

I would encourage anyone that is interested to file an ER.

 

In the meantime, the only BlockStyler workaround I know of is to use a Folder Selection with Browse box to select the folder and a separate String block to get the filename, then append the two in your code to get the full path.

Re: Block UI Styler: Create new file

You could also include a button and that launches the regular part open dialog of NX.

 

See UFSession.GetUFSession().Ui.AskOpenPartFilename() for example.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Block UI Styler: Create new file

The best workaround I've come up with is to add a button to the dialog and in the call back for that open an NX Filebox using the UF method:

theUfSession.ui().createFilebox(prompt, title, filter, defaultName);

If required, have a label or text field on the dialog to display the pathname of the selected file.

This method does not require that the user select an existing file.

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

Re: Block UI Styler: Create new file

Thanks for your answers,

 

I forgot to mention that I'm using C++. Unfotunately I could not find a way to get access to the UF method createFilebox() within C++.

 

In order to use the createFilebox() method I tried to get an instance of UfSession. Unfortunately I couldn't find out how to acquire this from the NXOpen::UI class that is provided by the Block UI Styler-generated C++-source.

 

 

 

Re: Block UI Styler: Create new file

You need to use NXOpen::UF to get the UFSession object.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Block UI Styler: Create new file

 

When you are using C++, you need to use the original Open C call, not a wrapper.  To do this, be sure that you:

 

#include <uf.h>

#include<uf_ui.h>  (or whatever header has the prototype for the function that you want to call)

 

Also, you must remember to call UF_initialize(), in addition to the usual GetSession().

 

So the functions that have been mentioned above would be:

 

UF_UI_create_filebox

 

and

 

UF_UI_ask_open_part_filename

 

To find examples on the support site that demonstrate using NXOpen C++ with Open C, search for:

 

sample program interop

 

then filter for document type of nx_api.

 

 

 

 

Re: Block UI Styler: Create new file

Finally it's working using the pure C call UF_UI_create_filebox() as SteveLabout suggested.

Thanks for all your help.

 

 

Re: Block UI Styler: Create new file

I used the createFilebox() command from within the update callback when the button is pressed.  The reuulting fileselection dialog deadlocks NX when I press the OK button on the file selection dialog.  What am I doing wrong?

 

 

 

Re: Block UI Styler: Create new file

I can't edit. So I should clarify. This is in Java, not C.

public int update(nxopen.blockstyler.UIBlock block) throws NXException, RemoteException {
try {
if (block == fileBrowseButton) {
String startPath = "";
if(currentFileSelection != null) {
startPath = currentFileSelection.getAbsolutePath();
}
CreateFileboxData fileData = ufs.ui().createFilebox(
"Select Excel Save File", "SaveFile", ".xls", startPath);
if (fileData.response == UFConstants.UF_UI_OK) {
currentFileSelection = new File(fileData.filename);
if (!currentFileSelection.isFile()) {
ui.nxmessageBox().show("Save filename error",
nxopen.NXMessageBox.DialogType.ERROR, "Invalid filename slected: " + fileData.filename);
return 0;
}
}
}

....