一个会的不多的人

一个会的不多的人

大家好,今天继续讲我们的通用方法分享系列。

下面开始今天的通用方法分享:

(1)这个通用方法为切换制图模块

    /// <summary>

    /// 切换到制图模块

    /// </summary>

    public void DrawingModule()

    {

        //切换到制图模块

        int s = 0;

        theUfSession.UF.AskApplicationModule(out s);

        if (s != 1)

        {

            theSession.ApplicationSwitchImmediate("UG_APP_DRAFTING");

        }

        //切换到制图模块

}

(2)这个通用方法为SW创建新零件:

        /// <summary>

        /// 创建新零件

        /// </summary>

        /// <param name="swAss"></param>

        /// <returns></returns>

        public static Component2 CreateNewPart(AssemblyDoc swAss,string filePath)

        {

            Component2 swcomp2 = null;

            int longstatus1 = 0;

            object swFaceOrPlane1 = null;

            longstatus1 = swAss.InsertNewVirtualPart(swFaceOrPlane1, out swcomp2);

            if (swcomp2 == null)

            {

                 MessageBox.Show("未能创建虚拟零件!!!", "提示:");

            }

            else

            {

                swcomp2.Name2 = "example";

            }

            return swcomp2;

        }

(3)这个通用方法为获得两点之间的距离

        /// <summary>

        /// 获取两点之间的距离

        /// </summary>

        /// <param name="startPoint"></param>

        /// <param name="endPoint"></param>

        /// <returns></returns>

        public static double GetDistance(double[] startPoint, double[] endPoint)

        {

            double distance = 0.0;

            if (startPoint.Length == 3 && endPoint.Length == 3)

            {

                double dx = (endPoint[0] - startPoint[0])*1000;

                double dy = (endPoint[1] - startPoint[1]) * 1000;

                double dz = (endPoint[2] - startPoint[2]) * 1000;

                distance = Math.Sqrt(dx * dx + dy * dy + dz * dz);

            }

            distance = distance / 1000;

            return distance;

        }

今天要介绍的就是这么多,我们下篇文章再见。

07-28 16:40