Esempio n. 1
0
        /// <summary>
        /// 设置平面铣边界(以绝对点)
        /// </summary>
        /// <param name="toolside">刀具侧</param>
        /// <param name="types"></param>
        /// <param name="pt">封闭还是开放</param>
        /// <param name="boundary">边界</param>
        /// <param name="edges">边</param>
        public static BoundarySetPlanarMill CreateBoundaryPlanarMill(BoundarySet.ToolSideTypes toolside, BoundarySet.BoundaryTypes types,
                                                                     Point3d pt, Boundary boundary, params NXObject[] edges)
        {
            if (boundary == null)
            {
                throw new Exception("输入边界为空!");
            }
            if (edges.Length == 0)
            {
                throw new Exception("输入边为空!");
            }
            Matrix4 mat = new Matrix4();

            mat.Identity();
            Part workPart = Session.GetSession().Parts.Work;
            BoundarySetPlanarMill boundarySetPlanarMill;

            boundarySetPlanarMill = boundary.CreateBoundarySetPlanarMill();
            Vector3d normal = new NXOpen.Vector3d(0.0, 0.0, 1.0);
            Plane    plane  = workPart.Planes.CreatePlane(pt, normal, NXOpen.SmartObject.UpdateOption.AfterModeling);

            boundarySetPlanarMill.ToolSide = toolside;
            boundarySetPlanarMill.AppendCurves(edges, pt, mat.GetMatrix3());
            boundarySetPlanarMill.BoundaryType = types;
            boundarySetPlanarMill.Plane        = plane;
            boundarySetPlanarMill.PlaneType    = NXOpen.CAM.BoundarySet.PlaneTypes.UserDefined;
            return(boundarySetPlanarMill);
        }
