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;
}
}
다음검색