using System;
using NXOpen;
using NXOpen.UF;
public class NXJournal
{
static Session theSession = Session.GetSession();
static UFSession theUFSession = UFSession.GetUFSession();
static Part workPart = theSession.Parts.Work;
public static void Main(string[] args)
{
Curve[] theCurves = SelectCurves("Select connected curves");
if (theCurves.Length == 0) return;
System.Collections.Generic.List<Curve>[] sortedCurves = sort_by_connectivity(theCurves);
DisplayModification displayModification1;
displayModification1 = theSession.DisplayManager.NewDisplayModification();
displayModification1.ApplyToAllFaces = false;
displayModification1.ApplyToOwningParts = false;
displayModification1.NewColor = 11;
displayModification1.Apply(sortedCurves);
displayModification1.Dispose();
// ----------------------------
}
static System.Collections.Generic.List<Curve>[] sort_by_connectivity(Curve[] theCurves)
{
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "");
System.Collections.Generic.List<Tag> theCurveTags =
new System.Collections.Generic.List<Tag>();
foreach (Curve aCurve in theCurves) theCurveTags.Add(aCurve.Tag);
int n_joined;
Tag[] joined = new Tag[theCurveTags.Count];
theUFSession.Curve.AutoJoinCurves(theCurveTags.ToArray(), theCurveTags.Count,
2, joined, out n_joined);
System.Collections.Generic.List<Curve>[] CurveLists =
new System.Collections.Generic.List<Curve>[n_joined];
for (int ii = 0; ii < n_joined; ii++)
CurveLists[ii] = new System.Collections.Generic.List<Curve>();
foreach (Curve aCurve in theCurves)
{
double min_dist;
double[] junk = new double[3];
double accuracy;
int which = 0;
theUFSession.Modl.AskMinimumDist3(2, joined[0], aCurve.Tag, 0, junk, 0, junk,
out min_dist, junk, junk, out accuracy);
for (int ii = 1; ii < n_joined; ii++)
{
double this_dist;
theUFSession.Modl.AskMinimumDist3(2, joined[ii], aCurve.Tag, 0, junk, 0, junk,
out this_dist, junk, junk, out accuracy);
if (this_dist < min_dist)
{
min_dist = this_dist;
which = ii;
}
}
CurveLists[which].Add(aCurve);
}
theSession.UndoToMark(markId1, "");
theSession.DeleteUndoMark(markId1, "");
return CurveLists;
}
static Curve[] SelectCurves(string prompt)
{
TaggedObject[] selobjs = null;
Selection.Response resp =
UI.GetUI().SelectionManager.SelectTaggedObjects(prompt, "Select Curves",
Selection.SelectionScope.WorkPart, false,
new Selection.SelectionType[] { Selection.SelectionType.Curves },
out selobjs);
System.Collections.Generic.List<Curve> theCurves =
new System.Collections.Generic.List<Curve>();
foreach (TaggedObject aTO in selobjs)
{
if (aTO is Curve) theCurves.Add((Curve)aTO);
}
return theCurves.ToArray();
}
public static int GetUnloadOption(string arg)
{
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
}
}