UG創建最大邊界盒


 1 using System;  2 using NXOpen;  3 using NXOpen.UF;  4 using System.Windows.Forms;  5 
 6 public class NXJournal  7 {  8   public static void Main(string[] args)  9  { 10        NXOpen.Session theSession = NXOpen.Session.GetSession(); 11     NXOpen.Part workPart = theSession.Parts.Work; 12     NXOpen.Part displayPart = theSession.Parts.Display; 13     UI theUI = UI.GetUI(); 14     UFSession theUfSession = UFSession.GetUFSession(); 15 
16     
17             //第一種方法
18 
19  TaggedObject tag; 20  Point3d point3d; 21 
22             ////選擇對象
23             theUI.SelectionManager.SelectTaggedObject("選擇對象", "創建邊界盒", Selection.SelectionScope.WorkPartAndOccurrence, false, true, out tag, out point3d); 24 
25             ////獲取對象的最大對角點 26             ////是以絕對坐標獲取的最大外圍,如果坐標擺斜了創建的方塊就不對.
27             //double[] outlinePoint = new double[6]; 28             //NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBox(tag.Tag, outlinePoint);
29 
30             ////創建一個點
31             //Point point = theSession.Parts.Work.Points.CreatePoint(new Point3d(outlinePoint[0], outlinePoint[1], outlinePoint[2]));
32             ////Point point_1 = theSession.Parts.Work.Points.CreatePoint(new Point3d(box[3], box[4], box[5])); 33 
34             ////創建點特征(真正的創建)
35             //NXOpen.Features.Feature pointFeature = null; 36             //NXOpen.Features.PointFeatureBuilder pointFeatureBuilder = theSession.Parts.Work.BaseFeatures.CreatePointFeatureBuilder(pointFeature); 37             //pointFeatureBuilder.Point = point; 38             //pointFeatureBuilder.Commit(); 39             //pointFeatureBuilder.Destroy();
40 
41             //////創建最大外圍盒 42             ////NXOpen.Features.Block block = null; 43             ////NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder; 44             ////blockFeatureBuilder = theSession.Parts.Work.Features.CreateBlockFeatureBuilder(block); 45 
46             ////blockFeatureBuilder.SetTwoDiagonalPoints 47             //// (new Point3d(outlinePoint[0], outlinePoint[1], outlinePoint[2]), new Point3d(outlinePoint[3], outlinePoint[4], outlinePoint[5])); 48 
49             ////block = (NXOpen.Features.Block)blockFeatureBuilder.Commit(); 50             ////blockFeatureBuilder.Destroy(); 51 
52             //////設置塊的名稱 53             ////block.SetName("rrr"); 54             //////取消或設置高亮 55             ////NXOpen.UF.UFSession.GetUFSession().Disp.SetHighlight(tag.Tag, 0);
56 
57 
58             //第二種方法 59             //按wcs坐標系
60             Tag UFWcs;// 61             NXOpen.UF.UFSession.GetUFSession().Csys.AskWcs(out UFWcs); 62             Tag wcs = theSession.Parts.Work.WCS.CoordinateSystem.Tag; 63 
64             bool expand = true; 65             double[] min_corner = new double[3]; //角落點
66             double[,] directions = new double[3,3];//方向
67             double[] distances = new double[3];//xyz最大距離
68  NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBoxAligned 69  (tag.Tag, wcs, expand, min_corner, directions, distances); 70 
71 
72             //創建最大外圍盒
73             NXOpen.Features.Block block = null; 74  NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder; 75             blockFeatureBuilder = theSession.Parts.Work.Features.CreateBlockFeatureBuilder(block); 76 
77  blockFeatureBuilder.SetOriginAndLengths 78                 (new Point3d(min_corner[0], min_corner[1], min_corner[2]), 79                 distances[0].ToString(), distances[1].ToString(), distances[2].ToString()); 80 
81             block = (NXOpen.Features.Block)blockFeatureBuilder.Commit(); 82  blockFeatureBuilder.Destroy(); 83 
84 
85             //取消或設置高亮
86             NXOpen.UF.UFSession.GetUFSession().Disp.SetHighlight(tag.Tag, 0); 87 
88 
89             //第3種方法 90 
91            // NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBoxExact(tag.Tag,theSession.Parts.Work.WCS.Tag,)
92     
93  } 94   public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; } 95 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM