|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
请看如下代码.
代码的功能是:将输入的原始操作,经过两次变化后生成目标操作。(先旋转,后缩放。)
此功能在GRIP内可用一条命令直接完成.
请教在VB.NET内或 VC++内该如何实现?
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
GRIP如下:
MAT1=MATRIX/SCALE,nScaleX,nScaleY,nScaleZ
MAT2=MATRIX/ZXROT,ANG
MAT=MATRIX/MAT1,MAT2
OPTRAN/MAT,ST1,INSTNC,ST2,1,IFERR,END1:
相信在VC++内应该也有此功能,可惜找了N次都没找到..
没有次功能?还是要自己编制子程序实现? |
|