概述
public int apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
TaggedObject[] curves = edge_select0.GetSelectedObjects();
NXOpen.TaggedObject[] pointsObjects = point0.GetSelectedObjects();
NXOpen.Point point = null;
if (curves.Length <= 1 && pointsObjects.Length > 0)
{
point = (NXOpen.Point)pointsObjects[0];
}
double distance = double0.Value;
//bool i = toggle0.Value;
//double x1 = point0.Point.X;
//double y1 = point0.Point.Y;
//double z1 = point0.Point.Z;
OffsetCurve(curves, point,toggle0.Value);
// ----------------------------------------------
}
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.Point pointOnOffsetPlane = null)
{
//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);
if (pointOnOffsetPlane != null)
{
offsetCurveBuilder1.PointOnOffsetPlane = pointOnOffsetPlane;
}
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
// ----------------------------------------------
}
public void OffsetCurve(NXOpen.TaggedObject[] curves1,NXOpen.Point point1,bool isRetain =true)
{
//NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
if (!workPart.Preferences.Modeling.GetHistoryMode())
{
throw new 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.01;
offsetCurveBuilder1.CurveFitData.AngleTolerance = 0.5;
offsetCurveBuilder1.OffsetDistance.RightHandSide = "20";
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";
if (isRetain)
{
offsetCurveBuilder1.InputCurvesOptions.Associative = true;
offsetCurveBuilder1.InputCurvesOptions.InputCurveOption = NXOpen.GeometricUtilities.CurveOptions.InputCurve.Retain;
}
else
{
offsetCurveBuilder1.InputCurvesOptions.Associative = false;
offsetCurveBuilder1.InputCurvesOptions.InputCurveOption = NXOpen.GeometricUtilities.CurveOptions.InputCurve.Delete;
}
offsetCurveBuilder1.TrimMethod = NXOpen.Features.OffsetCurveBuilder.TrimOption.ExtendTangents;
offsetCurveBuilder1.LawControl.AlongSpineData.SetFeatureSpine(offsetCurveBuilder1.CurvesToOffset);
offsetCurveBuilder1.CurvesToOffset.DistanceTolerance = 0.01;
offsetCurveBuilder1.CurvesToOffset.ChainingTolerance = 0.0095;
offsetCurveBuilder1.LawControl.AlongSpineData.Spine.DistanceTolerance = 0.01;
offsetCurveBuilder1.LawControl.AlongSpineData.Spine.ChainingTolerance = 0.0095;
offsetCurveBuilder1.LawControl.LawCurve.DistanceTolerance = 0.01;
offsetCurveBuilder1.LawControl.LawCurve.ChainingTolerance = 0.0095;
offsetCurveBuilder1.CurvesToOffset.AngleTolerance = 0.5;
offsetCurveBuilder1.LawControl.AlongSpineData.Spine.AngleTolerance = 0.5;
offsetCurveBuilder1.LawControl.LawCurve.AngleTolerance = 0.5;
NXOpen.Vector3d offsetdirection1;
NXOpen.Point3d startpoint1;
try
{
// 轮廓不能为“空”
offsetCurveBuilder1.ComputeOffsetDirection(out offsetdirection1, out startpoint1);
}
catch (NXException ex)
{
ex.AssertErrorCode(671415);
}
offsetCurveBuilder1.CurvesToOffset.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
offsetCurveBuilder1.CurvesToOffset.AllowSelfIntersection(true);
//添加曲线
//NXOpen.Features.Feature[] features1 = new NXOpen.Features.Feature[1];
//NXOpen.Features.AssociativeLine associativeLine1 = (NXOpen.Features.AssociativeLine)workPart.Features.FindObject("LINE(1)");
//features1[0] = associativeLine1;
//NXOpen.CurveFeatureRule curveFeatureRule1;
//curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);
//NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
//rules1[0] = curveFeatureRule1;
//NXOpen.Line line1 = (NXOpen.Line)associativeLine1.FindObject("CURVE 1");
//NXOpen.NXObject nullNXOpen_NXObject = null;
//NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(-4.44089209850063e-015, 32.1109564740434, -1.77635683940025e-015);
//offsetCurveBuilder1.CurvesToOffset.AddToSection(rules1, line1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
List<NXOpen.SelectionIntentRule> selectionIntentRules = new List<NXOpen.SelectionIntentRule>();
NXOpen.ICurve 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.Edge)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.Curve)curve;
}
}
Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
offsetCurveBuilder1.CurvesToOffset.AddToSection(selectionIntentRules.ToArray(), (NXOpen.NXObject)seed, null, null, helpPoint1, NXOpen.Section.Mode.Create, false);
NXOpen.Point3d seedpoint1 = new NXOpen.Point3d(-4.44089209850063e-015, 32.1109564740434, -1.77635683940025e-015);
NXOpen.Vector3d offsetdirection2;
NXOpen.Point3d startpoint2;
try
{
// 输入的曲线构成一直线,无法确定偏置平面。
offsetCurveBuilder1.ComputeOffsetDirection(seed, seedpoint1, out offsetdirection2, out startpoint2);
}
catch (NXException ex)
{
ex.AssertErrorCode(1395069);
}
if (point1 != null)
{
// point1.RemoveViewDependency();
offsetCurveBuilder1.PointOnOffsetPlane = point1;
}
NXOpen.Point3d seedpoint2 = new NXOpen.Point3d(-4.44089209850063e-015, 32.1109564740434, -1.77635683940025e-015);
NXOpen.Vector3d offsetdirection3;
NXOpen.Point3d startpoint3;
try
{
// 输入的曲线构成一直线,无法确定偏置平面。
offsetCurveBuilder1.ComputeOffsetDirection(seed, seedpoint2, out offsetdirection3, out startpoint3);
}
catch (NXException ex)
{
ex.AssertErrorCode(1395069);
}
NXOpen.NXObject nXObject1 = offsetCurveBuilder1.Commit();
NXOpen.NXObject[] objects1 = offsetCurveBuilder1.GetCommittedObjects();
offsetCurveBuilder1.Destroy();
}
最后
以上就是丰富冷风为你收集整理的选择单条曲线偏置选择参考点的全部内容,希望文章能够帮你解决选择单条曲线偏置选择参考点所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复