Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

holePackageBuilder and result as a body or feature 1

Status
Not open for further replies.

MANox

Mechanical
Apr 2, 2007
121
Hello,

I have journal for create thread with holePackageBuilder (record by NX and edited by me).
Code:
    Sub Create_thread(myPointTag As Tag, startPointTag As Tag, ThreadDepth As String, ThreadSize As String, TapDrillDiameter As String, ThreadedHoleDepth As String, thread_type As String, substractType As Boolean, direct As Boolean)

        Dim nullNXOpen_Features_HolePackage As NXOpen.Features.HolePackage = Nothing
        Dim holePackageBuilder1 As NXOpen.Features.HolePackageBuilder = Nothing
        holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(nullNXOpen_Features_HolePackage)

        Dim n_parents As Integer
        Dim parentTags As Tag()
        Dim line1 As NXOpen.Line
        theUfSession.So.AskParents(myPointTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)
        For Each parentTag As Tag In parentTags
            Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag)
            If parent_object.ToString.ToLower.Contains("line") Then
                line1 = parent_object
            End If
        Next
        Dim point1 As NXOpen.Point = Utilities.NXObjectManager.Get(myPointTag)
        Dim startpoint As NXOpen.Point = Utilities.NXObjectManager.Get(startPointTag)
        Dim nXObject1 As NXOpen.NXObject = Nothing
        Dim xform1 As NXOpen.Xform = Nothing
        xform1 = workPart.Xforms.CreateExtractXform(line1, NXOpen.SmartObject.UpdateOption.WithinModeling, False, nXObject1)
        Dim line2 As NXOpen.Line = CType(nXObject1, NXOpen.Line)
        Dim direction2 As NXOpen.Direction = Nothing

        If Not (Math.Abs(line2.StartPoint.X - point1.Coordinates.X) < 0.000001 And Math.Abs(line2.StartPoint.Y - point1.Coordinates.Y) < 0.000001 And Math.Abs(line2.StartPoint.Z - point1.Coordinates.Z) < 0.000001) Then
            direction2 = workPart.Directions.CreateDirection(line2, NXOpen.Sense.Reverse, NXOpen.SmartObject.UpdateOption.WithinModeling)
        Else
            direction2 = workPart.Directions.CreateDirection(line2, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)
        End If
        If direct = False Then
            Dim success1 As Boolean = Nothing
            success1 = direction2.ReverseDirection()
        End If
        holePackageBuilder1.ProjectionDirection.ProjectVector = direction2

        holePackageBuilder1.Tolerance = 0.00001
        holePackageBuilder1.ScrewStandard = "ISO"
        holePackageBuilder1.ThreadStandard = thread_type
        holePackageBuilder1.StartExtensionEnabled = False
        holePackageBuilder1.HolePosition.DistanceTolerance = 0.00001
        holePackageBuilder1.HolePosition.ChainingTolerance = 0.0000095
        holePackageBuilder1.ThreadedReliefDepth.RightHandSide = "0.5"
        holePackageBuilder1.ThreadedReliefDiameter.RightHandSide = "1"
        holePackageBuilder1.ThreadedReliefChamferOffset.RightHandSide = "0.08"
        holePackageBuilder1.ThreadedStartChamferDiameter.RightHandSide = "1"
        holePackageBuilder1.ThreadedEndChamferDiameter.RightHandSide = "1"

        holePackageBuilder1.EndHoleData.TapDrillDiameter.RightHandSide = "0.75"
        holePackageBuilder1.EndHoleData.ThreadedStartChamferDiameter.RightHandSide = "1"
        holePackageBuilder1.EndHoleData.ThreadedEndChamferDiameter.RightHandSide = "1"
        holePackageBuilder1.EndHoleData.ThreadedReliefDepth.RightHandSide = "0.5"
        holePackageBuilder1.EndHoleData.ThreadedReliefDiameter.RightHandSide = "1"
        holePackageBuilder1.EndHoleData.ThreadedReliefChamferOffset.RightHandSide = "0.08"

        holePackageBuilder1.RadialEngageOption = "Custom"
        holePackageBuilder1.Type = NXOpen.Features.HolePackageBuilder.Types.ThreadedHole
        holePackageBuilder1.ProjectionDirection.ProjectDirectionMethod = NXOpen.GeometricUtilities.ProjectionOptions.DirectionType.Vector
        holePackageBuilder1.ThreadLengthOption = NXOpen.Features.HolePackageBuilder.ThreadLengthOptions.Custom
        holePackageBuilder1.HolePosition.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyPoints)
        holePackageBuilder1.HolePosition.AllowSelfIntersection(True)
        Dim targetBodies1(0) As NXOpen.Body
        If IsSubstract = False Then
            holePackageBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create
            Dim nullNXOpen_Body As NXOpen.Body = Nothing
            targetBodies1(0) = nullNXOpen_Body
        Else
            holePackageBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract
            targetBodies1(0) = Body1
        End If
        'targetBodies1(0).SetUserAttribute("EndsType", -1, "9ENM10x60", Update.Option.Now)
        holePackageBuilder1.BooleanOperation.SetTargetBodies(targetBodies1)

        holePackageBuilder1.ThreadDepth.RightHandSide = ThreadDepth '"10"
        holePackageBuilder1.ThreadSize = ThreadSize ' "M10 x 1"
        holePackageBuilder1.TapDrillDiameter.RightHandSide = TapDrillDiameter '"9"
        holePackageBuilder1.ThreadedHoleDepth.RightHandSide = ThreadedHoleDepth '"12"


        Dim points1(0) As NXOpen.Point
        points1(0) = startpoint

        Dim curveDumbRule1 As NXOpen.CurveDumbRule = Nothing
        curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(points1)
        Dim rules1(0) As SelectionIntentRule
        rules1(0) = curveDumbRule1
        Dim nullNXOpen_NXObject As NXOpen.NXObject = Nothing
        Dim helpPoint1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
        holePackageBuilder1.HolePosition.AddToSection(rules1, nullNXOpen_NXObject, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, False)
        Dim nXObject3 As NXOpen.NXObject = Nothing
        nXObject3 = holePackageBuilder1.Commit()
        holePackageBuilder1.Destroy()

    End Sub
I would like add attribute for created thread as body (when BooleanOperation.Type = None) or feature (when BooleanOperation.Type = Substract).
It is possible get body or feature from holePackageBuilder for use in next operation?

Best regards
MANok
NX2207
Tc14
 
Replies continue below

Recommended for you

The builder's .Commit method will usually return something useful (nXObject3, in your case). However, in the case of a hole package builder, I would expect a feature to be created. You might have better luck using .CommitFeature instead of .Commit. Once you have a reference to the returned feature, you could use the feature's .GetBodies (since a hole package is a body feature) or .GetEntities to get the geometry.

www.nxjournaling.com
 
Thanks cowski,

You helping was very useful.

Best regards

MANok
NX2006
TC14
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor