Extrude circles

Hello,

I am fresh in journaling with NX.

I could create several randomly distributed circles on a surface of my part (a cube). Now I want to extrude these circles through the cube to make cylindrical holes. The holes do not start from the surface, but the start and the end points for extruding are known.
I found a code for extruding curves of a part on this website, but it doesn't work for me since I could not select the circles (they are not shown in the NX tree) as the curves, and also the start point is not zero in my case.

Any help would be appreciated.

I would suggest that you start by recording a journal while performing an extrude operation. When you start the extrude command, it will prompt you to "Select curve"; you can select any curve, whether it is in the feature tree or not. The recorded journal will give you a good starting point for your code; you will be able to edit the recorded code to better meet your exact needs.

Thanks.

Actually I had done so, but in the code, it assigns the curve using this:
Dim arc1 As NXOpen.Arc = CType(workPart.Arcs.FindObject("ENTITY 5 8 1"), NXOpen.Arc)
in which it is not clear for me where "ENTITY 5 8 1" comes from.

I need to know the names of the curves and how to assign them to 'arc1'. Is it possible to make a list of curves in the part to be able to call them in such a case?

Regards

Do you want the user to interactively pick an arc, or do you want the journal to use a certain arc object that exists in the file?

If you want the user to interactively pick an arc, you can add a selection function.

If you want to use a specific, existing arc; you would need some way of identifying the arc that you want to use. You could give the arc a custom name or attribute so you can find the correct one when the journal runs. The part object has an .Arcs collection that you can iterate through to find the one you want.

The "ENTITY 5 8 1" is a system generated name assigned to the object (the 'journal identifier'). Generally speaking, these are for use by the journal recorder and won't be used by your code.

I want the journal to use a certain arc object that exists in the file.
As I explained I cannot rename my arcs (circles) since I do not see them in NX environment. Moreover, I need to select more than one arc (imagine something around 100 arcs), and extrude them. Therefore, as you mentioned, I need to iterate through the .Arcs collection, and choose those which fulfill some geometrical requirements (e.g. those which are in XZ plane). Then, I assign them to the curve in the extrude journal.
Could you please provide me with (an example of) such a code? I couldn't find it anywhere.

Regards

Even though it doesn't show up in the model tree, you can still give it a name. Objects can have names independent of feature names. To name one of these arcs, right click on it -> properties -> general -> enter name -> OK.

I'll make an example of finding circles on the XZ plane and post it later. It sounds like finding arcs by orientation/size will work better in your case.

The journal below finds arcs that are parallel to the absolute XZ plane and extrudes them in the Y direction. You could test the centerpoint location to see if they are on a particular plane.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "extrude XZ arcs"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim XZarcs As New List(Of Arc)
Dim angularTolerance As Double = 0.25 'angular tolerance in degrees
Dim vecTol As Double = Math.Sin(angularTolerance * Math.PI / 180) 'tolerance value converted for the vector function

'absolute Y vector
Dim YVec(2) As Double
YVec(0) = 0
YVec(1) = 1
YVec(2) = 0

For Each temp As Arc In workPart.Arcs

Dim arcZvec(2) As Double
arcZvec(0) = temp.Matrix.Element.Zx
arcZvec(1) = temp.Matrix.Element.Zy
arcZvec(2) = temp.Matrix.Element.Zz

Dim isParallel As Boolean = False
theUfSession.Vec3.IsParallel(YVec, arcZvec, vecTol, isParallel)
If isParallel Then
XZarcs.Add(temp)
End If

Next

'use absolute Y vector as extrude direction
Dim direction1 As Direction
Dim origin As New Point3d(0, 0, 0)
Dim vec As New Vector3d(0, 1, 0)
direction1 = workPart.Directions.CreateDirection(origin, vec, SmartObject.UpdateOption.DontUpdate)

Dim nullFeatures_Feature As Features.Feature = Nothing
Dim nullNXObject As NXObject = Nothing

Dim extrudeBuilder1 As Features.ExtrudeBuilder
extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature)

Dim section1 As Section
section1 = workPart.Sections.CreateSection(0.00038, 0.0004, 0.5)
section1.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
section1.AllowSelfIntersection(True)

With extrudeBuilder1
.Section = section1
.AllowSelfIntersectingSection(True)
.DistanceTolerance = 0.0004
.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
.Limits.StartExtend.Value.RightHandSide = "-0.5"
.Limits.EndExtend.Value.RightHandSide = "1"
.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
.Direction = direction1
End With

For Each temp As Arc In XZarcs
Dim curves1(0) As IBaseCurve

curves1(0) = temp
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1

section1.AddToSection(rules1, temp, nullNXObject, nullNXObject, temp.CenterPoint, Section.Mode.Create, False)

Next

Dim feature1 As Features.Feature
feature1 = extrudeBuilder1.CommitFeature()

extrudeBuilder1.Destroy()

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

It does exactly what I need.
Thanks!

Regards

Here's the same thing using SNAP functions. Since you're a beginner, it might be easier for you to understand.

Option Infer On
Imports Snap, Snap.Create

Public Class MyProgram

Public Shared Sub Main()

Dim axisY = Vector.AxisY
Dim angleTolerance = 0.1 ' Angle tolerance, in degrees

For Each arc1 In Snap.Globals.WorkPart.Arcs

If Vector.Angle(arc1.AxisZ, axisY) < angleTolerance
Extrude( {arc1}, axisY, 10)
End If

Next

End Sub

End Class

SNAP is definitely a good way to go; if you have a license for it.