Submitted by DHuskic on Thu, 09/04/2014 - 12:25
Forums:
How would I go about wavelinking self intersecting curves? I have tried recording and generalizing the code to take a selection input but I keep getting commit errors, along with an example I found on GTAC that I was not able to get working. Any help is greatly appreciated, thank you.
re: self intersecting curve
Try recording a journal while creating a wave link (composite curve), be sure to check the "allow self-intersection" option in the dialog box. The resulting code will contain a line such as:
compositeCurveBuilder1.AllowSelfIntersection = True
Wave Link A Curve
This is the code I have been using to attempt wave linking a curve, however, it either completes the program and appears not to apply the changes, or gets stuck running forever and I am forced to close it. This is based off an example on GTAC.
Sub CreateLinkedCurve(theCurve As Curve)
Dim waveLinkBuilder1 As Features.WaveLinkBuilder
waveLinkBuilder1 = Workpart.BaseFeatures.CreateWaveLinkBuilder(Nothing)
waveLinkBuilder1.Type = Features.WaveLinkBuilder.Types.CurveLink
Dim compositeCurveBuilder1 As Features.CompositeCurveBuilder
compositeCurveBuilder1 = waveLinkBuilder1.CompositeCurveBuilder
compositeCurveBuilder1.Associative = True
compositeCurveBuilder1.AllowSelfIntersection = True
Dim section1 As Section
section1 = compositeCurveBuilder1.Section
section1.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)
section1.AllowSelfIntersection(True)
Dim acurve As Curve() = {theCurve.Prototype}
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = Workpart.ScRuleFactory.CreateRuleCurveDumb({theCurve})
Dim rules1() As SelectionIntentRule = {curveDumbRule1}
section1.AddToSection(rules1, theCurve.Prototype, Nothing, Nothing, _
AskCurveStartPoint(theCurve), Section.Mode.Create, False)
'This method stalls the program and makes it run forever
Dim nXObject1 As NXObject
nXObject1 = waveLinkBuilder1.Commit()
'This method appeared not to apply any changes
'Dim theCompositeCurve As Features.CompositeCurve = waveLinkBuilder1.Commit()
waveLinkBuilder1.Destroy()
End Sub
DHuskic
Nx 9 VB
re: wave link a curve
I recorded a wave link operation and modified the result into the following journal (NX 8.5).
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module wavelink_curve
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "wave link curve")
Dim theCurve As Curve = Nothing
If SelectCurve("Select a curve", theCurve) = Selection.Response.Cancel Then
Return
End If
Dim curvePart As Part = Nothing
If theCurve.IsOccurrence Then
curvePart = theCurve.Prototype.OwningPart
Else
curvePart = theCurve.OwningPart
End If
If theSession.Parts.Work.Equals(curvePart) Then
MsgBox("choose curve from a part other than the current work part")
Return
End If
WaveLinkCurve(theCurve)
lw.Close()
End Sub
Function SelectCurve(ByVal prompt As String, ByRef theObj As Curve) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a curve"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(3) As Selection.MaskTriple
Dim selObj As TaggedObject = Nothing
With selectionMask_array(0)
.Type = UFConstants.UF_circle_type
.Subtype = 0
End With
With selectionMask_array(1)
.Type = UFConstants.UF_conic_type
.Subtype = UFConstants.UF_all_subtype
End With
With selectionMask_array(2)
.Type = UFConstants.UF_line_type
.Subtype = UFConstants.UF_all_subtype
End With
With selectionMask_array(3)
.Type = UFConstants.UF_spline_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
theObj = selObj
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Sub WaveLinkCurve(ByVal someCurve As Curve)
Dim waveLinkBuilder1 As Features.WaveLinkBuilder
waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(Nothing)
Dim compositeCurveBuilder1 As Features.CompositeCurveBuilder
compositeCurveBuilder1 = waveLinkBuilder1.CompositeCurveBuilder
With compositeCurveBuilder1
.AllowSelfIntersection = True
.Section.DistanceTolerance = 0.001
.Section.ChainingTolerance = 0.00095
.Associative = True
.MakePositionIndependent = False
.FixAtCurrentTimestamp = False
.HideOriginal = False
.InheritDisplayProperties = False
.JoinOption = Features.CompositeCurveBuilder.JoinMethod.No
.Tolerance = 0.001
End With
Dim section1 As Section
section1 = compositeCurveBuilder1.Section
section1.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)
Dim curves1(0) As IBaseCurve
curves1(0) = someCurve
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)
section1.AllowSelfIntersection(True)
Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXObject As NXObject = Nothing
Dim helpPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
section1.AddToSection(rules1, someCurve, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)
Dim nXObject1 As NXObject
nXObject1 = waveLinkBuilder1.Commit()
waveLinkBuilder1.Destroy()
End Sub
End Module