CAFE

Java

Sample NX Open Java program : select a feature

작성자k2ice|작성시간08.05.22|조회수493 목록 댓글 0
Date:  5-MAY-2008
Subject:  Sample NX Open Java program : select a feature

Note:  GTAC provides programming examples for illustration only, and
assumes that you are familiar with the programming language being
demonstrated and the tools used to create and debug procedures.  GTAC
support professionals can help explain the functionality of a particular
procedure, but we will not modify these examples to provide added
functionality or construct procedures to meet your specific needs.

import nxopen.*;
import nxopen.uf.*;
import nxopen.features.*;
import java.rmi.RemoteException;
import java.io.PrintWriter;
import java.io.StringWriter;


public class select_a_feature 
{
		
	public static void main(String[] args) throws NXException, Exception
    {
		Session s = null ;
		UFSession ufs = null ;
		ListingWindow lw = null;
		Selection.SelectFeaturesData selObj = null;

		try
        {
			s = (Session)SessionFactory.get("Session");
            ufs = (UFSession)SessionFactory.get("UFSession");
            lw = s.listingWindow();
           	if (!lw.isOpen()) lw.open();

            selObj = select_a_feature();
            while( selObj != null )
            {
            	Feature feat = selObj.featureArray[0];
           		lw.writeLine( "Feature " + feat.tag().value + " is from type " + feat.featureType());
	            selObj = select_a_feature();
           	}
           		
        }
        catch (NXException ex)
        {
            if (!lw.isOpen()) lw.open();
            lw.writeLine("Error code: " + ex.errorCode());
            lw.writeLine("Error text: " +
                ufs.UF().getFailMessage(ex.errorCode()));
        }
        catch (Exception ex)
        {
            if(ufs != null)
			{
				StringWriter sw = new StringWriter();
				PrintWriter pw = new PrintWriter(sw);
				pw.println("Caught exception " + ex );
				ex.printStackTrace(pw);
				lw.writeLine("\nFailed");
				lw.writeLine("\n"+ex.getMessage());
				lw.writeLine("\n"+sw.getBuffer().toString());
			}
		
        
		}
    }
   
    public static Selection.SelectFeaturesData select_a_feature() throws NXException, RemoteException
    {
		UI theUI = (UI)SessionFactory.get("UI");
		Selection.MaskTriple mask[] = { new Selection.MaskTriple(UFConstants.UF_feature_type, UFConstants.UF_feature_subtype, 0) };
		
		Selection.SelectFeaturesData selFeats = 
			theUI.selectionManager().selectFeatures("Select a Feature", Selection.SelectionFeatureType.BROWSABLE );

		if ( selFeats.response == Selection.Response.OBJECT_SELECTED ||
				selFeats.response == Selection.Response.OK )
		{
			return selFeats;
		}
		else
			return null;
    }
    
	public static int getUnloadOption() 
	{ 
		return BaseSession.LibraryUnloadOption.IMMEDIATELY; 
	}
}
다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