Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

get edges and faces

Pioneer
Pioneer

how to tag upper face of the cylinder and lower edges of the cube.

I recorded the jounal but it is showing FindObect method. Is there any method for this ?

I want specific faces and edges only.

6 REPLIES 6

Re: get edges and faces

Siemens Phenom Siemens Phenom
Siemens Phenom

There is no function that returns "the top face of a cylinder", or "the bottom edges of a cube".

 

You have to cycle through the given body, testing each face or edge in turn until you find the one you want.

 

So, in the case of the cylinder, there are three faces. One of them is cylindrical, so that's not the one you want. Of the two planar faces, one has a normal pointing upwards, and the other one has a normal pointing downwards. The face you want is the first of these two.

山田
yamada

Re: get edges and faces

Pioneer
Pioneer

I want get edge with vertices (0,0,0) and (50,0,0). this code is giving error, can you correct the error..?

Session theSession = Session.GetSession();
            Part workPart = theSession.Parts.Work;
            UFSession ufs = UFSession.GetUFSession();

            BlockFeatureBuilder builder = workPart.Features.CreateBlockFeatureBuilder(null);
            builder.OriginPoint= workPart.Points.CreatePoint(new Point3d(0, 0, 0));
            builder.SetOriginAndLengths(new Point3d(0, 0, 0), "50.0", "70.0", "90.0");
            NXObject nxobject=builder.CommitFeature();
            builder.Destroy();

            Tag block_tag;
            ufs.Modl.AskFeatBody(nxobject.Tag, out block_tag);

            Tag[] edge_list1;
            ufs.Modl.AskBodyEdges(block_tag, out edge_list1);
            double[] pt1 = { 0.0, 0.0, 0.0 };
            double[] pt2 = {0.0, 0.0, 0.0};
            double[] t ={ 0, 0, 0 };
            double[] o ={50, 0, 0 };
            int edgeCount;
            ufs.Modl.AskListCount(edge_list1, out edgeCount);

            ArrayList arr_list2 = new ArrayList();
            for (int i = 0; i < edgeCount; i++)
            {
                Tag edge;          
                int vcount;             

                ufs.Modl.AskListItem(edge_list1, i, out edge);
                ufs.Modl.AskEdgeVerts(edge, pt1, pt2, out vcount);

                if (pt1==t && pt2==o)
                {
                    arr_list2.Add(edge);
                }

            }

            Tag[] list2 = (Tag[]) arr_list2.ToArray(typeof(Tag));

            Tag blend1;
            ufs.Modl.CreateBlend("5", list2, 0,
                0, 0, 0, out blend1);

Re: get edges and faces

Siemens Phenom Siemens Phenom
Siemens Phenom

This line of code seems wrong, to me:

 

if (pt1==t && pt2==o)

What this does (I think) is compare the addresses of various arrays. So, this test will always fail, and your array of edges arr_list2 will always be empty.

 

What you want to do (I expect) is compare the locations of points. And, when you compare point locations, you need to use a small tolerance.

 

Also, I'd advise against using ArrayList; use System.Collection.Generic.List instead.

 

Lastly, I think the code would be easier if you used newer functions, instead of the old UF_MODL ones.

山田
yamada

Re: get edges and faces

Siemens Phenom Siemens Phenom
Siemens Phenom

Here's how you do it using Snap functions, which illustrates the logic. Using NX/Open would be similar:

 

using System.Collections.Generic;
using Snap;

namespace GetEdge
{
   class Program
   {
      static void Main()
      {
         var blockFeature = Snap.Create.Block(Position.Origin, 50, 70, 90);
         var blockBody = blockFeature.Body;

         var edgeList = new List<Snap.NX.Edge>();
         Position pt0 = new Position(0,0,0);
         Position pt1 = new Position(50,0,0);
         double tol = 0.0001;

         foreach (Snap.NX.Edge edge in blockBody.Edges)
         {
            Position p0 = edge.StartPoint;
            Position p1 = edge.EndPoint;

            double d00 = Snap.Position.Distance(p0, pt0);
            double d01 = Snap.Position.Distance(p0, pt1);
            double d10 = Snap.Position.Distance(p1, pt0);
            double d11 = Snap.Position.Distance(p1, pt1);

            if (d00 < tol && d11 < tol) edgeList.Add(edge);
            if (d01 < tol && d10 < tol) edgeList.Add(edge);
         }

         if (edgeList.Count > 0) Snap.Create.EdgeBlend(5, edgeList.ToArray());
      }
   }
}
山田
yamada

Re: get edges and faces

Pioneer
Pioneer

@Yamada thanks for the information.

can you suggest me newer functions which used instead of the old UF_MODL.

Re: get edges and faces

Siemens Phenom Siemens Phenom
Siemens Phenom

NXOpen.Features.BodyFeature.GetBodies

NXOpen.Body.GetEdges

NXOpen.Body.GetFaces

山田
yamada