UG NX二次开发(C#)-建模-拔模功能

Posted GimiGimmy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UG NX二次开发(C#)-建模-拔模功能相关的知识,希望对你有一定的参考价值。

概念

拔模通常用于对模型、部件、模具或冲模的竖直面添加斜度,以便借助拔模面将部件或模型与其模具或冲模分开。拔模,铸造时为了从砂中取出木模而不破坏砂型,往往零件毛胚设计带有上大下小的锥度,叫拔模斜度。拔模斜度有三种形式:增加厚度法,加减厚度法,减小厚度法。
拔模是对模具或铸件的面做锥度调整。一个用于成型或铸造的零件必须被正确设计和适当拔模,以便取出模具。拔模角被应用在一个扩展分型线相反的方向。
拔模就是为了保证模具在生产产品的过程中产品能顺利脱模,我们设计模具的时候有时就没有设置拔模度,而是用我们手工抛光时候自然形成的斜度(很小)这样也能保证脱模的。其实对于高精度零件,只要你模具型腔和型芯表面粗糙度小(用抛光或工艺磨床),不用拔模也能顺利脱模的。当然顶杆设计也要合理。

拔模的方法

在录制的代码中,我们可以筛选出有用的切必要的代码,将这些代码作为一个方法来使用。

  /// <summary>
        /// 创建拔模特征
        /// </summary>
        /// <param name="vector3D">拔模方向</param>
        /// <param name="edge">固定边</param>
        /// <param name="angle">拔模角度</param>
        /// <param name="feature">生成的拔模特征</param>
        public static void CreateDraft(Vector3d vector3D, Edge edge, double angle, out NXOpen.Features.Feature feature)
        

            NXOpen.Session.UndoMarkId markId1;
            markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "起点");

            NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
            NXOpen.Features.DraftBuilder draftBuilder1;
            draftBuilder1 = workPart.Features.CreateDraftBuilder(nullNXOpen_Features_Feature);

            NXOpen.Unit unit1 = ((NXOpen.Unit)workPart.UnitCollection.FindObject("MilliMeter"));
            NXOpen.Expression expression1;
            expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

            draftBuilder1.DistanceTolerance = 0.001;

            draftBuilder1.AngleTolerance = 0.050000000000000003;

            draftBuilder1.AngleTolerance = 0.050000000000000003;

            draftBuilder1.DistanceTolerance = 0.001;

            draftBuilder1.DraftIsoclineOrTruedraft = NXOpen.Features.DraftBuilder.Method.Isocline;

            NXOpen.GeometricUtilities.DraftVariableAngleData draftVariableAngleData1;
            draftVariableAngleData1 = draftBuilder1.VariableAngleData;

            NXOpen.GeometricUtilities.DraftPointData[] points1;
            points1 = draftVariableAngleData1.GetDraftPoints();

            theSession.SetUndoMarkName(markId1, "拔模 对话框");

            NXOpen.Expression expression2;
            expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

            draftBuilder1.TypeOfDraft = NXOpen.Features.DraftBuilder.Type.Edge;

            draftBuilder1.TwoDimensionFaceSetsData.Clear(NXOpen.ObjectList.DeleteOption.Delete);

            draftBuilder1.FaceSetAngleExpressionList.Clear(NXOpen.ObjectList.DeleteOption.Delete);

            draftBuilder1.EdgeSetAngleExpressionList.Clear(NXOpen.ObjectList.DeleteOption.Delete);

            NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            NXOpen.Vector3d vector1 = new NXOpen.Vector3d(1.0, 0.0, 0.0);
            NXOpen.Direction direction1;
            direction1 = workPart.Directions.CreateDirection(origin1, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling);

            draftBuilder1.Direction = direction1;

            NXOpen.ScCollector nullNXOpen_ScCollector = null;
            NXOpen.ExpressionCollectorSet expressionCollectorSet1;
            expressionCollectorSet1 = workPart.CreateExpressionCollectorSet(nullNXOpen_ScCollector, angle.ToString(), "角度", 0);

            draftBuilder1.EdgeSetAngleExpressionList.Append(expressionCollectorSet1);

            NXOpen.ScCollector scCollector1;
            scCollector1 = workPart.ScCollectors.CreateCollector();

            NXOpen.SelectionIntentRuleOptions selectionIntentRuleOptions1;
            selectionIntentRuleOptions1 = workPart.ScRuleFactory.CreateRuleOptions();

            selectionIntentRuleOptions1.SetSelectedFromInactive(false);

            NXOpen.Edge edge1 = edge;
            NXOpen.Edge nullNXOpen_Edge = null;
            NXOpen.EdgeTangentRule edgeTangentRule1;
            edgeTangentRule1 = workPart.ScRuleFactory.CreateRuleEdgeTangent(edge1, nullNXOpen_Edge, true, 0.050000000000000003, false, false, selectionIntentRuleOptions1);

            selectionIntentRuleOptions1.Dispose();
            NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
            rules1[0] = edgeTangentRule1;
            scCollector1.ReplaceRules(rules1, false);

            expressionCollectorSet1.Collector = scCollector1;

            NXOpen.Session.UndoMarkId markId2;
            markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "拔模");

            theSession.DeleteUndoMark(markId2, null);

            NXOpen.Session.UndoMarkId markId3;
            markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "拔模");

           
            feature = draftBuilder1.CommitFeature();

            theSession.DeleteUndoMark(markId3, null);

            theSession.SetUndoMarkName(markId1, "拔模");

            NXOpen.Expression expression3 = expressionCollectorSet1.ItemValue;
            draftBuilder1.Destroy();

            workPart.MeasureManager.SetPartTransientModification();

            workPart.Expressions.Delete(expression1);

            workPart.MeasureManager.ClearPartTransientModification();

            workPart.MeasureManager.SetPartTransientModification();

            workPart.Expressions.Delete(expression2);

            workPart.MeasureManager.ClearPartTransientModification();

            theSession.CleanUpFacetedFacesAndEdges();
        

方法调用

编写一段调用代码,如下:

 Vector3d vector3D = _VectorSelect.Vector;
                    Edge edge = (Edge)_EdgeSelect.GetSelectedObjects()[0];
                    double angle = 20;
                    Feature feature;
                    CreateDraft(vector3D,edge,angle,out feature);

创建效果

采用二次开发的拔模效果如下图所示。

以上是关于UG NX二次开发(C#)-建模-拔模功能的主要内容,如果未能解决你的问题,请参考以下文章

UG NX二次开发(C#)-建模-分割曲线

UG NX二次开发(C#)-建模-分割曲线

UG NX二次开发(C#)-建模-删除面

UG NX二次开发(C#)-建模-创建填充曲面(CreateFillHoleBuilder)

UG NX二次开发(C#)-建模-获得NX当前打开的所有part文件

UG NX二次开发(C#)-同步建模-删除倒圆(圆角)