cancel
Showing results for 
Search instead for 
Did you mean: 

Generating Surfaces using NX OPEN and C++

Pioneer
Pioneer

Hi! I am trying to generate my custom parametric surfaces like NURBS, Bezier patches, for my research in Manufacturing. To start with I am trying to write a code in C++, for plotting a line, using NX OPEN application wizard of Visual Studio9 and then running the .dll file in NX. I am stuck on the point, about what libraries/functions to use so that when the code runs in NX, I can get the display of a line and two points on the NX Open Interface. I am sure, if I can get a line, I can extend it to get curves and subsequently surfaces.

12 REPLIES

Re: Generating Surfaces using NX OPEN and C++

Esteemed Contributor
Esteemed Contributor

Have you already tried to record a C++ journal of what you like to do, when you do it manually in an interactive NX session?

 

I always record a journal of the manual approach to get the blue-print for my final code.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Generating Surfaces using NX OPEN and C++

Pioneer
Pioneer

Stefan,

 

I tried that for generating just points in NX and recording its journal, and I found that the code generated is 100s of lines in length which makes it difficult to read and tweak with. I am looking for a direct, simplified method to just join two points with a line (Just like a set of points are displayed as joined by lines, in Matlab by "plot"/"line" command). This would help me to extend it o higher dimensions of geometries (surfaces,solids) more easily as I would have only the code lines that I need. 

 

Thanks,

Archak

Re: Generating Surfaces using NX OPEN and C++

Siemens Phenom Siemens Phenom
Siemens Phenom

I don't think you're looking at the problem the right way. In NX, you don't display a curve or a surface by drawing lots of tiny lines. Instead, you tell NX to create the curve or surface, and then it (NX) takes care of displaying it.

 

I never use C++, so I can't give you any example code, but I expect some is available on the GTAC site.

 

In C#, the code to create a line is:

 

NXOpen.Point3d p0 = new NXOpen.Point3d(3,5,9);
NXOpen.Point3d p1 = new NXOpen.Point3d(1,6,8);

NXOpen.Part workPart = NXOpen.Session.GetSession().Parts.Work;

NXOpen.Line myLine = workPart.Curves.CreateLine(p0, p1);

If you have access to the SNAP API, its even easier:

 

Snap.Position p0 = new Snap.Position(3,5,9);
Snap.Position p1 = new Snap.Position(1,6,8);
Snap.NX.Line myLine = Snap.Create.Line(p0, p1);

But, again, you shouldn't be displaying curves and surfaces by drawing little lines.

 

It might help to read some of the "Getting Started with SNAP" guide, especially chapter 16.

 

 

 

山田
yamada

Re: Generating Surfaces using NX OPEN and C++

Genius
Genius

Hello Archak!

 

As Yamada said, perhaps you are looking at your problem the wrong way.

 

First topic: Visualize a line

If you want NX to visualize a single line and you DON'T want to create it,

you can use the method DisplayTemporaryLine. This line will NOT appear in the

part navigator since it is just a temporary line.

 

As far as I know there is no function like that for surfaces, so you will have to create

a patch (which will appear in the part navigator).

 

Second topic: Create a NURBS-Patch

Since you mentionend NURBS and Bezier-Patches I assume that you are

familiar with some basic expressions like poles and knot vectors of

a (Tensor Product) B-Spline (surface).

 

To create a Spline-Surface you can use the method CreateBsurf  in the UFMODL Class.

You should pay attention to:

- The order of a B-Spline is (degree+1), so for a cubic patch it is 4 not 3!

- The poles are homogeneous coordinates, that means (x,y,z,w) with w = weight of the pole.

   If your B-Spline Patch is polynomial, all weights must be set to 1.

 

After calling that method, the new surface should be listed in the part navigator (I think as a Body..)

and will be added in the model.

 

Hope that helps! :-)

 

Flo

 

 

Re: Generating Surfaces using NX OPEN and C++

Pioneer
Pioneer

Thank you Yamada for providing the knowledge that curves and surfaces can't be plotted by "little lines" as in Matlab. That brings a difficulty, that I can only plot the type of surfaces that are built in NX. I wonder if I try to implement my own mathematics for a specific surface geometry, how would I implement that. Moreover, I will have to check if I can completely customise the available modules of NURBS or B-splines - like knot vector values, parameter set (not just the range), control point position. For example, in Matlab I can just give any mathematical function to generate any geometry or its representation - all I need are the points on the geometry and they can be joined by little lines to look like a surface mesh. I will explore more about it in NX.

Re: Generating Surfaces using NX OPEN and C++

Pioneer
Pioneer

Thank you FlolScreen, I will try to use these functions and see what all I can tweak with. Probably, then I will come up with more specific or perhaps altogether new questions.

Re: Generating Surfaces using NX OPEN and C++

Siemens Phenom Siemens Phenom
Siemens Phenom

You can display curves and surfaces in NX by drawing little lines (as in Matlab) if you want to. My point was that this is usually not the right approach. 

However, if you want to display some geometry type that NX doesn't support, then drawing little lines might be a reasonable approach, maybe. But, it might be better to approximate your new geometry type by a NURBS surface. You'll be able to use the NURBS approximation in all NX functions, whereas the network of little lines will be pretty useless. You'll be able to display the lines (as in Matlab), but not much else.

Adding new geometry types is not very well supported because NX provides a broad range already. I'd be intersted to know what type(s) you want to add. 

