Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Module M_Trns
Sub Main1()
TranformOneOper("CONTOUR_AREA", "NewOper")
End Sub
'将输入的原始操作,经过两次变化后生成目标操作。(先旋转,后缩放。)
Sub TranformOneOper(ByVal stOperName As String, ByVal stName As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim operationTransformBuilder1 As CAM.OperationTransformBuilder
Dim operationTransformBuilder2 As CAM.OperationTransformBuilder
Dim objectsToTransform1(0) As CAM.CAMObject
Dim sp As Point3d
Dim ep As Point3d
Dim line1 As Line
Dim point1 As Point3d
Dim nXObject1 As NXObject
Dim rp As Point
sp.X = 0 : sp.Y = 0 : sp.Z = 0 : ep.X = 0 : ep.Y = 10 : ep.Z = 0
line1 = workPart.Curves.CreateLine(sp, ep)
point1 = New Point3d(0.0, 0.0, 0.0)
'绕直线旋转
objectsToTransform1(0) = workPart.CAMSetup.CAMOperationCollection.FindObject(stOperName)
operationTransformBuilder1 = workPart.CAMSetup.CreateOperationTransformBuilder(objectsToTransform1)
With operationTransformBuilder1
'.TransformType = CAM.OperationTransformBuilder.Transform.Translate
.TransformType = CAM.OperationTransformBuilder.Transform.RotateAboutLine '绕直线旋转
.MoveCopyInstance = CAM.OperationTransformBuilder.Result.Copy '复制
.LineMethod = CAM.OperationTransformBuilder.Line.Specify
.LineSelection.SetValue(line1, workPart.ModelingViews.WorkView, point1) '基准直线,当然,也可用两点方式。
.AngleValue = 13.0 '旋转角度。
nXObject1 = .Commit()
.Destroy()
End With
'以WCS原点为基点比例放大。
rp = workPart.Points.CreatePoint(sp) 'WCS原点
objectsToTransform1(0) = workPart.CAMSetup.CAMOperationCollection.FindObject(stOperName + "_COPY") '当原始操作名较长时,此句会失败。
operationTransformBuilder2 = workPart.CAMSetup.CreateOperationTransformBuilder(objectsToTransform1)
With operationTransformBuilder2
.TransformType = CAM.OperationTransformBuilder.Transform.Scale '比例变换
.ScaleFactor = 1.2 '比例值
.ReferencePoint = rp '参考点
.MoveCopyInstance = CAM.OperationTransformBuilder.Result.Move '移动
nXObject1 = .Commit()
.Destroy()
End With
objectsToTransform1(0).SetName(stName) '因为是移动,所以该变量引用的就是目标操作。
MsgBox("ok")
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = Session.LibraryUnloadOption.Immediately
End Function
End Module