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二次開發-判斷程式是否為空刀軌
- NX建模和工程圖培訓
- 獲取cookie裡面的值Cookie
- 獲取洞口邊界及在牆上開洞(Revit二次開發)
- 獲取當前頁面的topViewControllerViewController
- 如何獲取 alter 裡面的字串?字串
- NX二次開發:一個DLL設定多個按鈕操作的方法
- 直播原始碼開發,js 正規表示式獲取括號裡面的內容原始碼JS
- js獲取url傳遞引數,js獲取url?號後面的引數JS
- react獲取當前頁面的url引數React
- API介面的運用場景以及獲取方式API
- js 獲取可視介面的高度或寬度JS
- 曲面建模3D模型設計Rhino 7中文3D模型
- PHP中獲取當前頁面的各種URL格式PHP
- API介面的藝術:如何巧妙獲取商品資料API
- iOS開發-獲取rootViewController的正確方式iOSViewController
- layui 子彈窗獲取父頁面的引數傳參UI
- 網站修改二次開發,網站二次開發流程網站
- kubernetes 二次開發
- SOLIDWORKS二次開發Solid
- Dresdon二次開發
- 網路節點資源獲取共享方面的演算法演算法
- pbootcms獲取結果頁面的搜尋keyword值和tag值boot
- OpenHarmony開發筆記:獲取原始碼(repo安裝)筆記原始碼
- SOLIDWORKS二次開發形式Solid
- NX二次開發-調內部函式UGS::UICOMP_enum::set_width(int)更改BlockUI的列舉控制元件寬度函式UIBloC控制元件
- 考研大資料爬取與分析工具二次開發進行中。。。大資料
- Solon Aop 特色開發(1)注入或手動獲取配置
- 使用Python開發獲取商品銷量詳情API介面PythonAPI
- 只需一個小bug,就可獲取facebook頁面的管理員許可權
- 請問PbootCMS獲取結果頁面的搜尋keyword值和tag值boot
- SAP 電商雲 Spartacus 產品明細頁面的 pageContext 如何獲取的?Context
- UG二次開發筆記筆記
- 基於 solox 二次開發
- SOLIDWORKS二次開發介紹Solid