Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

intersection of splines/section curves

After the Section Analysis tool generates a set of section curves/splines for a faceted model, is there a way to find the intersection pt of the resulting section curves/splines?  

 

I tried to use NXOpen.UF.Modeling.IntersectCurveToCurve(spline1, spline2) but it can only call NXOpen.UF.Modeling objects. I am also trying to adapt some of Steve Labout's code from a similar post.

 

 

 

        #finding intersection pts of 2 splines
        for j in range(len(spline_list)):
            
            spline1 = workPart.Splines.FindObject(str(spline_list[j]))

            for k in range(len(spline_list)):
            
                spline2 = workPart.Splines.FindObject(str(spline_list[k]))

                NXOpen.UF.Modeling.IntersectCurveToCurve(spline1, spline2)

 

 

 

Here are some other posts that have covered this topic

https://community.plm.automation.siemens.com/t5/NX-Programming-Customization/NX-Snap-Intersection-of...

 

https://community.plm.automation.siemens.com/t5/NX-Programming-Customization/Finding-intersection-po...

 

https://community.plm.automation.siemens.com/t5/NX-Programming-Customization/Exact-Intersection-poin...

9 REPLIES

Re: intersection of splines/section curves

I think you need to pass the tag of the spline objects to the UF function.

Re: intersection of splines/section curves

[ Edited ]

Thanks for the reply. When I run the code below with Tags, I get the following error. I think the issue is that the "Section Analysis" generates a Spline class not a Curve class.

 

        for j in range(len(line_list)):
            
            line1 = line_list[j]

            for k in range(len(line_list)):
            
                line2 = line_list[k]

                NXOpen.UF.Curve.Intersect(line1.Tag, line2.Tag)

intersect_error.jpg

 

 

Re: intersection of splines/section curves

The "spline" object class inherits from the "curve" class, so the fact that you have a spline should not be an issue. If you are using the .Intersect method, it appears that you are missing the "refPoint" argument?

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

Re: intersection of splines/section curves

[ Edited ]

thanks for the reply, after reading up on the subject more I think finding the intersection pt of 2 splines is pretty challenging and I'm not sure if the available NX Open methods can pull it off.

 

i included the refpoints argument but I still get an error message that says a "NXOpen.UF.Curve" object is required. Below is my code. Is there a way to get the parametric equation of the spline? Ex: X(t), Y(t), Z(t)

 

 

intersect_ufcurve2.jpg

 

 

    for line in workPart.Curves:
            line_list.append(line)

    for j in range(len(line_list)):

            curve1 = line_list[j]

            for k in range(len(line_list)):

                curve2 = line_list[k]

                #returns a list of NX Open 3D Points
                poles=curve2.Get3DPoles()

                poles_list=[poles[0].X, poles[0].Y, poles[0].Z]          
                
                #trying to find intersection point of 2 splines 
                NXOpen.UF.Curve.Intersect(curve1, curve2, poles_list)

 

 

I also tried a second NX Open method, NXOpen.UF.Modeling.IntersectCurveToCurve, and I get a similar error message. At this point, I am thinking I will have to write my own function to approximate/calculate the intersection pt of 2 splines.

 

I will try to adapt @SteveLabout's code from the GTAC solution's center (

nx_api5674) but I don't know if it will work for the spline class

 

http://mathematica.stackexchange.com/questions/35107/intersection-of-two-splines

 

 

        for line in workPart.Curves:


            line_list.append(line)

        ###uf.modeling intersect method

        for j in range(len(line_list)):
            
            curve1 = line_list[j]

            for k in range(len(line_list)):
            
                curve2 = line_list[k]


                NXOpen.UF.Modeling.IntersectCurveToCurve(curve1, curve2)

                #including a tag (returns an integer) does not work either
                #NXOpen.UF.Modeling.IntersectCurveToCurve(curve1.Tag, curve2.Tag)

 

 

Re: intersection of splines/section curves

Hi,

 

Below is the code that lets you select two splines and outputs its intersection points.

 

using System;
using NXOpen;
using NXOpen.UF;

public class Program
{
    // class members
    private static Session theSession;
    private static UI theUI;
    private static UFSession theUfSession;
    public static Program theProgram;
    public static bool isDisposeCalled;

