UG帮助文档NXOPEN C#

更新时间:2023-10-28 21:52:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

C#(UG)

NXOPEN Create and display a dialog

Private dialog As nxopen.uistyler.Dialog

dialog = UI.GetUI().Styler.CreateStylerDialog(\

显示对话框

dialog.Show()

Alternatively, the UI Styler uses the following instead of the show function you open the dialog from the menu:

或者,UI/Styler用以下代码实现从菜单打开的对话框的显示功能。

Dim isTopDialog As Boolean isTopDialog = false

dialog.RegisterWithUIMenu(isTopDialog)

How styler items are declared:

Private changeDialog As NXOpen.UIStyler.DialogItem Private changeStr0 As NXOpen.UIStyler.StringItem Private changeReal6 As NXOpen.UIStyler.RealItem How styler items are initialized: (初始化)

changeDialog = theDialog.GetStylerItem(\NXOpen.UIStyler.Dialog.ItemType.DialogItem)

changeStr0=theDialog.GetStylerItem(\ringItem)

changeReal6=theDialog.GetStylerItem(\.RealItem)

Register dialog box item callback functions

In order to register these callbacks, NX provides an API “Add##Handler”, where ## is replaced with “Activate”, “Construct”, “Apply” as shown in following examples. For more information on callbacks of all the dialog items, see the callback section in Dialog Item Reference.

When you exit a Styler dialog box normally, the destructor callback is executed at last. Selecting Cancel or OK will invoke Cancel or OK callback first, followed by the destructor callback.

Event Handler representation(事件处理程序代表)

In case of .NET (VB/C#) APIs, registration is done through Delegates, and represented as:

namespace NXOpen.UIStyler { }

In your C# application, the registration will look like this:

changeDialog.AddConstructHandler(AddressOf constructor_cb, False) changeDialog.AddOkayHandler(AddressOf ok_cb, False) changeDialog.AddApplyHandler(AddressOf apply_cb, False) changeStr0.AddActivateHandler(AddressOf bend_radius_cb, False) changeReal6.AddActivateHandler(AddressOf tolerance_cb, False)

public class StringItem: UIStyler.StylerItem { }

public delegate int Activate(UIStyler.StylerEvent eventObject); public unsafe void

AddActivateEvent(UIStyler.PushButton.Activate activateevent)();

Get and set dialog item attributes

The NX Open API provides get and set methods for the relevant attributes of each dialog item. You can set and get the visibility for a PushButton using the following code. Once you get the dialog item, you can set the property of the item anywhere in your program. Here “thePushButton0” is an object of PushButton dialog item. C#

/*Getting visibility attribute*/

Boolean isVisible = thePushButton0.Visibility;

/*Setting visibility attribute*/

thePushButton0.Visibility = true;

Launch a dialog from the event callback of another dialog

While registering a callback, you must determine whether this event can launch another dialog box, depending upon the value of the toggle for “Creates Dialog” on the resource editor. The last argument in every callback registering function indicates this. It is done by setting this argument to “TRUE” or “FALSE”. ?

C#

changeAction0 =

(NXOpen.UIStyler.PushButton)theDialog.GetStylerItem(\Dialog.ItemType.PushButton);

changeAction0.AddActivateHandler(new NXOpen.UIStyler.PushButton.Activate (action_0_act_cb), true); changeAction1 =

(NXOpen.UIStyler.PushButton)theDialog.GetStylerItem(\Dialog.ItemType.PushButton);

changeAction1.AddActivateHandler(new NXOpen.UIStyler.PushButton.Activate (action_1_act_cb), false);

Run a VB application as a journal script

1. 2. 3.

Choose Tools→Journal→Play. The Journal Manager dialog box opens. Click Browse to navigate to the location of the VB file. Click Run.

Run a VB application using DLL

1. 2. o o

Open Microsoft Visual Studio .Net. Create a new project:

Choose File→New→Project.

Select Visual Basic Projects, Console Application and type the name with

which you want to save the project (for example, test). o

Click OK.

3. In the Solution Explorer, select the AssemblyInfo.vb file from the project, right-click and choose Delete from the shortcut menu. A dialog appears warning you that the file will be permanently removed. Click OK.

4. In the Solution Explorer, select theModule1.vb file from the project, right-click and choose Delete from the shortcut menu. A dialog appears warning you that the file will be permanently removed. Click OK.

5. o o o o

Add references for the following files:

NXOpen.dll NXOpenUI.dll NXOpen.Utilities.dll NXOpen.UF.dll

In the Solution Explorer, right-click References under the project. Choose Add Reference→Browse→%UGII_ROOT_DIR%\\out\\managed. Press the CTRL key and select the dlls. 6.

In the Solution Explorer, highlight the project name, right-click and choose Add Existing Item. Navigate to the location of the .vb file and add it. 7.

Choose Project Menu→Properties. If you see \t, push down list, select Startup Project as the new Module name displayed in the list. Click OK. 8.

Choose Build Menu→Build Solution, or Ctrl + Shift + B, or go to Solution Explorer, select the project name, right-click and select Build. This creates the required dll. 9. o

To run the VB examples, do the following:

Choose File→Execute→NX Open. The Execute User Function dialog

box opens. o

Navigate to the location of the .dll file. It will be in the \\bin

directory under the directory named for the VB project. o

Select the .dll file and click OK.

Selection

Selection class contains methods that update the selection structure associated with the active dialog box. Some method declarations for class Selection are: namespace NXOpen {

class Selection

void SetSelectionMask (

NXOpen::SelectionHandle * select /** Selection handle */, NXOpen::Selection::SelectionAction action /** Mask action */,

const std::vector & mask_array /** Mask triples */ );

public: void SetSelectionCallbacks (

NXOpen::SelectionHandle * select /** Selection handle */, const NXOpen::Selection::FilterCallback& filterproc /** Filter callback for additional user specific filtering. */,

const NXOpen::Selection::SelectionCallback& selcb /** Selection callback for application specific processing. */ );

C#

?

To get the selection handle

Dim selectH As SelectionHandle = changeDialog.GetSelectionHandle() ? ? ? ? ? ?

Create selection mask array

Dim selectionMask_array(0) As NXOpen.Selection.MaskTriple With selectionMask_array(0)

.Type = NXOpen.UF.UFConstants.UF_solid_type

.Subtype = NXOpen.UF.UFConstants.UF_solid_edge_subtype

.SolidBodySubtype = NXOpen.UF.UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE End With ? ?

Set the selection mask

UI.GetUI().SelectionManager.SetSelectionMask(selectH,

NXOpen.Selection.SelectionAction.ClearAndEnableSpecific, selectionMask_array) ? ?

Set selection procedures

UI.GetUI().SelectionManager.SetSelectionCallbacks(selectH, AddressOf filter_cb, AddressOf sel_cb) ?

Define the filter_cb and sel_cb procedures as follows in order to register this in set selection procedure in the above step. ? ? ? ? ?

Public Function filter_cb(ByVal selectedObject As NXObject, ByVal selectionMask_array As NXOpen.Selection.MaskTriple, ByVal selectHandle As SelectionHandle) As Integer Try

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

// write your code here

Catch ex As NXException

' ---- Enter your exception handling code here ----- MsgBox(ex.Message) End Try End Function

Public Function sel_cb(ByVal selectedObjects As NXObject(), ByVal deselectedObjects() As NXObject, ByVal selectHandle As SelectionHandle) As Integer Try

// write your code here

Catch ex As NXException

' ---- Enter your exception handling code here ----- MsgBox(ex.Message) End Try

sel_cb = NXOpen.UIStyler.DialogState.ContinueDialog End Function

Dialog box layout

Introduction

Attachment class is used to set the attachment of the dialog item, for example left item, right item, top item, and so on and also the relative positioning of the item (for example, center, left, right, bottom, top). The following sections explain the corresponding NX Open APIs that manipulate the dialog item’s attachment (layout) structure.

Set an attachment to dialog Item

Following set of APIs are used to set the attachment for a particular dialog box item

C#

Attachment attach = changeAction0.InitializeAttachment(); attach.SetCenter(false);

attach.SetAttachTypeTop(Attachment.AttachType.Dialog); attach.SetTopDialogItem(\attach.SetTopOffset(0);

attach.SetAttachTypeRight(Attachment.AttachType.Dialog); attach.SetRightDialogItem(\attach.SetRightOffset(50);

attach.SetAttachTypeLeft(Attachment.AttachType.Dialog); attach.SetLeftDialogItem(\attach.SetLeftOffset(50);

changeAction0.SetAttachment(attach);

本文来源:https://www.bwwdw.com/article/2h42.html

Top