Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) 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 = "connected_curves"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim theCurve As Curve
If SelectCurve("select seed curve", theCurve) = Selection.Response.Cancel Then
Return
End If
Dim section1 As Section
section1 = workPart.Sections.CreateSection(0.00095, 0.001, 0.5)
section1.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
section1.AllowSelfIntersection(True)
Dim curveChainRule1 As CurveChainRule
curveChainRule1 = workPart.ScRuleFactory.CreateRuleCurveChain(theCurve, Nothing, True, 0.001)
Dim rules1(0) As SelectionIntentRule
rules1(0) = curveChainRule1
Dim nullNXObject As NXObject = Nothing
Dim helpPoint1 As Point3d = New Point3d(0, 0, 0)
section1.AddToSection(rules1, theCurve, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)
Dim outputObjs() As NXObject
section1.GetOutputCurves(outputObjs)
Dim theData() As SectionData
section1.GetSectionData(theData)
Dim theSectionElementData() As SectionElementData
theData(0).GetSectionElementsData(theSectionElementData)
Dim sectionElements As New List(Of DisplayableObject)
lw.WriteLine("number of curves in section: " & outputObjs.Length.ToString)
For Each temp As SectionElementData In theSectionElementData
Dim secElement As DisplayableObject
Dim stConn As DisplayableObject
Dim stPt As Point3d
Dim endConn As DisplayableObject
Dim endPt As Point3d
temp.GetSectionElementData1(secElement, stConn, stPt, endConn, endPt)
sectionElements.Add(secElement)
Next
For Each temp As DisplayableObject In sectionElements
Dim secCurve As Curve = DirectCast(temp, Curve)
lw.WriteLine("curve type: " & secCurve.GetType.ToString)
lw.WriteLine("curve length: " & secCurve.GetLength.ToString)
lw.WriteLine("")
Next
lw.Close()
End Sub
Function SelectCurve(ByVal prompt As String, ByRef selCurve 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.WorkPart
Dim selectionMask_array(3) As Selection.MaskTriple
Dim selObj As TaggedObject
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)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selCurve = DirectCast(selObj, Curve)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
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