Bear with me, I'm quite new at NX customization. In NX 11, I've created a Block UI and added a button to it (all python output). When I go to edit the callback and define what happens when I push the button, I want to reference a seperate .py file inwhich I programmatically build geometry. Is there a way to call/reference the external file within the UI application script? Any help would be appreciated. See below for a snippet of what I would like to do. Thanks!
def update_cb(self, block):
if block == self.button0:
# ---- Enter your code here ---
# I would like to have seperate code referenced here when I push the button....(customScript.py)
elif block == self.button01:
Solved! Go to Solution.
This can be done in following, key is to add file path of second script to sys.path before you import it.
#File1.py import NXOpen import os import sys sys.path.append(os.path.dirname(__file__)) import File2 def main(): NXOpen.UI.GetUI().NXMessageBox.Show("Test Code", NXOpen.NXMessageBox.DialogType.Information, "Called main from File1") try: File2.SomeFunction() except Exception as ex: NXOpen.UI.GetUI().NXMessageBox.Show("Test Code", NXOpen.NXMessageBox.DialogType.Information, "Exception in main") if __name__ == '__main__': main()
#File2.py import NXOpen def SomeFunction(): NXOpen.UI.GetUI().NXMessageBox.Show("Test Code", NXOpen.NXMessageBox.DialogType.Information, "Called SomeFunction from File2") return