179 lines
5.6 KiB
C#
179 lines
5.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using NXOpen;
|
|
using NXOpen.UF;
|
|
|
|
public class Program
|
|
{
|
|
// class members
|
|
private static Session s;
|
|
private static UI ui;
|
|
private static UFSession ufs;
|
|
public static Program theProgram;
|
|
public static bool isDisposeCalled;
|
|
|
|
#region UG...
|
|
//------------------------------------------------------------------------------
|
|
// Constructor
|
|
//------------------------------------------------------------------------------
|
|
public Program()
|
|
{
|
|
try
|
|
{
|
|
s = Session.GetSession();
|
|
ui = UI.GetUI();
|
|
ufs = UFSession.GetUFSession();
|
|
isDisposeCalled = false;
|
|
}
|
|
catch (NXOpen.NXException)
|
|
{
|
|
// ---- Enter your exception handling code here -----
|
|
// UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Explicit Activation
|
|
// This entry point is used to activate the application explicitly
|
|
//------------------------------------------------------------------------------
|
|
[DebuggerStepThrough] public static int Main(string[] args)
|
|
{
|
|
int retValue = 0;
|
|
try
|
|
{
|
|
theProgram = new Program();
|
|
|
|
//TODO: Add your application code here
|
|
theProgram.DoIt(args);
|
|
|
|
|
|
theProgram.Dispose();
|
|
}
|
|
catch (NXOpen.NXException )
|
|
{
|
|
// ---- Enter your exception handling code here -----
|
|
|
|
}
|
|
return retValue;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Following method disposes all the class members
|
|
//------------------------------------------------------------------------------
|
|
[DebuggerStepThrough] public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
if (isDisposeCalled == false)
|
|
{
|
|
//TODO: Add your application code here
|
|
}
|
|
isDisposeCalled = true;
|
|
}
|
|
catch (NXOpen.NXException )
|
|
{
|
|
// ---- Enter your exception handling code here -----
|
|
|
|
}
|
|
}
|
|
|
|
[DebuggerStepThrough] public static int GetUnloadOption(string arg)
|
|
{
|
|
//Unloads the image explicitly, via an unload dialog
|
|
//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
|
|
|
|
//Unloads the image immediately after execution within NX
|
|
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
|
|
|
|
//Unloads the image when the NX session terminates
|
|
// return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
|
|
}
|
|
|
|
[DebuggerStepThrough] public void StartDebugger()
|
|
{
|
|
if (!System.Diagnostics.Debugger.IsAttached)
|
|
System.Diagnostics.Debugger.Launch();
|
|
}
|
|
#endregion
|
|
|
|
|
|
ListingWindow lw;
|
|
|
|
private void lwWriteLine(string line)
|
|
{
|
|
lw.WriteLine(line); lw.Close(); lw.Open();
|
|
}
|
|
|
|
public void DoIt(string[] args)
|
|
{
|
|
ufs.Ui.SetStatus($"Starting SimpleTests");
|
|
StartDebugger();
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
Session theSession = Session.GetSession();
|
|
Part dispPart = theSession.Parts.Display;
|
|
Part workPart = theSession.Parts.Work;
|
|
UFSession theUFSession = UFSession.GetUFSession();
|
|
lw = theSession.ListingWindow;
|
|
lw.Open(); lw.Close(); lw.Open();
|
|
int iColPartName = -1;
|
|
bool is_family_template;
|
|
theUFSession.Part.IsFamilyTemplate(dispPart.Tag, out is_family_template);
|
|
lwWriteLine(("Part Family Template: " + is_family_template.ToString()));
|
|
if ((is_family_template == false))
|
|
{
|
|
return;
|
|
}
|
|
|
|
int family_count;
|
|
Tag[] families;
|
|
theUFSession.Part.AskFamilies(dispPart.Tag, out family_count, out families);
|
|
lwWriteLine(("Part Families: " + family_count.ToString()));
|
|
for (int ii = 0; (ii <= (family_count - 1)); ii++)
|
|
{
|
|
UFFam.FamilyData family_data;
|
|
theUFSession.Fam.AskFamilyData(families[ii], out family_data);
|
|
int member_count = family_data.member_count;
|
|
lwWriteLine(("Part Family Name: " + family_data.name));
|
|
|
|
Hashtable tab = new Hashtable();
|
|
|
|
if ((iColPartName == -1))
|
|
{
|
|
for (int jj = 0; (jj
|
|
<= (family_data.attribute_count - 1)); jj++)
|
|
{
|
|
UFFam.AttributeData attribute_data;
|
|
theUFSession.Fam.AskAttributeData(family_data.attributes[jj], out attribute_data);
|
|
lwWriteLine($"Attribute {jj} : {attribute_data.name} = {attribute_data.value}");
|
|
|
|
tab.Add(jj, attribute_data.name);
|
|
}
|
|
}
|
|
|
|
lwWriteLine("----");
|
|
|
|
for (int kk = 0; (kk <= (member_count - 1)); kk++)
|
|
{
|
|
UFFam.MemberData member_row_data;
|
|
theUFSession.Fam.AskMemberRowData(families[ii], kk, out member_row_data);
|
|
|
|
for (int v=0; v<member_row_data.value_count; v++)
|
|
{
|
|
lwWriteLine($"{tab[v]}: {member_row_data.values[v]}"); //lwWriteLine(String.Format("{0}: {1}", tab[v], member_row_data.values[v]));
|
|
}
|
|
lwWriteLine("----");
|
|
}
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
ufs.Ui.SetStatus($"Finishing SimpleTests");
|
|
}
|
|
} |