我是靠谱客的博主 机灵雨,最近开发中收集的这篇文章主要介绍创建双边偏置曲线(通过TOGGLE控件来控制是否保留原来的曲线),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 public int apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
NXOpen.TaggedObject[] curves = edge_select0.GetSelectedObjects();
double distance = double0.Value;
bool i = toggle0.Value;
CreateOffset(curves,distance,i);
CreateOffset(curves,-distance, i);
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return errorCode;
}
private void CreateOffset(NXOpen.TaggedObject[] curves1, double distance, bool i)
{
//NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
// ----------------------------------------------
//
菜单:镶块->Curve from Curves->Offset...
// ----------------------------------------------
//Arc arc1 = (Arc)workPart.Arcs.FindObject("ENTITY 5 1 1");
//Curve[] curves1 = new Curve[1] { arc1 };
NXOpen.Session.UndoMarkId markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
theSession.SetUndoMarkName(markId1, "Offset Curve 对话框");
if (!workPart.Preferences.Modeling.GetHistoryMode())
{
throw new System.Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
}
NXOpen.Features.OffsetCurveBuilder offsetCurveBuilder1 = workPart.Features.CreateOffsetCurveBuilder(null);
offsetCurveBuilder1.CurveFitData.Tolerance = 0.0254;
offsetCurveBuilder1.InputCurvesOptions.InputCurveOption = NXOpen.GeometricUtilities.CurveOptions.InputCurve.Retain;
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;
Vector3d offsetdirection1;
Point3d startpoint1;
try
{
// 轮廓不能为“空”
offsetCurveBuilder1.ComputeOffsetDirection(out offsetdirection1, out startpoint1);
}
catch (NXException ex)
{
ex.AssertErrorCode(671415);
}
offsetCurveBuilder1.CurvesToOffset.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
NXOpen.Session.UndoMarkId markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
NXOpen.Session.UndoMarkId markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
offsetCurveBuilder1.CurvesToOffset.AllowSelfIntersection(true);
List<NXOpen.SelectionIntentRule> selectionIntentRules = new List<NXOpen.SelectionIntentRule>();
NXOpen.NXObject seed = null;
foreach (NXOpen.TaggedObject curve in curves1)
{
if (curve is NXOpen.Edge)
{
NXOpen.EdgeDumbRule edgeDumbRule =
workPart.ScRuleFactory.CreateRuleEdgeDumb(new NXOpen.Edge[1] {(NXOpen.Edge) curve});
selectionIntentRules.Add(edgeDumbRule);
seed = (NXOpen.NXObject) curve;
}
else if (curve is NXOpen.Curve)
{
NXOpen.CurveDumbRule curveDumbRule =
workPart.ScRuleFactory.CreateRuleCurveDumb(new NXOpen.Curve[1] { (NXOpen.Curve)curve });
selectionIntentRules.Add(curveDumbRule);
seed = (NXOpen.NXObject)curve;
}
}
Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
offsetCurveBuilder1.CurvesToOffset.AddToSection(selectionIntentRules.ToArray(), seed, null, null, helpPoint1, NXOpen.Section.Mode.Create, false);
theSession.DeleteUndoMark(markId3, null);
Vector3d offsetdirection2;
Point3d startpoint2;
offsetCurveBuilder1.ComputeOffsetDirection(out offsetdirection2, out startpoint2);
offsetCurveBuilder1.OffsetDistance.RightHandSide = distance.ToString("0.000");
theSession.DeleteUndoMark(markId2, null);
NXOpen.Session.UndoMarkId markId4;
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Offset Curve");
offsetCurveBuilder1.InputCurvesOptions.Associative = i;
if (!i)
{
offsetCurveBuilder1.InputCurvesOptions.InputCurveOption = NXOpen.GeometricUtilities.CurveOptions.InputCurve.Delete;
}
else
{
offsetCurveBuilder1.InputCurvesOptions.InputCurveOption = NXOpen.GeometricUtilities.CurveOptions.InputCurve.Blank;
}
NXObject nXObject1 = offsetCurveBuilder1.Commit();
theSession.DeleteUndoMark(markId4, null);
theSession.SetUndoMarkName(markId1, "Offset Curve");
offsetCurveBuilder1.CurvesToOffset.CleanMappingData();
offsetCurveBuilder1.CurvesToOffset.CleanMappingData();
offsetCurveBuilder1.Destroy();
// ----------------------------------------------
//
菜单:刀具->操作记录->Stop Recording
// ----------------------------------------------
}

 

最后

以上就是机灵雨为你收集整理的创建双边偏置曲线(通过TOGGLE控件来控制是否保留原来的曲线)的全部内容,希望文章能够帮你解决创建双边偏置曲线(通过TOGGLE控件来控制是否保留原来的曲线)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部