    //------------------------------------------------------------------------------
    // Constructor
    //------------------------------------------------------------------------------
    public Program()
    {
        try
        {
            theSession = Session.GetSession();
            theUI = UI.GetUI();
            theUfSession = UFSession.GetUFSession();
            isDisposeCalled = false;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- 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
    //------------------------------------------------------------------------------
    public static int Main(string[] args)
    {
        int retValue = 0;
        try
        {
            theProgram = new Program();

            //TODO: Add your application code here 
            Spline sp1 = null;
            Spline sp2 = null;

            if ((sp1 = select_obj("Select Spline")) != null)
            {
                sp2 = select_obj("Select Spline");
                sp1.Unhighlight();
                if (sp2 != null)
                {
                    sp2.Unhighlight();
                    int num_intersections = 0;
                    double[] theIntersections;

                    theUfSession.Modl.IntersectCurveToCurve(sp1.Tag, sp2.Tag, out num_intersections, out theIntersections);
                    for (int i = 0; i < num_intersections; i++)
                    {
                        theSession.ListingWindow.Open();
                        theSession.ListingWindow.WriteLine("Intersection " + (i+1).ToString());
                        theSession.ListingWindow.WriteLine("X = " + theIntersections[i * 5 + 0]);
                        theSession.ListingWindow.WriteLine("Y = " + theIntersections[i * 5 + 1]);
                        theSession.ListingWindow.WriteLine("Z = " + theIntersections[i * 5 + 2]);
                        theSession.ListingWindow.WriteLine("First curve parameter = " + theIntersections[i * 5 + 3]);
                        theSession.ListingWindow.WriteLine("Second curve parameter = " + theIntersections[i * 5 + 4]);
                        theSession.ListingWindow.WriteLine("");
                    }
                }
            }

            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
        return retValue;
    }

    private static Spline select_obj(string prompt)
    {
        UI theUI = UI.GetUI();
        NXObject selobj;
        Point3d cursor;
        Selection.MaskTriple[] mask = new Selection.MaskTriple[1];

        mask[0].Type = UFConstants.UF_spline_type;
        mask[0].Subtype = 0;
        mask[0].SolidBodySubtype = 0;


        Selection.Response resp = theUI.SelectionManager.SelectObject("Select " + prompt, prompt,
            Selection.SelectionScope.WorkPart, Selection.SelectionAction.ClearAndEnableSpecific, false, true, mask, out selobj, out cursor);

        if (resp == Selection.Response.ObjectSelected ||
                resp == Selection.Response.ObjectSelectedByName)
        {
            Spline theSpline = (Spline)selobj;
            return theSpline;
        }
        else
            return null;

    }

    //------------------------------------------------------------------------------
    // Following method disposes all the class members
    //------------------------------------------------------------------------------
    public void Dispose()
    {
        try
        {
            if (isDisposeCalled == false)
            {
                //TODO: Add your application code here 
            }
            isDisposeCalled = true;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
    }

    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);
    }

}

 

Re: intersection of splines/section curves

[ Edited ]

If you have access to SNAP, then this code works, and correctly computes all 16 intersection points:

 

Option Infer On
Imports Snap, Snap.Create

Public Class MyProgram

   Public Shared Sub Main()

      Dim s1 = Snap.Create.BezierCurve( {0, 0, 0}, {1, 20, 0}, {2, -30, 0}, {3, 25, 0}, {4, 0, 0} )
      Dim s2 = Snap.Create.BezierCurve( {0, 1, 0}, {20, 1, 0}, {-40, 3, 0}, {30, 3, 0}, {0, 4, 0} )

      Dim intPts = Snap.Compute.Intersect(s1, s2)

      For Each pt In intPts
         Snap.Create.Point(pt)
      Next

   End Sub

End Class

The SNAP docs have other example code that might be useful, too, even if you don't use SNAP.

 

I definitely do not recommend trying to code your own intersection function.

 

Internally, the SNAP function just calls  NXOpen.UF.UFModl.IntersectCurveToCurve.

山田
yamada

Re: intersection of splines/section curves

thank you all for your feedback. For some reason, the "NXOpen.UF.Modeling.IntersectCurveToCurve" method does not work on splines. I am writing it in Python. I will figure something out.

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

 

intersect_error2.jpg

Solution
Solution
Accepted by topic author AlexLee
‎11-18-2016 02:10 PM

Re: intersection of splines/section curves

[ Edited ]

Try the code below. It gets the first 2 curves in the work part's .Curves collection and looks for intersections. I tested on NX 10.0.3.5 and it seems to work on splines.

 

#Find intersection points of first 2 curves in work part's curves collection.
#Tested on NX 10.0.3.5

import NXOpen
import NXOpen.UF

theSession = NXOpen.Session.GetSession()
theLw = theSession.ListingWindow
theUfSession = NXOpen.UF.UFSession.GetUFSession()    
    
def main(): 

    workPart = theSession.Parts.Work
    
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "report intersection point")
    theLw.Open()    
        
    curveList = list(theSession.Parts.Work.Curves)
    curve1 = curveList[0]
    curve2 = curveList[1]
        
    (numInt, intData) = theUfSession.Modeling.IntersectCurveToCurve(curve1.Tag, curve2.Tag)
    theLw.WriteLine("number of intersections: " + str(numInt))
    
    for i in range(numInt):
        theLw.WriteLine("  " + str(i) + ": " + "(" + str(intData[5*i]) + ", " + str(intData[5*i+1]) + ", " + str(intData[5*i+2]) + ")")
    
    theLw.WriteLine("")
    
    theLw.Close()
    
    
if __name__ == '__main__':
    main()

 

 

It looks like you need to instantiate a UF session object and call its methods rather than trying to call the method definition. Instead of:

NXOpen.UF.Modeling.IntersectCurveToCurve(curve1.Tag, curve2.Tag)

use:

theUfSession = NXOpen.UF.UFSession.GetUFSession()
.
.
.
theUfSession.Modeling.IntersectCurveToCurve(curve1.Tag, curve2.Tag)
Solution
Solution
Accepted by topic author AlexLee
‎11-18-2016 02:10 PM

Re: intersection of splines/section curves

To summarise, your original code had two basic problems in your call to IntersectCurveToCurve:

 

(1)  It's method on an NXOpen.UF.UFModl object, so first you have to get one of these.

The typical way to get one is: NXOpen.UF.UFSession.GetUFSession().Modeling.

 

(2) The function expects to receive Tags for the curves. You were passing NXOpen.Spline objects, which are not tags. So, as you can see in Cowski's code, you need to write curve1.Tag and curve2.Tag. Generally, all NXOpen.UF functions work with tags.

山田
yamada