找回密码
 注册
Simdroid-非首页
查看: 61|回复: 0

[二次开发] Java program : decrease points of selected non associative spline by one

[复制链接]
发表于 2009-12-18 00:45:11 | 显示全部楼层 |阅读模式 来自 河北廊坊
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;
    }
   
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-9-29 09:28 , Processed in 0.030042 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表