Esempio n. 2
0
        /// <summary>
        /// 设置边界
        /// </summary>
        /// <param name="floorPt"></param>
        /// <param name="conditions"></param>
        public void SetBoundary(Point3d floorPt, params BoundaryModel[] conditions)
        {
            NXOpen.CAM.PlanarMillingBuilder planarMillingBuilder1;
            planarMillingBuilder1 = workPart.CAMSetup.CAMOperationCollection.CreatePlanarMillingBuilder(this.Oper);
            planarMillingBuilder1.FeedsBuilder.SetMachiningData();
            BoundaryPlanarMill           boundary    = planarMillingBuilder1.PartBoundary;
            BoundarySetList              list        = boundary.BoundaryList;
            List <BoundarySetPlanarMill> boundarySet = new List <BoundarySetPlanarMill>();

            foreach (BoundaryModel bc in conditions)
            {
                boundarySet.Add(OperationUtils.CreateBoundaryPlanarMill(bc.ToolSide, bc.Types,
                                                                        bc.BouudaryPt, boundary, bc.Edges.ToArray()));
            }
            list.Append(boundarySet.ToArray());

            Vector3d normal = new NXOpen.Vector3d(0.0, 0.0, 1.0);
            Plane    plane  = workPart.Planes.CreatePlane(floorPt, normal, NXOpen.SmartObject.UpdateOption.AfterModeling);

            planarMillingBuilder1.Geometry.FloorPlane = plane;
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = planarMillingBuilder1.Commit();
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("PlanarMillingModel.SetBoundary 错误" + ex.Message);
            }
            finally
            {
                planarMillingBuilder1.Destroy();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 移动部件并复制部件
        /// </summary>
        /// <param name="compObj"></param>
        /// <param name="endPt"></param>
        /// <param name="mat"></param>
        /// <returns></returns>
        public static NXOpen.Assemblies.Component MoveCompCopyPart(NXOpen.Assemblies.Component compObj, Vector3d endPt, Matrix4 mat)
        {
            Part workPart = theSession.Parts.Work;

            Matrix4 invers = mat.GetInversMatrix();

            invers.ApplyVec(ref endPt);

            NXOpen.Positioning.ComponentPositioner componentPositioner1;
            componentPositioner1 = workPart.ComponentAssembly.Positioner;                                                                                    //组件定位
            componentPositioner1.ClearNetwork();                                                                                                             //删除定位器
            NXOpen.Assemblies.Arrangement arrangement1 = (NXOpen.Assemblies.Arrangement)workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"); //布局
            componentPositioner1.PrimaryArrangement = arrangement1;                                                                                          //主要布局
            componentPositioner1.BeginMoveComponent();                                                                                                       //开始移动组件
            bool allowInterpartPositioning1;

            allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning;                       //首选项的部件间的定位
            NXOpen.Positioning.Network network1;
            network1 = componentPositioner1.EstablishNetwork();                                                        //建立
            NXOpen.Positioning.ComponentNetwork componentNetwork1 = (NXOpen.Positioning.ComponentNetwork)network1;
            componentNetwork1.MoveObjectsState = true;                                                                 //移动对象状态
            NXOpen.Assemblies.Component nullNXOpen_Assemblies_Component = null;
            componentNetwork1.DisplayComponent        = nullNXOpen_Assemblies_Component;                               //显示组件
            componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing; //现有安排模式
            componentNetwork1.RemoveAllConstraints();                                                                  //删除约束
            NXOpen.NXObject[] movableObjects1 = new NXOpen.NXObject[1];
            movableObjects1[0] = compObj;
            NXOpen.Assemblies.Component[] components1 = new NXOpen.Assemblies.Component[1];
            components1[0] = compObj;
            NXOpen.Assemblies.Component[] newComponents1 = workPart.ComponentAssembly.CopyComponents(components1);

            componentNetwork1.SetMovingGroup(newComponents1); //设置移动组件
            componentNetwork1.Solve();                        //解除约束
            bool loaded1;

            loaded1 = componentNetwork1.IsReferencedGeometryLoaded(); //参考几何加载
            componentNetwork1.BeginDrag();                            //操作即将开始

            NXOpen.Vector3d translation1 = new NXOpen.Vector3d(endPt.X, endPt.Y, endPt.Z);
            componentNetwork1.DragByTranslation(translation1); //移动
            componentNetwork1.EndDrag();                       //操作结束
            componentNetwork1.ResetDisplay();                  //返回到模型上
            componentNetwork1.ApplyToModel();                  //应该到当前模型
            componentNetwork1.Solve();                         //解除约束
            componentPositioner1.ClearNetwork();               //清空
            int nErrs1;

            nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1); //更新

            componentPositioner1.ClearNetwork();
            componentPositioner1.DeleteNonPersistentConstraints();
            componentPositioner1.EndMoveComponent();

            NXOpen.Assemblies.Arrangement nullNXOpen_Assemblies_Arrangement = null;
            componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement;
            return(newComponents1[0]);
        }
Esempio n. 4
0
        /// <summary>
        /// 矢量差乘
        /// </summary>
        /// <param name="vec1">矢量1</param>
        /// <param name="vec2">矢量2</param>
        /// <returns>差乘矢量</returns>
        public static NXOpen.Vector3d VectorCross(NXOpen.Vector3d vec1, NXOpen.Vector3d vec2)
        {
            NXOpen.UF.UFSession ufSession = NXOpen.UF.UFSession.GetUFSession();
            double[]            x         = { vec1.X, vec1.Y, vec1.Z };
            double[]            y         = { vec2.X, vec2.Y, vec2.Z };
            double[]            z         = new double[3];
            ufSession.Vec3.Cross(x, y, z);
            NXOpen.Vector3d zVec = new NXOpen.Vector3d(z[0], z[1], z[2]);

            return(zVec);
        }
Esempio n. 5
0
        /// <summary>
        ///正交
        /// </summary>
        /// <param name="vec"></param>
        /// <returns></returns>
        public static Vector3d GetNorm(NXOpen.Vector3d vec)
        {
            double dis = Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);

            Vector3d res = new Vector3d();

            res.X = vec.X / dis;
            res.Y = vec.Y / dis;
            res.Z = vec.Z / dis;

            return(res);
        }
