Please help me :((
When using winform, after executing the function. NX always displays the message board: Work in process, Click stop to interput this operator.
How does NX finish after function execution?
Code: Event click to table, select face change color.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NXOpen;
using NXOpenUI;
namespace ColorTable
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static int GetUnloadOption(string dummy)
{ return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List mySelectedObjects = new List();
public static Selection.Response SelectmultiObkjects(string prompt, ref List dispObj )
{
TaggedObject[] selObj;
UI theUI = UI.GetUI();
string title = "Select face";
Selection.SelectionAction selAction = Selection.SelectionAction.ClearAndEnableSpecific;
Selection.SelectionScope scope = Selection.SelectionScope.AnyInAssembly;
Selection.MaskTriple[] selectionMask_array = new Selection.MaskTriple[1];
selectionMask_array[0].Type = NXOpen.UF.UFConstants.UF_face_type;
selectionMask_array[0].SolidBodySubtype = NXOpen.UF.UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY;
Selection.Response resp = theUI.SelectionManager.SelectTaggedObjects(prompt, title, scope, selAction, false, false, selectionMask_array, out selObj);
if(resp == Selection.Response.ObjectSelected || resp == Selection.Response.ObjectSelectedByName || resp == Selection.Response.Ok)
{
foreach(NXObject item in selObj)
{
dispObj.Add((NXOpen.DisplayableObject)item);
}
return Selection.Response.Ok;
}
else
{
return Selection.Response.Cancel;
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;
UI theUI = UI.GetUI();
if(SelectmultiObkjects("Color Table (Code by Mold CADCAM P)", ref mySelectedObjects) == Selection.Response.Ok)
{
NXOpen.DisplayModification displayModification1;
displayModification1 = theSession.DisplayManager.NewDisplayModification();
displayModification1.ApplyToAllFaces = true;
displayModification1.ApplyToOwningParts = true;
displayModification1.NewColor = 186;
displayModification1.Apply(mySelectedObjects.ToArray());
displayModification1.Dispose();
}
}
}
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "91"),
new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "", System.Drawing.SystemColors.WindowText, System.Drawing.Color.Blue, new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))))}, -1);
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.FullRowSelect = true;
this.listView1.GridLines = true;
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1});
this.listView1.Location = new System.Drawing.Point(-1, 2);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(599, 507);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
//
// columnHeader1
//
this.columnHeader1.Text = "Code";
//
// columnHeader2
//
this.columnHeader2.Text = "Color";
this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader2.Width = 80;
//
// columnHeader3
//
this.columnHeader3.Text = "Tolerance";
this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader3.Width = 151;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(739, 501);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
}
}
re: C# winform
I created a new NX file with only a block feature in it and ran your code. A form appears with a single entry in the table; when I click on the entry, it prompts me to select a face. I select one or more faces and it changes the color and the "work in progress" dialog appears. The winform has been minimized to the windows task bar; if I click on the icon for the form, it re-appears. I can close the form and NX will continue normally.
I'm not sure what your desired workflow is, but if you want NX to continue normally after the face selection, just add code that closes the form.