Private Sub CopyThisOneOperation1(ByVal theSession As Session, ByVal stOper As String, _
ByVal workPart As Part, ByVal nAng As Double, ByVal nScale As Double, ByVal stNewName As String)
Dim objectsToTransform1(0) As CAM.CAMObject
Dim operation1 As CAM.Operation = CType(workPart.CAMSetup.CAMOperationCollection.FindObject(stOper), CAM.Operation)
objectsToTransform1(0) = operation1
Dim operationTransformBuilder1 As CAM.OperationTransformBuilder
operationTransformBuilder1 = workPart.CAMSetup.CreateOperationTransformBuilder(objectsToTransform1)
operationTransformBuilder1.TransformType = CAM.OperationTransformBuilder.Transform.RotateAboutLine '+ CAM.OperationTransformBuilder.Transform.Scale
operationTransformBuilder1.LineMethod = CAM.OperationTransformBuilder.Line.PointAndVector
'旋转变换
Dim op As Point3d = New Point3d(0, 0, 0)
Dim point3 As NXOpen.Point
point3 = workPart.Points.CreatePoint(op)
operationTransformBuilder1.LinePoint = point3 '必须要此行
Dim vec1 As Vector3d = New Vector3d(0, 1, 0)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(op, vec1, SmartObject.UpdateOption.AfterModeling)
operationTransformBuilder1.LineVector = direction1
operationTransformBuilder1.MoveCopyInstance = CAM.OperationTransformBuilder.Result.Copy
operationTransformBuilder1.NumOfCopyInstance = 1
operationTransformBuilder1.AngleValue = nAng '旋转角度
Dim nXObject2 As NXObject
nXObject2 = operationTransformBuilder1.Commit()
operationTransformBuilder1.Destroy()
第一,用UF函数好像不可对CAM对象进行变换。请看如下代码。
我运行后是失败的。
Private Sub TestTransform(ByVal workPart As Part, ByVal nAng As Double, ByVal nScale As Double)
Dim se As UFSession = UFSession.GetUFSession()
Dim obj1 As NXObject = Nothing
Dim org(2) As Double '原点
Dim dec(2) As Double '方向
Dim mat(15) As Double '变换矩阵。
Dim sta As Integer '状态。
org(0) = 0 : org(1) = 0 : org(2) = 0
dec(0) = 0 : dec(1) = 1 : dec(2) = 0 '绕Y轴旋转角度nAng
se.Trns.CreateRotationMatrix(org, dec, nAng, mat, sta)
MsgBox(sta.ToString & mat.ToString) 'sta返回零表示成功。
Dim operation1 As CAM.Operation = CType(workPart.CAMSetup.CAMOperationCollection.FindObject("CAM1"), CAM.Operation)
Dim sTags(0) As NXOpen.Tag
sTags(0) = operation1.Tag '下面的变换函数只能变换几何实体,不能变换CAM对象。不知为何。
Dim tTags(0) As Tag
Dim gTag As Tag
Dim nCou As Integer
MsgBox(sTags(0).ToString)
nCou = 1 '指定变换数量。
se.Trns.TransformObjects(mat, sTags, nCou, 2, -1, 2, tTags, gTag, sta)
MsgBox(sta.ToString) ' 3 - Invalid Object (Not Alive Or Not Transformable)
End Sub
第二,“先做两次变换,再commit()”,该如何实现?
请看下面的代码。
Private Sub CopyThisOneOperation1(ByVal theSession As Session, ByVal stOper As String, _
ByVal workPart As Part, ByVal nAng As Double, ByVal nScale As Double, ByVal stNewName As String)
Dim objectsToTransform1(0) As CAM.CAMObject
Dim operation1 As CAM.Operation = CType(workPart.CAMSetup.CAMOperationCollection.FindObject(stOper), CAM.Operation)
objectsToTransform1(0) = operation1
Dim operationTransformBuilder1 As CAM.OperationTransformBuilder
operationTransformBuilder1 = workPart.CAMSetup.CreateOperationTransformBuilder(objectsToTransform1)
operationTransformBuilder1.TransformType = CAM.OperationTransformBuilder.Transform.RotateAboutLine
'旋转变换
operationTransformBuilder1.LineMethod = CAM.OperationTransformBuilder.Line.PointAndVector
Dim op As Point3d = New Point3d(0, 0, 0)
Dim point3 As NXOpen.Point
point3 = workPart.Points.CreatePoint(op)
operationTransformBuilder1.LinePoint = point3 '必须要此行
Dim vec1 As Vector3d = New Vector3d(0, 1, 0)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(op, vec1, SmartObject.UpdateOption.AfterModeling)
operationTransformBuilder1.LineVector = direction1
operationTransformBuilder1.NumOfCopyInstance = 1
operationTransformBuilder1.AngleValue = nAng '旋转角度