Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to check connected curves ?

Status
Not open for further replies.

lexus911

Automotive
Jan 18, 2018
13
Hello!
I have a pretty basic question.

I am trying to write a macro to check connected curves in the model, the old way to check is using the project curve feature and select a connected curve. it takes a lot of time if I have many curves.

can you help me another way to improve it

1_zr140x.png

2_rwmutp.png
 
Replies continue below

Recommended for you

Knowing what version of NX you're using would be quite helpful.

Tim Flater
NX Designer
NX 11.0.2.7 MP11 Rev. A
GM TcE v11.2.3.1
GM GPDL v11-A.3.5.1
Win7 Enterprise x64 SP1
Intel Core i7 2.5GHz 16GB RAM
4GB NVIDIA Quadro K3100M
 
Are you working with edges on a body? If so, the .AskCnncEdges method might be helpful. It appears that it will only work with edges and won't accept curves (lines, arcs, splines, etc) as input.

www.nxjournaling.com
 
I tried, but it not work, can you help me fix my code, Thanks

I tried to write a demo code, change the color of the connected curve

Code:
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);
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor