- 积分
- 10
- 注册时间
- 2007-10-5
- 仿真币
-
- 最后登录
- 1970-1-1
|
import nxopen.*;
import nxopen.uf.*;
import nxopen.features.Feature;
import java.rmi.RemoteException;
public class decrease_points_of_selected_non_associative_spline_by_one
{
static UFSession ufs = null;
static ListingWindow lw = null;
public static void main(String[] args) throws NXException, RemoteException
{
Session s = (Session)SessionFactory.get("Session");
ufs = (UFSession)SessionFactory.get("UFSession");
Part dispPart = s.parts().display();
Part workPart = s.parts().work();
lw = s.listingWindow();
Feature spline_feat = null;
Selection.SelectObjectData spline = null;
while( (spline=select_a_spline()) != null )
{
// Report the spline points
lw.writeLine("\nSpline data before edit...\n");
report_spline_thru_points(spline);
// Reduce the amount of points by 1
UFCurve.AskSplineThruPtsData data = ufs.curve().askSplineThruPts(spline.object.tag());
int numPoints2 = data.numPoints-1;
if( numPoints2 < 2 )
{
lw.writeLine("\nCannot reduce amount of spline points anymore...exit\n");
return;
}
int saveDefData = 1;
UFCurve.PtSlopeCrvatr[] pdata2 = new UFCurve.PtSlopeCrvatr[numPoints2];
double[] parameters2 = new double[numPoints2];
for( int j=0;j<numPoints2;j++)
{
pdata2[j] = data.pointData[j];
parameters2[j] = data.parameters[j];
}
ufs.curve().editSplineThruPts( spline.object.tag(),
data.degree,
data.periodicity,
numPoints2,
pdata2,
parameters2,
saveDefData);
// Report the spline points again
lw.writeLine("\nSpline data after edit...\n");
report_spline_thru_points(spline);
}
}
public static void report_spline_thru_points(Selection.SelectObjectData spline)
throws NXException, RemoteException
{
lw.open();
lw.writeLine("Found Spline " + spline.object.tag().value);
// Report the spline points
UFCurve.AskSplineThruPtsData data = ufs.curve().askSplineThruPts(spline.object.tag());
lw.writeLine("Degree: " + data.degree);
lw.writeLine("Periodicity: " + data.periodicity);
lw.writeLine("Number of Spline Points: " + data.numPoints);
for( int i=0;i<data.numPoints;i++)
{
UFCurve.PtSlopeCrvatr pdata = data.pointData[i];
lw.writeLine(
"X=" + pdata.point[0]
+ " Y=" + pdata.point[1]
+ " Z=" + pdata.point[2]
+ " P=" + data.parameters[i]
);
}
}
public static Selection.SelectObjectData select_a_spline() throws NXException, RemoteException
{
UI theUI = (UI)SessionFactory.get("UI");
Selection.MaskTriple mask[] = { new Selection.MaskTriple(UFConstants.UF_spline_type, 0, 0) };
Selection.SelectObjectData selObj = theUI.selectionManager().selectObject("Select Spline", "Select Spline",
Selection.SelectionScope.WORK_PART, Selection.SelectionAction.CLEAR_AND_ENABLE_SPECIFIC, false, false, mask );
if ( selObj.response == Selection.Response.OBJECT_SELECTED ||
selObj.response == Selection.Response.OBJECT_SELECTED_BY_NAME )
{
return selObj;
}
else
return null;
}
public static final int getUnloadOption()
{
return BaseSession.LibraryUnloadOption.IMMEDIATELY;
}
} |
|