Soyasauce
Aerospace
- Apr 18, 2017
- 4
Hi all,
I would like to request help from the kind souls here in this forum. I am quite new to programming NX open.
I have created a journal code that when played, will create a simple solid block by the co-ordinates 100 by 100 by 100. What i wish to accomplish is to use the block UI styler to allow the user to choose the co-ordinates of the block before creation.
Thus, i have created a simple dialog with the block UI styler requesting for 3 integers of values X Y and Z. I generated the code and now i do not know how to combine the two together.. How do i retrieve the values input by the user from the dialog box into my journal code?
My journal code is shown as below ( C# ) :
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
NXOpen.Point3d originPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
blockFeatureBuilder1.SetOriginAndLengths(originPoint1, "100", "100", "100");
NXOpen.Features.Feature feature1;
feature1 = blockFeatureBuilder1.CommitFeature();
My Dialog box code :
//==============================================================================
// WARNING!! This file is overwritten by the Block UI Styler while generating
// the automation code. Any modifications to this file will be lost after
// generating the code again.
//
// Filename: C:\Users\MTS PG 6\Desktop\blockdialog.cs
//
// This file was generated by the NX Block UI Styler
// Created by: MTS PG 6
// Version: NX 10
// Date: 04-19-2017 (Format: mm-dd-yyyy)
// Time: 07:54 (Format: hh-mm)
//
//==============================================================================
//==============================================================================
// Purpose: This TEMPLATE file contains C# source to guide you in the
// construction of your Block application dialog. The generation of your
// dialog file (.dlx extension) is the first step towards dialog construction
// within NX. You must now create a NX Open application that
// utilizes this file (.dlx).
//
// The information in this file provides you with the following:
//
// 1. Help on how to load and display your Block UI Styler dialog in NX
// using APIs provided in NXOpen.BlockStyler namespace
// 2. The empty callback methods (stubs) associated with your dialog items
// have also been placed in this file. These empty methods have been
// created simply to start you along with your coding requirements.
// The method name, argument list and possible return values have already
// been provided for you.
//==============================================================================
//------------------------------------------------------------------------------
//These imports are needed for the following template code
//------------------------------------------------------------------------------
using System;
using NXOpen;
using NXOpen.BlockStyler;
//------------------------------------------------------------------------------
//Represents Block Styler application class
//------------------------------------------------------------------------------
public class blockdialog
{
//class members
private static Session theSession = null;
private static UI theUI = null;
private string theDlxFileName;
private NXOpen.BlockStyler.BlockDialog theDialog;
private NXOpen.BlockStyler.Group group0;// Block type: Group
private NXOpen.BlockStyler.IntegerBlock integer0;// Block type: Integer
private NXOpen.BlockStyler.IntegerBlock integer02;// Block type: Integer
private NXOpen.BlockStyler.IntegerBlock integer01;// Block type: Integer
//------------------------------------------------------------------------------
//Constructor for NX Styler class
//------------------------------------------------------------------------------
public blockdialog()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theDlxFileName = "blockdialog.dlx";
theDialog = theUI.CreateDialog(theDlxFileName);
theDialog.AddApplyHandler(new NXOpen.BlockStyler.BlockDialog.Apply(apply_cb));
theDialog.AddOkHandler(new NXOpen.BlockStyler.BlockDialog.Ok(ok_cb));
theDialog.AddUpdateHandler(new NXOpen.BlockStyler.BlockDialog.Update(update_cb));
theDialog.AddInitializeHandler(new NXOpen.BlockStyler.BlockDialog.Initialize(initialize_cb));
theDialog.AddDialogShownHandler(new NXOpen.BlockStyler.BlockDialog.DialogShown(dialogShown_cb));
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
throw ex;
}
}
//------------------------------- DIALOG LAUNCHING ---------------------------------
//
// Before invoking this application one needs to open any part/empty part in NX
// because of the behavior of the blocks.
//
// Make sure the dlx file is in one of the following locations:
// 1.) From where NX session is launched
// 2.) $UGII_USER_DIR/application
// 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
// recommended. This variable is set to a full directory path to a file
// containing a list of root directories for all custom applications.
// e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat
//
// You can create the dialog using one of the following way:
//
// 1. Journal Replay
//
// 1) Replay this file through Tool->Journal->Play Menu.
//
// 2. USER EXIT
//
// 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
// 2) Invoke the Shared Library through File->Execute->NX Open menu.
//
//------------------------------------------------------------------------------
public static void Main()
{
blockdialog theblockdialog = null;
try
{
theblockdialog = new blockdialog();
// The following method shows the dialog immediately
theblockdialog.Show();
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
finally
{
if(theblockdialog != null)
theblockdialog.Dispose();
theblockdialog = null;
}
}
//------------------------------------------------------------------------------
// This method specifies how a shared image is unloaded from memory
// within NX. This method gives you the capability to unload an
// internal NX Open application or user exit from NX. Specify any
// one of the three constants as a return value to determine the type
// of unload to perform:
//
//
// Immediately : unload the library as soon as the automation program has completed
// Explicitly : unload the library from the "Unload Shared Image" dialog
// AtTermination : unload the library when the NX session terminates
//
//
// NOTE: A program which associates NX Open applications with the menubar
// MUST NOT use this option since it will UNLOAD your NX Open application image
// from the menubar.
//------------------------------------------------------------------------------
public static int GetUnloadOption(string arg)
{
//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
// return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
}
//------------------------------------------------------------------------------
// Following method cleanup any housekeeping chores that may be needed.
// This method is automatically called by NX.
//------------------------------------------------------------------------------
public static void UnloadLibrary(string arg)
{
try
{
//---- Enter your code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
//------------------------------------------------------------------------------
//This method shows the dialog on the screen
//------------------------------------------------------------------------------
public NXOpen.UIStyler.DialogResponse Show()
{
try
{
theDialog.Show();
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return 0;
}
//------------------------------------------------------------------------------
//Method Name: Dispose
//------------------------------------------------------------------------------
public void Dispose()
{
if(theDialog != null)
{
theDialog.Dispose();
theDialog = null;
}
}
//------------------------------------------------------------------------------
//---------------------Block UI Styler Callback Functions--------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Callback Name: initialize_cb
//------------------------------------------------------------------------------
public void initialize_cb()
{
try
{
group0 = (NXOpen.BlockStyler.Group)theDialog.TopBlock.FindBlock("group0");
integer0 = (NXOpen.BlockStyler.IntegerBlock)theDialog.TopBlock.FindBlock("integer0");
integer02 = (NXOpen.BlockStyler.IntegerBlock)theDialog.TopBlock.FindBlock("integer02");
integer01 = (NXOpen.BlockStyler.IntegerBlock)theDialog.TopBlock.FindBlock("integer01");
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
//------------------------------------------------------------------------------
//Callback Name: dialogShown_cb
//This callback is executed just before the dialog launch. Thus any value set
//here will take precedence and dialog will be launched showing that value.
//------------------------------------------------------------------------------
public void dialogShown_cb()
{
try
{
//---- Enter your callback code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
//------------------------------------------------------------------------------
//Callback Name: apply_cb
//------------------------------------------------------------------------------
public int apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: update_cb
//------------------------------------------------------------------------------
public int update_cb( NXOpen.BlockStyler.UIBlock block)
{
try
{
if(block == integer0)
{
//---------Enter your code here-----------
}
else if(block == integer02)
{
//---------Enter your code here-----------
}
else if(block == integer01)
{
//---------Enter your code here-----------
}
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return 0;
}
//------------------------------------------------------------------------------
//Callback Name: ok_cb
//------------------------------------------------------------------------------
public int ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();
//---- Enter your callback code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Function Name: GetBlockProperties
//Returns the propertylist of the specified BlockID
//------------------------------------------------------------------------------
public PropertyList GetBlockProperties(string blockID)
{
PropertyList plist =null;
try
{
plist = theDialog.GetBlockProperties(blockID);
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return plist;
}
}
Thank you in advance ! Your help is very much appreciated !
I would like to request help from the kind souls here in this forum. I am quite new to programming NX open.
I have created a journal code that when played, will create a simple solid block by the co-ordinates 100 by 100 by 100. What i wish to accomplish is to use the block UI styler to allow the user to choose the co-ordinates of the block before creation.
Thus, i have created a simple dialog with the block UI styler requesting for 3 integers of values X Y and Z. I generated the code and now i do not know how to combine the two together.. How do i retrieve the values input by the user from the dialog box into my journal code?
My journal code is shown as below ( C# ) :
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
NXOpen.Point3d originPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
blockFeatureBuilder1.SetOriginAndLengths(originPoint1, "100", "100", "100");
NXOpen.Features.Feature feature1;
feature1 = blockFeatureBuilder1.CommitFeature();
My Dialog box code :
//==============================================================================
// WARNING!! This file is overwritten by the Block UI Styler while generating
// the automation code. Any modifications to this file will be lost after
// generating the code again.
//
// Filename: C:\Users\MTS PG 6\Desktop\blockdialog.cs
//
// This file was generated by the NX Block UI Styler
// Created by: MTS PG 6
// Version: NX 10
// Date: 04-19-2017 (Format: mm-dd-yyyy)
// Time: 07:54 (Format: hh-mm)
//
//==============================================================================
//==============================================================================
// Purpose: This TEMPLATE file contains C# source to guide you in the
// construction of your Block application dialog. The generation of your
// dialog file (.dlx extension) is the first step towards dialog construction
// within NX. You must now create a NX Open application that
// utilizes this file (.dlx).
//
// The information in this file provides you with the following:
//
// 1. Help on how to load and display your Block UI Styler dialog in NX
// using APIs provided in NXOpen.BlockStyler namespace
// 2. The empty callback methods (stubs) associated with your dialog items
// have also been placed in this file. These empty methods have been
// created simply to start you along with your coding requirements.
// The method name, argument list and possible return values have already
// been provided for you.
//==============================================================================
//------------------------------------------------------------------------------
//These imports are needed for the following template code
//------------------------------------------------------------------------------
using System;
using NXOpen;
using NXOpen.BlockStyler;
//------------------------------------------------------------------------------
//Represents Block Styler application class
//------------------------------------------------------------------------------
public class blockdialog
{
//class members
private static Session theSession = null;
private static UI theUI = null;
private string theDlxFileName;
private NXOpen.BlockStyler.BlockDialog theDialog;
private NXOpen.BlockStyler.Group group0;// Block type: Group
private NXOpen.BlockStyler.IntegerBlock integer0;// Block type: Integer
private NXOpen.BlockStyler.IntegerBlock integer02;// Block type: Integer
private NXOpen.BlockStyler.IntegerBlock integer01;// Block type: Integer
//------------------------------------------------------------------------------
//Constructor for NX Styler class
//------------------------------------------------------------------------------
public blockdialog()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theDlxFileName = "blockdialog.dlx";
theDialog = theUI.CreateDialog(theDlxFileName);
theDialog.AddApplyHandler(new NXOpen.BlockStyler.BlockDialog.Apply(apply_cb));
theDialog.AddOkHandler(new NXOpen.BlockStyler.BlockDialog.Ok(ok_cb));
theDialog.AddUpdateHandler(new NXOpen.BlockStyler.BlockDialog.Update(update_cb));
theDialog.AddInitializeHandler(new NXOpen.BlockStyler.BlockDialog.Initialize(initialize_cb));
theDialog.AddDialogShownHandler(new NXOpen.BlockStyler.BlockDialog.DialogShown(dialogShown_cb));
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
throw ex;
}
}
//------------------------------- DIALOG LAUNCHING ---------------------------------
//
// Before invoking this application one needs to open any part/empty part in NX
// because of the behavior of the blocks.
//
// Make sure the dlx file is in one of the following locations:
// 1.) From where NX session is launched
// 2.) $UGII_USER_DIR/application
// 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
// recommended. This variable is set to a full directory path to a file
// containing a list of root directories for all custom applications.
// e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat
//
// You can create the dialog using one of the following way:
//
// 1. Journal Replay
//
// 1) Replay this file through Tool->Journal->Play Menu.
//
// 2. USER EXIT
//
// 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
// 2) Invoke the Shared Library through File->Execute->NX Open menu.
//
//------------------------------------------------------------------------------
public static void Main()
{
blockdialog theblockdialog = null;
try
{
theblockdialog = new blockdialog();
// The following method shows the dialog immediately
theblockdialog.Show();
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
finally
{
if(theblockdialog != null)
theblockdialog.Dispose();
theblockdialog = null;
}
}
//------------------------------------------------------------------------------
// This method specifies how a shared image is unloaded from memory
// within NX. This method gives you the capability to unload an
// internal NX Open application or user exit from NX. Specify any
// one of the three constants as a return value to determine the type
// of unload to perform:
//
//
// Immediately : unload the library as soon as the automation program has completed
// Explicitly : unload the library from the "Unload Shared Image" dialog
// AtTermination : unload the library when the NX session terminates
//
//
// NOTE: A program which associates NX Open applications with the menubar
// MUST NOT use this option since it will UNLOAD your NX Open application image
// from the menubar.
//------------------------------------------------------------------------------
public static int GetUnloadOption(string arg)
{
//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
// return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
}
//------------------------------------------------------------------------------
// Following method cleanup any housekeeping chores that may be needed.
// This method is automatically called by NX.
//------------------------------------------------------------------------------
public static void UnloadLibrary(string arg)
{
try
{
//---- Enter your code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
//------------------------------------------------------------------------------
//This method shows the dialog on the screen
//------------------------------------------------------------------------------
public NXOpen.UIStyler.DialogResponse Show()
{
try
{
theDialog.Show();
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return 0;
}
//------------------------------------------------------------------------------
//Method Name: Dispose
//------------------------------------------------------------------------------
public void Dispose()
{
if(theDialog != null)
{
theDialog.Dispose();
theDialog = null;
}
}
//------------------------------------------------------------------------------
//---------------------Block UI Styler Callback Functions--------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Callback Name: initialize_cb
//------------------------------------------------------------------------------
public void initialize_cb()
{
try
{
group0 = (NXOpen.BlockStyler.Group)theDialog.TopBlock.FindBlock("group0");
integer0 = (NXOpen.BlockStyler.IntegerBlock)theDialog.TopBlock.FindBlock("integer0");
integer02 = (NXOpen.BlockStyler.IntegerBlock)theDialog.TopBlock.FindBlock("integer02");
integer01 = (NXOpen.BlockStyler.IntegerBlock)theDialog.TopBlock.FindBlock("integer01");
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
//------------------------------------------------------------------------------
//Callback Name: dialogShown_cb
//This callback is executed just before the dialog launch. Thus any value set
//here will take precedence and dialog will be launched showing that value.
//------------------------------------------------------------------------------
public void dialogShown_cb()
{
try
{
//---- Enter your callback code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
//------------------------------------------------------------------------------
//Callback Name: apply_cb
//------------------------------------------------------------------------------
public int apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: update_cb
//------------------------------------------------------------------------------
public int update_cb( NXOpen.BlockStyler.UIBlock block)
{
try
{
if(block == integer0)
{
//---------Enter your code here-----------
}
else if(block == integer02)
{
//---------Enter your code here-----------
}
else if(block == integer01)
{
//---------Enter your code here-----------
}
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return 0;
}
//------------------------------------------------------------------------------
//Callback Name: ok_cb
//------------------------------------------------------------------------------
public int ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();
//---- Enter your callback code here -----
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Function Name: GetBlockProperties
//Returns the propertylist of the specified BlockID
//------------------------------------------------------------------------------
public PropertyList GetBlockProperties(string blockID)
{
PropertyList plist =null;
try
{
plist = theDialog.GetBlockProperties(blockID);
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return plist;
}
}
Thank you in advance ! Your help is very much appreciated !