cancel
Showing results for 
Search instead for 
Did you mean: 

Building a simple hole

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello everyone!

 

I need help with an problem I considered trivial until I tried to solve it. Man Very Happy

I'm tryng to build a general simple hole through a body. I recorded a journal and found it absolutely incomprehensible - there's simple too much code there, and it covers all options at once. Maybe someone has a simple C# example? Thanks in advance!

14 REPLIES

Re: Building a simple hole

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Well, after speding a day with my nose buried in the journal code, I was finally able to build a hole. But initially I was proprely overwhelmed! Man Very Happy

Re: Building a simple hole

Esteemed Contributor
Esteemed Contributor

Did you look in the "Solutions" database? (https://solutions.industrysoftware.automation.siemens.com/)

search on something (e.g. "create hole")

Then filter on "document type" = "nx_api"

 

 

Also there are some example code files in your install folder (...\UGOPEN\SampleNXOpenApplications\...)

 

Ken

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Building a simple hole

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

I tried, but did not find anything. At any rate, I can build holes now. Thanks!

Re: Building a simple hole

Experimenter
Experimenter

I was overwhelmed by the amount of code to create a hole through the API jounral. 

 

I developed code using the older style Ufuncs.  But the problem was with the rpo constraints.  After creating the hole the rpo constraints worked okay.  But, NX would not allow repositionng or resizing of the constraint dimensions.

 

If anyone is interested the code is provided below.  It is considerabilty alot shorter than the Journaling code.  You can try it out and if anyone has any suggestions on fixing the rpo contraints I'd like to hear it.  Thanks.

 

theUfSession.Modl.RegisterRpoRoutine(AddressOf PlaceHole)

theUfSession.Modl.CreateSimpleHole(New Double(2) {xLen, yWidth / 2, zHeight}, _

New Double(2) {0, 0, -1}, _

holeDiameter.ToString(), "", "", _

topFace.Tag, btmFace.Tag, theHoleTag)

theUfSession.Modl.UnregisterRpoRoutine()

 

Function PlaceHole(ByVal theHoleTag As Tag) As Integer

Dim theHoleEdges() As Tag = {Tag.Null}

theUfSession.Modl.AskFeatEdges(theHoleTag, theHoleEdges)

Dim targets() As Tag = {theXAxis.Tag, theYAxis.Tag}

Dim target_qualifiers() As Integer = {0, 0} ' Not used

Dim tools() As Tag = {theHoleEdges(0), theHoleEdges(0)}

Dim tool_qualifiers() As Integer = {UFConstants.UF_MODL_ARC_CENTER, UFConstants.UF_MODL_ARC_CENTER}

Dim constraintNames() As String = {"PERP_DIST_PARMS", "PERP_DIST_PARMS"}

Dim constraintValues() As String = {"yDim=" & yDimension.ToString, "xDim=" & xDimension.ToString}

theUfSession.Modl.CreateRpoConstraints(theHoleTag, Nothing, Nothing, _

targets, target_qualifiers, _

tools, tool_qualifiers, _

constraintValues, constraintNames, 2)

End Function

 

Re: Building a simple hole

Genius
Genius

I recommend Python because you don't need to compile, the syntax is much easier to learn and there are several libraries out there (numpy, scipy, etc.)

 

Go to user preferences and Journal>> change the language to Python. Here is an incomplete example of how to start out

 

#import the libraries you need
import math
import NXOpen
import NXOpen.Features
import NXOpen.GeometricUtilities
import NXOpen.Preferences

#this will be your main hole creating function
def main() : 

     workPart = self.theSession.Parts.Work
#loop through all the parts
          for body in workPart.Bodies:
# call your hole builder method
                     holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(NXOpen.Features.HolePackage.Null)
    
    holePackageBuilder1.StartHoleData.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract
    
holePackageBuilder1.GeneralSimpleHoleDiameter.RightHandSide = "5"
    holePackageBuilder1.StartHoleData.BooleanOperation.SetTargetBodies(body)

if __name__ == '__main__':
main()

Re: Building a simple hole

Esteemed Contributor
Esteemed Contributor

Note that journaling has to do things certain ways, so yes, there is a lot of "junk"

 

First thing I do is comment out all the "undo" code, and make sure it still runs (I've run across a thing or 2 that requires an "undo" or 2 be set).

 

Once that is cleaned out, sometimes there's a lot of repetition that can be cleaned out.

 

Typically once that's done it is "reasonably" clean.

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Building a simple hole

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Actual code to create a hole is rather short. Here's what does the job for me:

 

                NXOpen.Features.HolePackageBuilder holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(null);
                holePackageBuilder1.Type = NXOpen.Features.HolePackageBuilder.Types.GeneralHole;
                holePackageBuilder1.GeneralSimpleHoleDiameter.RightHandSide = key.ToString(CultureInfo.CreateSpecificCulture("en-GB"));
                holePackageBuilder1.HoleDepthLimitOption = NXOpen.Features.HolePackageBuilder.HoleDepthLimitOptions.ThroughBody;
                holePackageBuilder1.BooleanOperation.SetTargetBodies(bodies);
                holePackageBuilder1.StartExtensionEnabled = true;

                NXObject nullNXObject = null;
                Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
                holePackageBuilder1.HolePosition.AddToSection(rules1, nullNXObject, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

                holePackageBuilder1.Tolerance = 0.01;
                holePackageBuilder1.HolePosition.DistanceTolerance = 0.01;
                holePackageBuilder1.HolePosition.ChainingTolerance = 0.0095;

                holePackageBuilder1.Commit();
                holePackageBuilder1.Destroy();

I personally find journalling only of very limited use for the exact reason that it swamps you with code that is all but irrelevant for the actual NX Open application.

Re: Building a simple hole

Phenom
Phenom

The journal recorder is a good teacher of the NXOpen API. Granted, the code it returns isn't the most concise, but it works. Sometimes the API objects work together in a way that isn't obvious from the API reference alone. Cleaning up the recorded code can be tedious, but it isn't usually that difficult to cull out what you don't need for your particular task.

 

FWIW, my general strategy is:

  1. Look for and comment/delete builder objects that don't pertain to the desired task. I once recorded code for adding a part attribute and the recorder also gave code for updating the mass properties and part preview. I only wanted to add an attribute, so I got rid of the other builder objects.
  2. Look for objects that are created and later deleted. Most often I see this with expression objects; the recorder will create a bunch then delete them at the end of the journal.
  3. Starting from the bottom up, look for variables that are declared then never referenced in later code.
  4. Try getting rid of the undo marks. As Ken wrote, occasionally one will be necessary (usually those associated with updates), but most are not.

Re: Building a simple hole

Phenom
Phenom

If you have an IDE that supports highlighting instances of variables etc, this can be very helpful in cleaning up these unwanted expressions, undo marks etc.

I'm using Java and the Eclipse IDE is quite good at this.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5