NX二次开发 抽取线代码
时间: 2023-11-12 15:45:40 浏览: 76
抽取线是 NX 中的一个功能,可以用于在零件或装配体中创建二维截面曲线。以下是 NX 12 中抽取线的代码示例:
```
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
'选择曲面
Dim objectTag As Tag
Dim response As Integer
response = theUI.SelectionManager.SelectTaggedObject("Select a surface", "Select a surface", Selection.DialogType.Surface, False, False, objectTag)
Dim surface As Surface
surface = CType(NXObjectManager.Get(objectTag), Surface)
'创建抽取线
Dim curvesBuilder1 As CurveExtractor.CurvesBuilder
curvesBuilder1 = workPart.CurveManager.CreateCurveExtractor()
curvesBuilder1.Surface = surface
curvesBuilder1.SectionType = CurveExtractor.CurvesBuilder.SectionTypes.ExtractCurve
curvesBuilder1.ExtractMethod = CurveExtractor.CurvesBuilder.ExtractMethods.NormalToSurface
Dim curves1() As NXObject
curves1 = curvesBuilder1.CommitExtract()
'显示抽取线
Dim displayModification1 As DisplayModification
displayModification1 = workPart.DispLiteManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.NewColor = 186
displayModification1.NewTranslucency = 0.5
displayModification1.Apply()
For Each curve As Curve In curves1
Dim curve1 As Curve
curve1 = CType(workPart.NXObjectManager.CreateObjectFromHandle(curve.Tag), Curve)
Dim curveBuilder1 As CurveBuilder
curveBuilder1 = workPart.CurveManager.CreateCurveBuilder(curve1)
curveBuilder1.BooleanOperation.Type = BooleanOperation.BooleanType.None
curveBuilder1.BooleanOperation.Tolerance = 1.0E-4
curveBuilder1.Commit()
curveBuilder1.Destroy()
Next
displayModification1.Undo()
displayModification1.Dispose()
```
这段代码可以从选择曲面中创建抽取线,并在工作部件中显示抽取线。其中,`Surface` 表示待抽取的曲面,`CurvesBuilder` 用于创建抽取线,`DispLiteManager` 用于显示抽取线,`CurveBuilder` 用于对抽取线进行操作。
阅读全文