iCAx开思工具箱

标题: 偏置操作后,如何保留原始曲线 [打印本页]

作者: zhangcanwei    时间: 2009-10-17 23:09
标题: 偏置操作后,如何保留原始曲线
代码如下: 这是从NX中录制的,我稍稍做了改动,其中InputCurve()为Curve类型的数组,是原始输入曲线。这段代码运行后,输入曲线可以偏置10毫米,但是原始曲线也消失了

Public Sub TheOffsetCurveSub(ByVal inputCurve() As NXOpen.Curve, ByRef TagIndex As Integer, ByVal LinkTolerance As Double)
        Dim workPart As Part = Sess.Parts.Work
        Dim markId1 As Session.UndoMarkId
        markId1 = Sess.SetUndoMark(Session.MarkVisibility.Visible, "Start")
        Dim nullFeatures_Feature As Features.Feature = Nothing
        If Not workPart.Preferences.Modeling.GetHistoryMode Then
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free
Mode."))
        End If
        Dim OffsetCurveBuilder1 As Features.OffsetCurveBuilder
        OffsetCurveBuilder1 = workPart.Features.CreateOffsetCurveBuilder(nullFeatures_Feature)

        OffsetCurveBuilder1.Tolerance = 0.0254
        OffsetCurveBuilder1.OffsetDistance.RightHandSide = "10"
        OffsetCurveBuilder1.DraftHeight.RightHandSide = "5"
        OffsetCurveBuilder1.DraftAngle.RightHandSide = "0"
        OffsetCurveBuilder1.LawControl.Value.RightHandSide = "5"
        OffsetCurveBuilder1.LawControl.StartValue.RightHandSide = "5"
        OffsetCurveBuilder1.LawControl.EndValue.RightHandSide = "5"
        OffsetCurveBuilder1.Offset3dDistance.RightHandSide = "5"
        OffsetCurveBuilder1.InputCurvesOptions.InputCurveOption = GeometricUtilities.CurveOptions.InputCurve.Retain
        OffsetCurveBuilder1.TrimMethod = Features.OffsetCurveBuilder.TrimOption.ExtendTangents
        OffsetCurveBuilder1.ExtendFactor = 12.0
        OffsetCurveBuilder1.LawControl.AlongSpineData.SetFeatureSpine(OffsetCurveBuilder1.CurvesToOffset)
        
        OffsetCurveBuilder1.CurvesToOffset.DistanceTolerance = 0.0254
        OffsetCurveBuilder1.CurvesToOffset.ChainingTolerance = 0.02413
        OffsetCurveBuilder1.LawControl.AlongSpineData.Spine.DistanceTolerance = 0.0254
        OffsetCurveBuilder1.LawControl.AlongSpineData.Spine.ChainingTolerance = 0.02413
        OffsetCurveBuilder1.LawControl.LawCurve.DistanceTolerance = 0.0254
        OffsetCurveBuilder1.LawControl.LawCurve.ChainingTolerance = 0.02413
        OffsetCurveBuilder1.InputCurvesOptions.InputCurveOption = GeometricUtilities.CurveOptions.InputCurve.Retain
        OffsetCurveBuilder1.InputCurvesOptions.Associative = False
        OffsetCurveBuilder1.NumberOfCopies = 1
        
        Dim markId2 As Session.UndoMarkId
        markId2 = Sess.SetUndoMark(Session.MarkVisibility.Visible, "section mark")

        Dim markId3 As Session.UndoMarkId
        markId3 = Sess.SetUndoMark(Session.MarkVisibility.Visible, Nothing)

        Dim curveDumbRule1 As CurveDumbRule
        curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(InputCurve)
        OffsetCurveBuilder1.CurvesToOffset.AllowSelfIntersection(False)

        Dim rules1(0) As SelectionIntentRule
        rules1(0) = curveDumbRule1
        Dim nullNXObject As NXObject = Nothing

        Dim helpPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        OffsetCurveBuilder1.CurvesToOffset.AddToSection(rules1, nullNXObject, nullNXObject, nullNXObject, helpPoint1,
NXOpen.Section.Mode.Create, True)
        Sess.DeleteUndoMark(markId3, Nothing)

        Dim markId4 As Session.UndoMarkId
        markId4 = Sess.SetUndoMark(Session.MarkVisibility.Invisible, "Update Law Data")
        Sess.DeleteUndoMarksUpToMark(markId4, "Update Law Data", False)
        Sess.DeleteUndoMark(markId2, Nothing)

        Dim markId5 As Session.UndoMarkId
        markId5 = Sess.SetUndoMark(Session.MarkVisibility.Invisible, "Offset Curve")
        Dim nXObject1 As NXObject
        nXObject1 = OffsetCurveBuilder1.Commit

        Dim objects1() As NXObject
        objects1 = OffsetCurveBuilder1.GetCommittedObjects()
        Sess.DeleteUndoMark(markId5, Nothing)
        Sess.SetUndoMarkName(markId1, "Offset Curve")

    End Sub
作者: lgmsddy    时间: 2009-10-23 07:59
我来顶一下…………
作者: 有偿帮助    时间: 2009-10-24 15:00
应该有个参数设置是否保留原有曲线的 找找
作者: begtostudy    时间: 2009-10-29 13:59
NXOpen的朋友,不错

可不可以先拷贝曲线
作者: zhangcanwei    时间: 2009-10-29 17:05
是啊,我就是这样做的,不过不应该这样啊。
作者: zhangcanwei    时间: 2009-10-29 17:10
begtostudy 发表于 2009-10-29 13:59
NXOpen的朋友,不错

可不可以先拷贝曲线


高手啊,我关注你的博客已经很久了
作者: begtostudy    时间: 2009-10-29 17:26
zhangcanwei 发表于 2009-10-29 17:10


高手啊,我关注你的博客已经很久了


真是惭愧,其实UG二次开发我也是外行,没发过几个帖子
而且还没有实际的工程经验,凭空瞎想的……




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