Option Strict Off
Imports System
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.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myEdge As Edge
If SelectEdge("select circular edge", myEdge) = Selection.Response.Cancel Then
Return
End If
'lw.WriteLine(myEdge.Tag)
'method 1: use evaluator
Dim edgeEvaluator As System.IntPtr
theUfSession.Eval.Initialize(myEdge.Tag, edgeEvaluator) '通过边的TAG值得到edgeEvaluator(intptr为指针)
Dim arcInfo As UFEval.Arc
theUfSession.Eval.AskArc(edgeEvaluator, arcInfo) '通过theUfSession.Eval.AskArc函数的到UFEval.Arc,最后打印它的信息
lw.WriteLine("method 1: edge evaluator")
lw.WriteLine("radius: " & arcInfo.radius.ToString)
lw.WriteLine("")
'method 2: extract arc, query radius
Dim edgeArcTag As Tag
theUfSession.Modl.CreateCurveFromEdge(myEdge.Tag, edgeArcTag) '通过边创建曲线
Dim edgeCurve As Arc = Utilities.NXObjectManager.Get(edgeArcTag)
lw.WriteLine("method 2: extracted curve from edge")
lw.WriteLine("radius: " & edgeCurve.Radius.ToString)
'delete curve
Dim markId2 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete Arc")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(edgeCurve)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
lw.Close()
End Sub
Function SelectEdge(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response '选择边
Dim theUI As UI = UI.GetUI
Dim title As String = "Select circular edge"
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(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
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
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
Imports System
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.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myEdge As Edge
If SelectEdge("select circular edge", myEdge) = Selection.Response.Cancel Then
Return
End If
'lw.WriteLine(myEdge.Tag)
'method 1: use evaluator
Dim edgeEvaluator As System.IntPtr
theUfSession.Eval.Initialize(myEdge.Tag, edgeEvaluator) '通过边的TAG值得到edgeEvaluator(intptr为指针)
Dim arcInfo As UFEval.Arc
theUfSession.Eval.AskArc(edgeEvaluator, arcInfo) '通过theUfSession.Eval.AskArc函数的到UFEval.Arc,最后打印它的信息
lw.WriteLine("method 1: edge evaluator")
lw.WriteLine("radius: " & arcInfo.radius.ToString)
lw.WriteLine("")
'method 2: extract arc, query radius
Dim edgeArcTag As Tag
theUfSession.Modl.CreateCurveFromEdge(myEdge.Tag, edgeArcTag) '通过边创建曲线
Dim edgeCurve As Arc = Utilities.NXObjectManager.Get(edgeArcTag)
lw.WriteLine("method 2: extracted curve from edge")
lw.WriteLine("radius: " & edgeCurve.Radius.ToString)
'delete curve
Dim markId2 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete Arc")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(edgeCurve)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
lw.Close()
End Sub
Function SelectEdge(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response '选择边
Dim theUI As UI = UI.GetUI
Dim title As String = "Select circular edge"
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(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
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
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module