NX二次開發-建模-獲取面的相切曲面
在UG NX中,選擇面時,有相切曲面、體的面等等。
在二次開發過程中,為了獲得面的相切面,採用錄製功能,獲取獲取相切面的程式碼(以偏置曲面為例),獲得如下程式碼。
// NX 1934
// Journal created by Administrator on Wed Nov 11 23:48:21 2020 中國標準時間
//
using System;
using NXOpen;
public class NXJournal
{
public static void Main(string[] args)
{
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
// ----------------------------------------------
// 選單:插入(S)->偏置/縮放(O)->偏置曲面(O)...
// ----------------------------------------------
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "起點");
NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
NXOpen.Features.OffsetSurfaceBuilder offsetSurfaceBuilder1;
offsetSurfaceBuilder1 = workPart.Features.CreateOffsetSurfaceBuilder(nullNXOpen_Features_Feature);
NXOpen.Unit unit1;
unit1 = offsetSurfaceBuilder1.Radius.Units;
NXOpen.Expression expression1;
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("5", unit1);
offsetSurfaceBuilder1.OutputOption = NXOpen.Features.OffsetSurfaceBuilder.OutputOptionType.OneFeatureForAllFaces;
offsetSurfaceBuilder1.Tolerance = 0.001;
offsetSurfaceBuilder1.Radius.SetFormula("5");
offsetSurfaceBuilder1.SetOrientationMethod(NXOpen.Features.OffsetSurfaceBuilder.OrientationMethodType.UseExistingNormals);
offsetSurfaceBuilder1.ApproxOption = true;
offsetSurfaceBuilder1.PartialOption = true;
offsetSurfaceBuilder1.MaximumExcludedObjects = 10;
offsetSurfaceBuilder1.RemoveProblemVerticesOption = true;
theSession.SetUndoMarkName(markId1, "偏置曲面 對話方塊");
NXOpen.ScCollector nullNXOpen_ScCollector = null;
NXOpen.GeometricUtilities.FaceSetOffset faceSetOffset1;
faceSetOffset1 = workPart.FaceSetOffsets.CreateFaceSet("5", nullNXOpen_ScCollector, false, 0);
offsetSurfaceBuilder1.FaceSets.Append(faceSetOffset1);
NXOpen.ScCollector scCollector1;
scCollector1 = workPart.ScCollectors.CreateCollector();
NXOpen.Features.SweepAlongGuide sweepAlongGuide1 = ((NXOpen.Features.SweepAlongGuide)workPart.Features.FindObject("SWEEP(2)"));
NXOpen.Face face1 = ((NXOpen.Face)sweepAlongGuide1.FindObject("FACE 563448 {(-8.5786437626905,0,191.4213562373095) SWEEP(2)}"));
NXOpen.Face[] boundaryFaces1 = new NXOpen.Face[0];
NXOpen.FaceTangentRule faceTangentRule1;
faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(face1, boundaryFaces1, 0.050000000000000003);
NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
rules1[0] = faceTangentRule1;
scCollector1.ReplaceRules(rules1, false);
faceSetOffset1.FaceCollector = scCollector1;
offsetSurfaceBuilder1.PartialOption = true;
NXOpen.Session.UndoMarkId markId2;
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "偏置曲面");
theSession.DeleteUndoMark(markId2, null);
NXOpen.Session.UndoMarkId markId3;
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "偏置曲面");
NXOpen.NXObject nXObject1;
nXObject1 = offsetSurfaceBuilder1.Commit();
theSession.DeleteUndoMark(markId3, null);
theSession.SetUndoMarkName(markId1, "偏置曲面");
workPart.Expressions.Delete(expression1);
NXOpen.Expression expression2 = offsetSurfaceBuilder1.Radius;
NXOpen.Expression expression3 = faceSetOffset1.Offset;
offsetSurfaceBuilder1.Destroy();
// ----------------------------------------------
// 選單:工具(T)->操作記錄(J)->停止錄製(S)
// ----------------------------------------------
}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
其實,獲得相切面的程式碼是在:
NXOpen.ScCollector scCollector1;
scCollector1 = workPart.ScCollectors.CreateCollector();
NXOpen.Features.SweepAlongGuide sweepAlongGuide1 = ((NXOpen.Features.SweepAlongGuide)workPart.Features.FindObject("SWEEP(2)"));
NXOpen.Face face1 = ((NXOpen.Face)sweepAlongGuide1.FindObject("FACE 563448 {(-8.5786437626905,0,191.4213562373095) SWEEP(2)}"));
NXOpen.Face[] boundaryFaces1 = new NXOpen.Face[0];
NXOpen.FaceTangentRule faceTangentRule1;
faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(face1, boundaryFaces1, 0.050000000000000003);
NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
rules1[0] = faceTangentRule1;
scCollector1.ReplaceRules(rules1, false);
這裡獲得的是NXOpen.ScCollector scCollector1,如何將NXOpen.ScCollector scCollector1中的面提取出來,作為NXObject,裡面沒有涉及。經過研究,可以採用如下的函式實現:
/// <summary>
/// 獲取面的相切面(tangentFaces)
/// </summary>
///<returns>tangentFaces[]</returns>>
public Face[] GetTangentFaces()
{
Face [] tangentFaces = new Face[0];
NXOpen.FaceTangentRule faceTangentRule;
NXOpen.Face[] boundaryFaces1 = new NXOpen.Face[0];
faceTangentRule = workPart.ScRuleFactory.CreateRuleFaceTangent(theFace, boundaryFaces1, 0.5);
NXOpen.SelectionIntentRule[] rules = new NXOpen.SelectionIntentRule[1];
rules[0] = faceTangentRule;
NXOpen.ScCollector scCollector;
scCollector = workPart.ScCollectors.CreateCollector();
scCollector.ReplaceRules(rules, false);
TaggedObject[] taggedObjects = scCollector.GetObjects();
foreach (var to in taggedObjects)
{
Array.Resize(ref tangentFaces, tangentFaces.Length + 1);
tangentFaces[tangentFaces.Length - 1] = (Face)to;
}
return tangentFaces;
}
採用TaggedObject[] taggedObjects = scCollector.GetObjects();來獲取面物件。
相關文章
- NX二次開發-建模-遍歷所有物件物件
- NX二次開發-使用NXOPEN C++嚮導模板做二次開發C++
- NX二次開發-NX連線SqlServer資料庫(增刪改查)C#版SQLServer資料庫C#
- NX二次開發-判斷程式是否為空刀軌
- 基於MFC設計NX二次開發介面——專案配置注意點
- 獲取洞口邊界及在牆上開洞(Revit二次開發)
- NX二次開發:一個DLL設定多個按鈕操作的方法
- 獲取cookie裡面的值Cookie
- 如何獲取 alter 裡面的字串?字串
- 基於NX開發Angular專案Angular
- 直播原始碼開發,js 正規表示式獲取括號裡面的內容原始碼JS
- 獲取當前頁面的topViewControllerViewController
- 微信獲取二維碼開發
- js獲取url傳遞引數,js獲取url?號後面的引數JS
- react獲取當前頁面的url引數React
- javascript如何獲取當前頁面的路徑JavaScript
- PHP中獲取當前頁面的完整URLPHP
- 【iOS開發】獲取區域網IPiOS
- 利用Civil 3D API更改曲面的樣式3DAPI
- API介面的運用場景以及獲取方式API
- 獲取當前頁面的上一個頁地址
- 利用js獲取當前頁面的域名程式碼JS
- asp.net獲取當前頁面的url地址ASP.NET
- js 獲取可視介面的高度或寬度JS
- 曲面建模3D模型設計Rhino 7中文3D模型
- 微信開發示例(access_token的獲取)
- iOS開發 獲取圖片中的顏色iOS
- Dresdon二次開發
- ThinkS二次開發
- PHP中獲取當前頁面的各種URL格式PHP
- API介面的藝術:如何巧妙獲取商品資料API
- js獲取文件頁面的尺寸包括滾動條部分JS
- javascript獲取當前頁面的來路頁面地址JavaScript
- golang web開發獲取get、post、cookie引數GolangWebCookie
- SOLIDWORKS二次開發Solid
- ebs二次開發1
- ebs二次開發2
- ebs二次開發3