iCAx开思工具箱

标题: CAM操作变换问题,恳请赐教!急!!! [打印本页]

作者: hello_icax    时间: 2009-11-13 10:26
标题: CAM操作变换问题,恳请赐教!急!!!
本人想对某个操作进行两次变换。
先按某个轴旋转,然后以WCS原点作比例变换。
在GRIP中只要将两个变换矩阵相加即可。如下代码:
MAT1=MATRIX/ZXROT,30
MAT2=MATRIX/SCALE,1.2,1.2,1.2
MAT=MATRIX/MAT1,MAT2
OPTRAN/MAT,'R5_FSH',INSTNC,'AABBCC',30,IFERR,END1:

此代码可实现一次性变换。

现在,我想在vb.net中实现。
但我只能分两步实现。先旋转,再比例。
这样一来速度就慢了。

那位高手知道一步实现的方法。请赐教!谢谢!
作者: zhangcanwei    时间: 2009-11-13 17:44
你先把矩阵合并
作者: hello_icax    时间: 2009-11-14 08:40
谢谢2楼的热心。
但我是用的VB.NET开发,好像没用到矩阵。
代码如下:

    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()

        '比例变换
        Dim objects1(0) As CAM.CAMObject
        Dim operation2 As CAM.Operation
        operation2 = CType(workPart.CAMSetup.CAMOperationCollection.FindObject(stOper & "_COPY"), CAM.Operation)
        objectsToTransform1(0) = operation2
        operationTransformBuilder1 = workPart.CAMSetup.CreateOperationTransformBuilder(objectsToTransform1)
        operationTransformBuilder1.TransformType = CAM.OperationTransformBuilder.Transform.Scale
        operationTransformBuilder1.ReferencePoint = point3
        operationTransformBuilder1.MoveCopyInstance = CAM.OperationTransformBuilder.Result.Move '移动
        operationTransformBuilder1.ScaleFactor = nScale
        nXObject2 = operationTransformBuilder1.Commit()
        operationTransformBuilder1.Destroy()
        '比例变换 完成!
        operation2.SetName(stNewName)

end sub
作者: zhangcanwei    时间: 2009-11-15 07:17
CreateTranslationMatrix () 用这个函数来连续变换矩阵
作者: zhangcanwei    时间: 2009-11-15 07:19
你这段代码好像是录制的,你可以先做两次变换后,再进行operationTransformBuilder1.Commit()
作者: hello_icax    时间: 2009-11-15 11:55
zhang兄,谢谢你的支持!
但还是搞不定。

第一,用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

函数TransformObjects的返回值sta=3。好像是说无效对象。这是否说明对CAM对象不支持?

第二,“先做两次变换,再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    '旋转角度

        Dim nXObject2 As NXObject

        '比例变换
        operationTransformBuilder1.TransformType = CAM.OperationTransformBuilder.Transform.Scale
        operationTransformBuilder1.ReferencePoint = point3
        operationTransformBuilder1.MoveCopyInstance = CAM.OperationTransformBuilder.Result.Move '移动
        operationTransformBuilder1.ScaleFactor = nScale
        nXObject2 = operationTransformBuilder1.Commit()
        operationTransformBuilder1.Destroy()
        MsgBox("比例变换 完成!")
        operation1.SetName(stNewName)
    End Sub

我先指定变换方式为        operationTransformBuilder1.LineMethod = CAM.OperationTransformBuilder.Line.PointAndVector
然后不做operationTransformBuilder1.Commit()
指定变换方式为        operationTransformBuilder1.ScaleFactor = nScale

结果,是只进行了比例变换。
请您指教!谢谢!
作者: zhangcanwei    时间: 2009-11-15 12:55
1 我说的是变换矩阵,不是直接变换CAM操作。
2 我说的方法看来行不通。

这个方法100%可以:
operationTransformBuilder1.TransformType = CAM.OperationTransformBuilder.Transform.Reposition
然后设置operationTransformBuilder1.RepositionFromCsys
再设置 operationTransformBuilder1.RepositionToCsys

上面这两个Csys的设置应该不成问题吧
作者: hello_icax    时间: 2009-11-15 13:02
谢谢!容我研究一下!
作者: hello_icax    时间: 2009-11-15 13:11
zhang兄,请恕小弟愚笨。
1,用函数MultiplyMatrices()可以实现多个矩阵合并,但问题是:“函数TransformObjects的返回值sta=3。好像是说无效对象。这是否说明对CAM对象不支持?”

2,RepositionFromCsys只是方位变换,而我还要比例变换!




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3