基本信息
源码名称:UG二次开发中nxopen测量距离
源码大小:0.03M
文件格式:.rar
开发语言:C#
更新时间:2019-06-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
在UG二次开发中用NXOPEN测量距离的例子很难找到,在上传一个供大家砸砖


using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;


public class Program
{
    // class members
    private static Session theSession;
    private static UI theUI;
    private static UFSession theUfSession;
    public static Program theProgram;
    public static bool isDisposeCalled;

    public static double ada,adb;
    static TaggedObject body1, body2;

    static Point3d point1, point2;
    public static Part workpart = null;
    public static ListingWindow lw = null;
    bool dir;
    //------------------------------------------------------------------------------
    // Constructor
    //------------------------------------------------------------------------------
    public Program()
    {
        try
        {
            theSession = Session.GetSession();
            theUI = UI.GetUI();
            theUfSession = UFSession.GetUFSession();
            lw = theSession.ListingWindow;
            workpart = theSession.Parts.Work;
            isDisposeCalled = false;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----
            // UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }
    }

    //------------------------------------------------------------------------------
    //  Explicit Activation
    //      This entry point is used to activate the application explicitly
    //------------------------------------------------------------------------------
    public  static int Main(string[] args)
    {
        int retValue = 0;
        try
        {
            theProgram = new Program();
            int ii, jj; ii = 2; jj = 3;
            string[] sta = { "保持当前Z轴", "Z轴反向", "3" }; jj=theUfSession.Ui.DisplayMenu("确认坐标系", 1, sta, 2);
            lw.Open();lw.WriteLine(jj.ToString());
            int face_1 = 1;double re;
            int face_2 = 5;
            int c;Point3d pt1, pt2;
            fun k = new fun();
            k.theSession = theSession;k.workPart = workpart;k.theUI = theUI;k.theUfSession = theUfSession;

            theUI.SelectionManager.SelectTaggedObject("选择实体", "选择", Selection.SelectionScope.WorkPart, false, false, out body1, out point1);
            theUI.SelectionManager.SelectTaggedObject("选择实体", "选择", Selection.SelectionScope.WorkPart, false, false, out body2, out point2);
            //     Measurement.GetMinimumDistance((NXObject)body1, (NXObject)body2, out point1, out point2, out ccs);



            re=k.measu_dist(body1, body2, out c, out pt1, out pt2);


      
            

            lw.Open(); lw.WriteLine(re.ToString());
           

            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
        return retValue;
    }

    //------------------------------------------------------------------------------
    // Following method disposes all the class members
    //------------------------------------------------------------------------------
    public void Dispose()
    {
        try
        {
            if (isDisposeCalled == false)
            {
                //TODO: Add your application code here 
            }
            isDisposeCalled = true;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
    }

    public static int GetUnloadOption(string arg)
    {
        //Unloads the image explicitly, via an unload dialog
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);

        //Unloads the image immediately after execution within NX
         return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

        //Unloads the image when the NX session terminates
       // return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
    }

}