Esempio n. 6
0
 /// <summary>
 /// 矢量相减
 /// </summary>
 /// <param name="vec1"></param>
 /// <param name="vec2"></param>
 /// <param name="resVec"></param>
 public static void VectorSubstract(NXOpen.Vector3d vec1, NXOpen.Vector3d vec2, ref NXOpen.Vector3d resVec)
 {
     resVec.X = vec1.X - vec2.X;
     resVec.Y = vec1.Y - vec2.Y;
     resVec.Z = vec1.Z - vec2.Z;
 }
Esempio n. 7
0
 /// <summary>
 /// 矢量点乘
 /// </summary>
 /// <param name="vec1">矢量1</param>
 /// <param name="vec2">矢量2</param>
 /// <returns></returns>
 public static double VectorDot(NXOpen.Vector3d vec1, NXOpen.Vector3d vec2)
 {
     return(vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z);
 }
Esempio n. 8
0
    public void CreateBracket(double thickness, double length, double height, double holeradius, double holedistance)
    {
        NXOpen.Point3d point1 = new NXOpen.Point3d(0, 0, 0);
        NXOpen.Point3d point2 = new NXOpen.Point3d(0, 0, height);
        NXOpen.Point3d point3 = new NXOpen.Point3d(0, thickness, height);
        NXOpen.Point3d point4 = new NXOpen.Point3d(0, thickness, thickness);
        NXOpen.Point3d point5 = new NXOpen.Point3d(0, length, thickness);
        NXOpen.Point3d point6 = new NXOpen.Point3d(0, length, 0);

        IBaseCurve[] curves1 = new IBaseCurve[6]
        {
            workPart.Curves.CreateLine(point1, point2),
            workPart.Curves.CreateLine(point2, point3),
            workPart.Curves.CreateLine(point3, point4),
            workPart.Curves.CreateLine(point4, point5),
            workPart.Curves.CreateLine(point5, point6),
            workPart.Curves.CreateLine(point6, point1)
        };

        CreateExtrude(curves1, true, 52.0, new Vector3d(1.0, 0, 0));

        //Left Line
        NXOpen.Point3d point7 = new NXOpen.Point3d(-21.0, 0, height - 8.0);
        NXOpen.Point3d point8 = new NXOpen.Point3d(-21, 0, height - 16.0);
        //Right LIne
        NXOpen.Point3d point9  = new NXOpen.Point3d(-15, 0, height - 16.0);
        NXOpen.Point3d point10 = new NXOpen.Point3d(-15, 0, height - 8.0);
        //Top Arc
        NXOpen.Point3d  Center1 = new NXOpen.Point3d(-18, 0, height - 8.0);
        NXOpen.Vector3d dir1    = new NXOpen.Vector3d(-1.0, 0, 0);
        NXOpen.Vector3d dir2    = new NXOpen.Vector3d(0, 0, -1.0);
        //Bottom Arc
        NXOpen.Point3d Center2 = new NXOpen.Point3d(-18, 0, height - 16.0);

        IBaseCurve[] curves2 = new IBaseCurve[4]
        {
            workPart.Curves.CreateLine(point7, point8),
            workPart.Curves.CreateArc(Center2, dir1, dir2, 3.0, 0, Math.PI),
            workPart.Curves.CreateLine(point9, point10),
            workPart.Curves.CreateArc(Center1, dir1, dir2, 3.0, Math.PI, 2 * Math.PI)
        };

        //Right Side
        //Left Line
        NXOpen.Point3d point11 = new NXOpen.Point3d(21.0, 0, height - 8.0);
        NXOpen.Point3d point12 = new NXOpen.Point3d(21, 0, height - 16.0);
        //Right LIne
        NXOpen.Point3d point13 = new NXOpen.Point3d(15, 0, height - 16.0);
        NXOpen.Point3d point14 = new NXOpen.Point3d(15, 0, height - 8.0);
        //Top Arc
        NXOpen.Point3d Center3 = new NXOpen.Point3d(18, 0, height - 8.0);
        //Bottom Arc
        NXOpen.Point3d Center4 = new NXOpen.Point3d(18, 0, height - 16.0);

        IBaseCurve[] curves3 = new IBaseCurve[4]
        {
            workPart.Curves.CreateLine(point11, point12),
            workPart.Curves.CreateArc(Center4, dir1, dir2, 3.0, 0, Math.PI),
            workPart.Curves.CreateLine(point13, point14),
            workPart.Curves.CreateArc(Center3, dir1, dir2, 3.0, Math.PI, 2 * Math.PI)
        };

        CreateExtrude(curves2, false, 2.0 * thickness, new Vector3d(0, 1, 0));
        CreateExtrude(curves3, false, 2.0 * thickness, new Vector3d(0, 1, 0));

        //EdgeBlend Start
        NXOpen.Features.EdgeBlendBuilder edgeBlendBuilder1 = workPart.Features.CreateEdgeBlendBuilder(null);

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

        NXOpen.Edge[]           seedEdges1 = new NXOpen.Edge[2];
        NXOpen.Features.Extrude extrude1   = (NXOpen.Features.Extrude)workPart.Features.ToArray().OfType <NXOpen.Features.Extrude>().First();
        Edge[]         edges         = extrude1.GetBodies()[0].GetEdges();
        NXOpen.Point3d edgeendpoint1 = new NXOpen.Point3d(26, 0, height);
        NXOpen.Point3d edgeendpoint2 = new NXOpen.Point3d(26, thickness, height);
        NXOpen.Point3d edgeendpoint3 = new NXOpen.Point3d(-26, 0, height);
        NXOpen.Point3d edgeendpoint4 = new NXOpen.Point3d(-26, thickness, height);
        Edge           edge1         = null;
        Edge           edge2         = null;

        for (int i = 0; i < edges.Length; i++)
        {
            NXOpen.Point3d endpoint;
            NXOpen.Point3d endpoint2;
            edges[i].GetVertices(out endpoint, out endpoint2);

            if (Math.Abs(edgeendpoint1.X - endpoint.X) < .01 && Math.Abs(edgeendpoint1.Y - endpoint.Y) < .01 && Math.Abs(edgeendpoint1.Z - endpoint.Z) < .01 && Math.Abs(edgeendpoint2.X - endpoint2.X) < .01 && Math.Abs(edgeendpoint2.Y - endpoint2.Y) < .01 && Math.Abs(edgeendpoint2.Z - endpoint2.Z) < .01)
            {
                edge1 = edges[i];
            }
            else if (Math.Abs(edgeendpoint3.X - endpoint.X) < .01 && Math.Abs(edgeendpoint3.Y - endpoint.Y) < .01 && Math.Abs(edgeendpoint3.Z - endpoint.Z) < .01 && Math.Abs(edgeendpoint4.X - endpoint2.X) < .01 && Math.Abs(edgeendpoint4.Y - endpoint2.Y) < .01 && Math.Abs(edgeendpoint4.Z - endpoint2.Z) < .01)
            {
                edge2 = edges[i];
            }

            if (edge1 != null && edge2 != null)
            {
                break;
            }
        }

        seedEdges1[0] = edge1;
        seedEdges1[1] = edge2;

        NXOpen.EdgeMultipleSeedTangentRule edgeMultipleSeedTangentRule1;
        edgeMultipleSeedTangentRule1 = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(seedEdges1, 0.5, true);

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

        int csIndex1;

        csIndex1 = edgeBlendBuilder1.AddChainset(scCollector1, "8");

        edgeBlendBuilder1.CommitFeature();
        edgeBlendBuilder1.Destroy();

        //EdgeBlend End

        //Circle's Extrude
        NXOpen.Point3d  holecenter1 = new NXOpen.Point3d(holedistance / 2, 20, 10);
        NXOpen.Point3d  holecenter2 = new NXOpen.Point3d(-holedistance / 2, 20, 10);
        NXOpen.Vector3d dir3        = new NXOpen.Vector3d(0, -1.0, 0);
        NXOpen.Vector3d dir4        = new NXOpen.Vector3d(1, 0, 0);

        IBaseCurve[] hole1 = new IBaseCurve[1]
        {
            workPart.Curves.CreateArc(holecenter1, dir3, dir4, holeradius, 0, 2 * Math.PI),
        };

        IBaseCurve[] hole2 = new IBaseCurve[1]
        {
            workPart.Curves.CreateArc(holecenter2, dir3, dir4, holeradius, 0, 2 * Math.PI),
        };

        CreateExtrude(hole1, false, 2 * thickness, new Vector3d(0, 0, 1));
        CreateExtrude(hole2, false, 2 * thickness, new Vector3d(0, 0, 1));

        //Big Slot

        //Top Line
        NXOpen.Point3d slotpt1 = new NXOpen.Point3d(-6, 44, 0);
        NXOpen.Point3d slotpt2 = new NXOpen.Point3d(-6, length - 14.0, 0);
        //BOttom Line
        NXOpen.Point3d slotpt4 = new NXOpen.Point3d(6, 44, 0);
        NXOpen.Point3d slotpt3 = new NXOpen.Point3d(6, length - 14.0, 0);
        //Right Arc
        NXOpen.Point3d slotcenter1 = new NXOpen.Point3d(0, 44, 0);
        //Left Arc
        NXOpen.Point3d slotcenter2 = new NXOpen.Point3d(0, length - 14.0, 0);

        IBaseCurve[] slotcurve = new IBaseCurve[4]
        {
            workPart.Curves.CreateLine(slotpt1, slotpt2),
            workPart.Curves.CreateArc(slotcenter2, dir3, dir4, 6.0, Math.PI / 2, 3 * Math.PI / 2),
            workPart.Curves.CreateLine(slotpt3, slotpt4),
            workPart.Curves.CreateArc(slotcenter1, dir3, dir4, 6.0, -Math.PI / 2, Math.PI / 2)
        };

        CreateExtrude(slotcurve, false, 2 * thickness, new Vector3d(0, 0, 1));

        //Curvey Part

        //bottom Arc
        NXOpen.Point3d botarc = new NXOpen.Point3d(26, 44, 0);
        //bottom line
        NXOpen.Point3d botpt1 = new NXOpen.Point3d(14, 44, 0);
        NXOpen.Point3d botpt2 = new NXOpen.Point3d(14, length - 14.0, 0);
        //Big Arc
        NXOpen.Point3d sidearc = new NXOpen.Point3d(0, length - 14.0, 0);
        //Top Line
        NXOpen.Point3d toppt2 = new NXOpen.Point3d(-14, 44, 0);
        NXOpen.Point3d toppt1 = new NXOpen.Point3d(-14, length - 14.0, 0);
        //Right Arc
        NXOpen.Point3d toparc = new NXOpen.Point3d(-26, 44, 0);

        //OUtline
        NXOpen.Point3d out1 = new NXOpen.Point3d(-26, 32, 0);
        NXOpen.Point3d out2 = new NXOpen.Point3d(-28, 32, 0);
        NXOpen.Point3d out3 = new NXOpen.Point3d(-28, length + 10, 0);
        NXOpen.Point3d out4 = new NXOpen.Point3d(28, length + 10, 0);
        NXOpen.Point3d out5 = new NXOpen.Point3d(28, 32, 0);
        NXOpen.Point3d out6 = new NXOpen.Point3d(26, 32, 0);


        IBaseCurve[] bigcutcurve = new IBaseCurve[10]
        {
            workPart.Curves.CreateArc(botarc, dir3, dir4, 12, -Math.PI / 2, 0),
            workPart.Curves.CreateLine(botpt1, botpt2),
            workPart.Curves.CreateArc(sidearc, dir3, dir4, 14, Math.PI / 2, 3 * Math.PI / 2),
            workPart.Curves.CreateLine(toppt1, toppt2),
            workPart.Curves.CreateArc(toparc, dir3, dir4, 12, 0, Math.PI / 2),
            workPart.Curves.CreateLine(out1, out2),
            workPart.Curves.CreateLine(out2, out3),
            workPart.Curves.CreateLine(out3, out4),
            workPart.Curves.CreateLine(out4, out5),
            workPart.Curves.CreateLine(out5, out6)
        };

        CreateExtrude(bigcutcurve, false, 2 * thickness, new Vector3d(0, 0, 1));
    }