Download SNAP Getting Started Guide
Transcript
So, to create a line in the work part, the code is: Dim curves As CurveCollection = theWorkPart.Curves Dim p1 As New Point3d(1, 2, 3) Dim p2 As New Point3d(5, 4, 7) curves.CreateLine(p1, p2) ' ' ' ' Get the CurveCollection of the Work Part Define start point of line Define end point of line Create the line (add to collection) These collections are very useful if you want to cycle through all the objects of a certain type within a given part file. For example, to perform some operation on all the points in a given part file (myPart) you can write: For Each pt As Point In theWorkPart.Points ' Do something with pt Next A Part object has many collection objects that can be used in this way, including collections of bodies, faceted bodies, annotations, dimensions, drawing sheets, and so on. See the documentation for the NXOpen.Part class for further details. Note that, even though the Line class (for example) does not help us create lines, it does help us edit them and get information from them. Once we have created a Line object, we can use functions and properties in the Line class to modify it. For example, there are functions like NXOpen.Line.SetStartPoint and NXOpen.Line.SetEndPoints. ■ Features and Builders The discussion above covers the case of simple geometry like points, lines, and arcs. Next, let’s look at a more complex object like our Sphere feature. The code to build a sphere feature is as follows: [1] [2] [3] [4] [5] [6] [7] Dim nullSphere As NXOpen.Features.Sphere = Nothing Dim mySphereBuilder As NXOpen.Features.SphereBuilder mySphereBuilder = theWorkPart.Features.CreateSphereBuilder(nullSphere) mySphereBuilder.Property1 = <whatever you want> mySphereBuilder.Property2 = < whatever you want > Dim myObject As NXOpen.NXObject = mySphereBuilder.Commit() mySphereBuilder.Destroy() So, the general approach is to create a “builder” object (line [3]) modify its properties as desired (lines [4] and [5]) “commit” the builder to create a new object (line [6]) As you can see in line [3] above, the functions to create various types of “builder” objects are methods of a FeatureCollection object, and we can get one of these from workPart.Features. A SphereBuilder object is fairly simple, but other feature builders are very complex, with many properties that you can set. ■ Exploring NX Open By Journaling The NX Open API is very rich and deep — it has thousands of available functions. This richness sometimes makes it difficult to find the functions you need. Fortunately, if you know how to use the corresponding interactive function in NX, the journaling facility will tell you which NX Open functions to use, and will even write some sample code for you. You choose Tools Journal Record to start recording, run through the desired series of steps, and then choose Tools Journal Stop Recording. The code generated by journaling is verbose and is often difficult to read. But it’s worth persevering, because hidden within that code is an example call showing you exactly the function you need. You can indicate which language should be used in the recorded code by choosing Preferences User Interface Tools Journal. The available choices are C#, C++, Java, Python, and Visual Basic. Getting Started with SNAP Chapter 16: The Jump to NX Open Page 108