在封装的ufun .NET库里面,对UF_MODL_ask_face_loops这个函数并没有封装,导致我们很多不便,那我们在.NET下怎样才能使用这个函数呢??当然是手动处理一下

 Public Function AskFaceLoops(ByVal faceTag As NXOpen.Tag) As loop_list()
Dim loop_t As IntPtr
NXOpen.Utilities.JAM.StartUFCall()
Dim errorCode As Integer = UF_MODL_ask_face_loops(faceTag, loop_t)
NXOpen.Utilities.JAM.EndUFCall()
If errorCode <> 0 Then
Throw NXOpen.NXException.Create(errorCode)
End If
Dim ptr As IntPtr = loop_t
Dim loopList As New List(Of loop_list)
While ptr <> IntPtr.Zero
Dim loop_list_t As _loop_list = CType(Marshal.PtrToStructure(ptr, GetType(_loop_list)), _loop_list)
Dim count As Integer
errorCode = UF_MODL_ask_list_count(loop_list_t.edge_list, count)
Dim edgeArray(count - 1) As NXOpen.Tag
For i As Integer = 0 To count - 1
UF_MODL_ask_list_item(loop_list_t.edge_list, i, edgeArray(i))
Next
'UF_MODL_delete_list(loop_list_t.edge_list)
loopList.Add(New loop_list With {
.type = loop_list_t.type,
.edge_list = edgeArray})
ptr = loop_list_t.next
End While
UF_MODL_delete_loop_list(loop_t)
Return loopList.ToArray()
End Function <DllImport("libufun.dll", EntryPoint:="UF_MODL_ask_face_loops", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
Friend Shared Function UF_MODL_ask_face_loops(ByVal face As Tag, <Out> ByRef loop_list As IntPtr) As Integer
End Function <DllImport("libufun.dll", EntryPoint:="UF_MODL_ask_list_count", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
Friend Shared Function UF_MODL_ask_list_count(ByVal list As IntPtr, <Out> ByRef count As Integer) As Integer
End Function <DllImport("libufun.dll", EntryPoint:="UF_MODL_ask_list_item", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
Friend Shared Function UF_MODL_ask_list_item(ByVal list As IntPtr, ByVal index As Integer, <Out> ByRef [object] As Tag) As Integer
End Function
<DllImport("libufun.dll", EntryPoint:="UF_MODL_delete_list", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
Public Shared Function UF_MODL_delete_list(ByRef list As IntPtr) As Integer
End Function <DllImport("libufun.dll", EntryPoint:="UF_MODL_delete_loop_list", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
Friend Shared Function UF_MODL_delete_loop_list(ByRef list As IntPtr) As Integer
End Function Friend Structure _loop_list
Public type As Integer
Public edge_list As IntPtr
Public [next] As IntPtr
End Structure Public Structure loop_list
Public type As Integer 'Peripheral=1, Hole=2, Other=3
Public edge_list() As NXOpen.Tag
End Structure
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; public class AskFaceLoop
{
public LoopList[] AskFaceLoops(NXOpen.Tag faceTag)
{
System.IntPtr loopT;
NXOpen.Utilities.JAM.StartUFCall();
int errorCode = UF_MODL_ask_face_loops(faceTag,out loopT);
NXOpen.Utilities.JAM.EndUFCall();
if (errorCode != 0)
{
throw NXOpen.NXException.Create(errorCode);
}
System.IntPtr ptr = loopT;
List<LoopList> loopList = new List<LoopList>();
while (ptr != IntPtr.Zero)
{
_loop_list loopListT = (_loop_list)Marshal.PtrToStructure(ptr, typeof(_loop_list));
int count;
errorCode = UF_MODL_ask_list_count(loopListT.edge_list,out count);
NXOpen.Tag[] edgeArray = new NXOpen.Tag[count];
for (int i = 0; i < count; i++)
{
UF_MODL_ask_list_item(loopListT.edge_list, i,out edgeArray[i]);
}
//UF_MODL_delete_list(out loopListT.edge_list);
loopList.Add(new LoopList{Type = loopListT.type,EdgeList = edgeArray});
ptr = loopListT.next;
}
UF_MODL_delete_loop_list(out loopT);
return loopList.ToArray();
} [DllImport("libufun.dll", EntryPoint = "UF_MODL_ask_face_loops", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_ask_face_loops(NXOpen.Tag face, out IntPtr loopList); [DllImport("libufun.dll", EntryPoint = "UF_MODL_ask_list_count", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_ask_list_count(IntPtr list, out int count); [DllImport("libufun.dll", EntryPoint = "UF_MODL_ask_list_item", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_ask_list_item(IntPtr list, int index, out NXOpen.Tag @object); [DllImport("libufun.dll", EntryPoint = "UF_MODL_delete_list", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_delete_list(out IntPtr list); [DllImport("libufun.dll", EntryPoint = "UF_MODL_delete_loop_list", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_delete_loop_list(out IntPtr list); internal struct _loop_list
{
public int type;
public IntPtr edge_list;
public IntPtr next;
} public struct LoopList
{
/// <summary>
/// Peripheral=1, Hole=2, Other=3
/// </summary>
public int Type;
public NXOpen.Tag[] EdgeList;
}
}

  

最新文章

  1. jvm的垃圾回收原理
  2. shell 问题解决
  3. Button 设置适应不同版本 旋转以后大小相应的改变
  4. iOS-编译简单静态库初探
  5. 根据DateTime来获取当天是周几(已完结)
  6. bzoj 4871: [Shoi2017]摧毁“树状图” [树形DP]
  7. php操作excel表格的导入和导出
  8. Modbus协议栈实现Modbus RTU多主站支持
  9. NSCTF web200
  10. [转帖] CA如何保护自己的私钥
  11. Word操作——通配符
  12. 深入理解Java类加载器(ClassLoader)
  13. 【做题】agc016d - XOR Replace——序列置换&amp;环
  14. 最新安全狗 apache v4.0 sql注入 bypass
  15. 基于asp.net mvc的近乎产品开发培训课程(第二讲)
  16. RC Calculation
  17. 洛谷SP16580 QTREE7 - Query on a tree VII(LCT,multiset)
  18. 在线聊天室 -onlinechat
  19. PFC电源设计与电感设计计算学习笔记
  20. mongodb 跟踪SQL语句及慢查询收集

热门文章

  1. Linux系统的高级网络配置(bond、team、网桥)
  2. uni-app 入门小白纯徒手编写组件 hello-popup
  3. 【流程】Flowable流程定义总结
  4. GDAL 矢量裁剪栅格
  5. Spring Boot入门系列(二十六)超级简单!Spring Data JPA 的使用!
  6. Git:为Git Bash.exe设置默认起始目录的两种方式(start in、~/.bashrc)
  7. Android使用百度语音识别api代码实现。
  8. C# Collection
  9. python win32com 处理excle 写一个公共的类
  10. 简单入门PHP中的多字节字符串操作