I need to select .csv file from BlockStyler dialog. I try to use NXOpen.BlockStyler.FileSelection
1) Create and save file, as in tkinter I can open file explorer, create the name of file and it will return full path to a new file. Then I can work with it in my code as I need. I don't know how to do it in BlockStyler.
I tried to use Tkinter fileopen, but the error was rised: "Can't find a usable init.tcl in the following directories... This probably means that Tcl wasn't installed properly."
2) Open file. Actually the same problems. And I don't understand how to set a "Filter" property for FileSelection.
Please, help me.
The block just returns what the user has selected like the regular FileOpen dialog available through regular .NET
The options of the file selection block are similar to the one of a FileOpen dialog.
Have you checked the block styler API reference in the NX documentation?
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk Testing: NX12.0 Preparing: NX12.0
Employees of the customers, together we are strong
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide
NX BlockStyler and tkinter are two completely separate classes.
The BlockStyler file browser can only select existing files. It cannot be used to create a new filename.
To reference TK libraries from a Python journal, the TCL_LIBRARY environment variable must be set to the appropriate TCL installation. Note that this is not part of the NX Python distribution.
I have met a similar error while using matplotlib package. I am using NX 12, and I have set my ugii_env.dat according to the documentation in the following way:
PYTHONPATH=C:\Python36;C:\Python36\Lib;C:\Python36\libs;C:\Python36\DLLs;C:\Python36\Lib\site-packages;"C:\Program Files\Siemens\NX120\NXBIN\python" UGII_PYTHON_HOME=C:\Python36 UGII_PYTHON_DLL=python36.dll UGII_PYTHON_LIBRARY_DIR=C:\Python36 UGII_PYTHONPATH=C:\Python36;C:\Python36\Lib;C:\Python36\libs;C:\Python36\DLLs;C:\Python36\Lib\site-packages;"C:\Program Files\Siemens\NX120\NXBIN\python" TCL_LIBRARY=C:\Python36\tcl\tcl8.6
This setting works for python libraries such as numpy, scipy, sympy, and of course NXOpen. But it does not work for matplotlib. The following code is a simple test script for matplotlib:
#nx: threaded import matplotlib.path as mpath import matplotlib.patches as mpatches import matplotlib.pyplot as plt import NXOpen Path = mpath.Path fig, ax = plt.subplots() pp1 = mpatches.PathPatch( Path([(0, 0), (1, 0), (1, 1), (0, 0)], [Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]), fc="none", transform=ax.transData) ax.add_patch(pp1) ax.plot([0.75], [0.25], "ro") ax.set_title('The red point should be on the path') plt.show()
When I run it in NX, NX gives an info saying "_tkinter.TclError: Can't find a usable init.tcl in the following directories: C:/Python36/lib/tcl8.6 ...". It seems that the TCL_LIBRARY environment variable set in ugii_env.dat does not give the correct Tcl directory to NX, and I can't figure out which part is wrong.
However, I try to solve this problem temporarily by manually copy the relevant files to the specific directories NX will search. And it works！
From my test, NX will find tcl or tk files in these two directories of my computer:
while the original directories should be:
The above works fine for me. I have unmodified installations of NX 12 and Python 3.6. I only set the following 3 variables:
UGII_PYTHON_LIBRARY_DIR=C:\apps\Python36 UGII_PYTHONPATH=C:\apps\Python36;C:\apps\Python36\DLLs;C:\apps\Python36\Lib;C:\apps\Python36\Lib\site-packages;C:\apps\Siemens\NX\12.0\nxbin\python TCL_LIBRARY=C:\apps\Python36\tcl\tcl8.6