找回密码 注册 QQ登录
一站式解决方案

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?快速3D打印 手板模型CNC加工服务在线3D打印服务,上传模型,自动报价
查看: 17544|回复: 8
打印 上一主题 下一主题

[求助] CAM操作变换问题,恳请赐教!急!!!

[复制链接]
跳转到指定楼层
1
发表于 2009-11-13 10:26:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
本人想对某个操作进行两次变换。
先按某个轴旋转,然后以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中实现。
但我只能分两步实现。先旋转,再比例。
这样一来速度就慢了。

那位高手知道一步实现的方法。请赐教!谢谢!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!
2
发表于 2009-11-13 17:44:13 | 只看该作者
你先把矩阵合并
3
发表于 2009-11-14 08:40:48 | 只看该作者
谢谢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
4
发表于 2009-11-15 07:17:27 | 只看该作者
CreateTranslationMatrix () 用这个函数来连续变换矩阵
5
发表于 2009-11-15 07:19:08 | 只看该作者
你这段代码好像是录制的,你可以先做两次变换后,再进行operationTransformBuilder1.Commit()
6
发表于 2009-11-15 11:55:56 | 只看该作者
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

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

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

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

2,RepositionFromCsys只是方位变换,而我还要比例变换!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2025-1-31 23:53 , Processed in 0.026115 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2025 www.iCAx.org

快速回复 返回顶部 返回列表