Certainly the NX implementation of NURBS curves and surfaces is very general. You have complete control over control points, weights, and knots, with very few restrictions.

As usual, the SNAP functions are the easiest to use. The example below uses the Snap.Create.Bsurface function. It's written in VB, but the correspondence with C++ should be fairly obvious. Other examples are available in the SNAP Reference guide (which is where I got this one):

 

Public Class MyProgram

   Public Shared Sub Main()

      Dim p00, p01, p02, p03, p04 As Position
      Dim p10, p11, p12, p13, p14 As Position
      Dim p20, p21, p22, p23, p24 As Position
      Dim p30, p31, p32, p33, p34 As Position
      Dim p40, p41, p42, p43, p44 As Position
      Dim p50, p51, p52, p53, p54 As Position

      p00 = {0, 0, 0}     :  p01 = {0, 1, 0.02}  :  p02 = {0, 2, 0.08}  :  p03 = {0, 3, 0.18}  :  p04 = {0, 4, 0.32}
      p10 = {1, 0, 0.01}  :  p11 = {1, 1, 0.03}  :  p12 = {1, 2, 0.09}  :  p13 = {1, 3, 0.19}  :  p14 = {1, 4, 0.33}
      p20 = {2, 0, 0.04}  :  p21 = {2, 1, 0.06}  :  p22 = {2, 2, 0.12}  :  p23 = {2, 3, 0.22}  :  p24 = {2, 4, 0.36}
      p30 = {3, 0, 0.09}  :  p31 = {3, 1, 0.11}  :  p32 = {3, 2, 0.17}  :  p33 = {3, 3, 0.27}  :  p34 = {3, 4, 0.41}
      p40 = {4, 0, 0.16}  :  p41 = {4, 1, 0.18}  :  p42 = {4, 2, 0.24}  :  p43 = {4, 3, 0.34}  :  p44 = {4, 4, 0.48}
      p50 = {5, 0, 0.25}  :  p51 = {5, 1, 0.27}  :  p52 = {5, 2, 0.33}  :  p53 = {5, 3, 0.43}  :  p54 = {5, 4, 0.57}

      ' Array of poles. We have nu = 6 in the u-direction, and nv = 5 in the v-direction
      Dim poles as Position(,) =
         {  { p00, p01, p02, p03, p04 } ,
            { p10, p11, p12, p13, p14 } , 
            { p20, p21, p22, p23, p24 } ,
            { p30, p31, p32, p33, p34 } ,
            { p40, p41, p42, p43, p44 } ,
            { p50, p51, p52, p53, p54 } }

      ' Array of weights, again with size nu = 6 and nv = 5
      Dim weights as Double(,) =
         {  { 1, 1, 1, 1, 1 } ,
            { 1, 2, 2, 2, 1 } , 
            { 1, 2, 3, 2, 1 } ,
            { 1, 2, 3, 2, 1 } ,
            { 1, 2, 2, 2, 1 } ,
            { 1, 1, 1, 1, 1 } }

      ' We're going to create a surface with degree = 3 in the u-direction, so ku = 4.
      ' So, our array of knots for the u-direction must have nu + ku = 6 + 4 = 10 elements.
      ' Also, since ku = 4, the knot array must start with 4 0's and end with 4 1's
      Dim knotsU As Double() = { 0,0,0,0,  0.31,  0.59,  1,1,1,1 }

      ' We're going to create a surface with degree = 2 in the v-direction, so kv = 3.
      ' So, our array of knots for the v-direction must have nv + kv = 5 + 3 = 8 elements.
      ' Also, since kv = 3, the knot array must start with 3 0's and end with 3 1's
      Dim knotsV As Double() = { 0,0,0,  0.35,  0.65,  1,1,1 }

      ' Create the surface
      Bsurface(poles, weights, knotsU, knotsV)

   End Sub

End Class

 

The function UF_MODL_create_bsurf is roughly equivalent to Snap.Create.Bsurface, and only a bit harder to use.

山田
yamada

Re: Generating Surfaces using NX OPEN and C++

Genius
Genius

Hello Archak!

 

Depending on your data you can also use the method CreateBsurfThruPts, which will create a

Spline-Surfaces using a interpolation.

 

As a first step you can try to sample your surface(s) in matlab (e.g. 100x100 points in a rectangular form),

write a *.dat file (e.g. in Matlab with fprintf) and then create a B-Spline surface in NX using the command

Menu->Insert->Surface->Through Points...

 

The quality of the result highly depends on the input data, but you would be able to test the function

very easily (without using NXOpen in the first way) and perhaps the resulting face is fine for your purposes.

(of course you can implement that function in NXOpen after some tests..).

 

The format of the *.dat file looks like this:

 

ROW 1
0 0 0
0 1 0
...

ROW 2
...

You will need at least (m+1)-rows/cols, so for a cubic patch you will need at least 4 rows and at least 4 entries in a row. Otherwise the solution of the interpolation is not unique and you'll get an error.

 

Perhaps you can post an example of what your surfaces look like (Matlab screenshot). There is a huge

amount of surface creation types in NX, perhaps we can find the best one for your problem! :-)

 

flo

Re: Generating Surfaces using NX OPEN and C++

Pioneer
Pioneer
Thank you Yamada for sharing this example, it will help me to understand better. I guess I will try to implement the functions that have been discussed in this thread, and then see how does that turn out. I am trying to implement another modified (by me) version of NURBS for my research, to handle some specific cases in surface reconstruction. I will let you know as I progress along the implementation. Thanks again.