NX Second Development - based development with C # Winform interface dialog interaction NXOPEN

1. Create a new library

Come in compiled code, success

 Add NXOPEN library to your project

 

 

 Different versions of NX, dll location may be different, NX11 later in NXBIN here, NX11 following versions probably UGII.

 Add header

using NXOpen;
using NXOpen.Utilities;
using NXOpen.UF;

 2. Add winform form

 

 

 3. Add the main entry mode function and unloading

 1 public static int Main()
 2 {
 3     Form1 aa = new Form1();
 4     aa.Show();//1.使用.show()为非模态对话框2.使用.ShowDialog()为模态对话框
 5 
 6     return 0;
 7 }
 8 
 9 public static int GetUnloadOption(string dummy)
10 {
11     return UFConstants.UF_UNLOAD_UG_TERMINATE;//卸载方式显示卸载
12 }
13 
14 Caesar卢尚宇
15 2020年3月1日

4.去winform对话框设计控件

在工具箱中拖过去botton控件

 设置控件属性

 更改控件显示的名字

更改控件ID

 

添加回调函数,按回车创建。

 

 

 依次在添加如下几个控件,就不详细截图了。不会弄,去看C# winform使用相关知识

添加头文件

 添加Session代码

5.去回调函数里添加代码Form1.cs

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 using NXOpen;
12 using NXOpen.Utilities;
13 using NXOpen.UF;
14 
15 namespace test
16 {
17     public partial class Form1 : Form
18     {
19         public Form1()
20         {
21             InitializeComponent();
22         }
23 
24         public static Session theSession = Session.GetSession();
25         public static UFSession theUfSession = UFSession.GetUFSession();
26         public static UFUi theUFUi = theUfSession.Ui;
27 
28         double[] base_pt;
29         private void setOrigin(object sender, EventArgs e)
30         {
31             theUfSession.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM);//对话框加锁
32 
33             //使用点构造器创建点  
34             string cue = "请选择一点";
35             UFUi.PointBaseMethod basemethod = UFUi.PointBaseMethod.PointCursorPos;
36             Tag tPt;
37             base_pt = new double[3];
38             int resp;
39             theUFUi.PointConstruct(cue, ref basemethod, out tPt, base_pt, out resp);
40 
41             theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM);//对话框解锁
42         }
43 
44         private void createBlock(object sender, EventArgs e)
45         {
46             FeatureSigns sign = FeatureSigns.Nullsign;//定义布尔
47             string[] edge_len = { textL.Text, textW.Text, textH.Text };//定义长宽高
48             Tag blk_obj_id = new Tag();
49             theUfSession.Modl.CreateBlock1(sign, base_pt, edge_len, out blk_obj_id);//创建块
50 
51             this.Close();//关闭对话框
52         }
53     }
54 }
55 Caesar卢尚宇
56 2020年3月1日

 Caesar卢尚宇

2020年3月1日

 

Guess you like

Origin www.cnblogs.com/nxopen2018/p/12387596.html